mirror of https://gitlab.com/bashrc2/epicyon
Improve handling of markup while emboldening text
parent
bca1f1c5b7
commit
9fdca7919c
|
@ -1345,9 +1345,9 @@ def bold_reading_string(text: str) -> str:
|
||||||
new_parag = ''
|
new_parag = ''
|
||||||
reading_markup = False
|
reading_markup = False
|
||||||
for wrd in words:
|
for wrd in words:
|
||||||
if '<' in wrd and '>' not in wrd:
|
if '<' in wrd:
|
||||||
reading_markup = True
|
reading_markup = True
|
||||||
if reading_markup and '>' in wrd and '<' not in wrd:
|
if reading_markup and '>' in wrd:
|
||||||
reading_markup = False
|
reading_markup = False
|
||||||
if not reading_markup and len(wrd) > 1 and \
|
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 \
|
||||||
|
|
6
tests.py
6
tests.py
|
@ -6721,12 +6721,12 @@ def _test_bold_reading() -> None:
|
||||||
assert text_bold == expected
|
assert text_bold == expected
|
||||||
|
|
||||||
text = '<p>This is a test <a class="some class" ' + \
|
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)
|
text_bold = bold_reading_string(text)
|
||||||
expected = \
|
expected = \
|
||||||
'<p><b>Th</b>is <b>i</b>s a <b>te</b>st ' + \
|
'<p><b>Th</b>is <b>i</b>s a <b>te</b>st ' + \
|
||||||
'<a class="some class" href="some_url">with ' + \
|
'<a class="some class" href="some_url"><label>with ' + \
|
||||||
'<b>mar</b>kup <b>conta</b>ining spaces</a></p>'
|
'<b>mar</b>kup <b>conta</b>ining spaces</label></a></p>'
|
||||||
if text_bold != expected:
|
if text_bold != expected:
|
||||||
print(text_bold)
|
print(text_bold)
|
||||||
assert text_bold == expected
|
assert text_bold == expected
|
||||||
|
|
Loading…
Reference in New Issue