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

@ -1338,8 +1338,13 @@ def bold_reading_string(text: str) -> str:
for parag in paragraphs:
words = parag.split(' ')
new_parag = ''
reading_markup = False
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 wrd.startswith(':'):

View File

@ -6720,6 +6720,17 @@ def _test_bold_reading() -> None:
print(text_bold)
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():
base_dir = os.getcwd()