Improve handling of markup while emboldening text

merge-requests/30/head
Bob Mottram 2022-03-24 15:32:37 +00:00
parent bca1f1c5b7
commit 9fdca7919c
2 changed files with 5 additions and 5 deletions

View File

@ -1345,9 +1345,9 @@ def bold_reading_string(text: str) -> str:
new_parag = ''
reading_markup = False
for wrd in words:
if '<' in wrd and '>' not in wrd:
if '<' in wrd:
reading_markup = True
if reading_markup and '>' in wrd and '<' not in wrd:
if reading_markup and '>' in wrd:
reading_markup = False
if not reading_markup and len(wrd) > 1 and \
'<' not in wrd and '>' not in wrd and \

View File

@ -6721,12 +6721,12 @@ def _test_bold_reading() -> None:
assert text_bold == expected
text = '<p>This is a test <a class="some class" ' + \
'href="some_url">with markup containing spaces</a><p>'
'href="some_url"><label>with markup containing spaces</label></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>'
'<a class="some class" href="some_url"><label>with ' + \
'<b>mar</b>kup <b>conta</b>ining spaces</label></a></p>'
if text_bold != expected:
print(text_bold)
assert text_bold == expected