Avoid emboldening spaces within markup

main
Bob Mottram 2022-03-24 14:08:07 +00:00
parent 4ea1f7e1bd
commit ea6520c7fb
2 changed files with 18 additions and 2 deletions

View File

@ -1334,12 +1334,17 @@ def bold_reading_string(text: str) -> str:
add_paragraph_markup = True add_paragraph_markup = True
paragraphs = text.split('\n') paragraphs = text.split('\n')
parag_ctr = 0 parag_ctr = 0
new_text = '' new_text = ''
for parag in paragraphs: for parag in paragraphs:
words = parag.split(' ') words = parag.split(' ')
new_parag = '' new_parag = ''
reading_markup = False
for wrd in words: for wrd in words:
if len(wrd) > 1 and \ if '<' in wrd and '>' not in wrd:
reading_markup = True
if reading_markup and '>' in wrd and '<' not in wrd:
reading_markup = False
if not reading_markup and len(wrd) > 1 and \
'<' not in wrd and '>' not in wrd and \ '<' not in wrd and '>' not in wrd and \
not wrd.startswith(':'): not wrd.startswith(':'):

View File

@ -6720,6 +6720,17 @@ def _test_bold_reading() -> None:
print(text_bold) print(text_bold)
assert text_bold == expected assert text_bold == expected
text = '<p>This is a test <a class="some class" ' + \
'href="some_url">with markup containing spaces</a><p>'
text_bold = bold_reading_string(text)
expected = \
'<p><b>Th</b>is <b>i</b>s a <b>te</b>st ' + \
'<a class="some class" href="some_url">with ' + \
'<b>mar</b>kup <b>conta</b>ining spaces</a></p>'
if text_bold != expected:
print(text_bold)
assert text_bold == expected
def run_all_tests(): def run_all_tests():
base_dir = os.getcwd() base_dir = os.getcwd()