mirror of https://gitlab.com/bashrc2/epicyon
Round up word division for bold reading
parent
2c087d5e2a
commit
5b480dd815
|
@ -7,6 +7,7 @@ __email__ = "bob@libreserver.org"
|
|||
__status__ = "Production"
|
||||
__module_group__ = "Core"
|
||||
|
||||
import math
|
||||
import html
|
||||
import os
|
||||
import email.parser
|
||||
|
@ -1349,7 +1350,8 @@ def bold_reading_string(text: str) -> str:
|
|||
reading_markup = True
|
||||
if reading_markup and '>' in wrd:
|
||||
reading_markup = False
|
||||
if not reading_markup and len(wrd) > 1 and \
|
||||
wrd_len = len(wrd)
|
||||
if not reading_markup and wrd_len > 1 and \
|
||||
'<' not in wrd and '>' not in wrd and \
|
||||
'&' not in wrd and '=' not in wrd and \
|
||||
not wrd.startswith(':'):
|
||||
|
@ -1361,9 +1363,9 @@ def bold_reading_string(text: str) -> str:
|
|||
wrd = wrd[1:]
|
||||
if wrd.endswith('"'):
|
||||
postfix = '"'
|
||||
wrd = wrd[:len(wrd) - 1]
|
||||
wrd = wrd[:wrd_len - 1]
|
||||
|
||||
initial_chars = int(len(wrd) / 2)
|
||||
initial_chars = int(math.ceil(wrd_len / 2.0))
|
||||
new_parag += \
|
||||
prefix + '<b>' + wrd[:initial_chars] + '</b>' + \
|
||||
wrd[initial_chars:] + postfix + ' '
|
||||
|
|
10
tests.py
10
tests.py
|
@ -6703,7 +6703,7 @@ def _test_bold_reading() -> None:
|
|||
text_bold = bold_reading_string(text)
|
||||
expected = \
|
||||
"<p><b>Th</b>is <b>i</b>s a <b>te</b>st <b>o</b>f " + \
|
||||
"<b>embol</b>dening <b>wi</b>th <b>parag</b>raph.</p>"
|
||||
"<b>embold</b>ening <b>wi</b>th <b>parag</b>raph.</p>"
|
||||
if text_bold != expected:
|
||||
print(text_bold)
|
||||
assert text_bold == expected
|
||||
|
@ -6714,8 +6714,8 @@ def _test_bold_reading() -> None:
|
|||
text_bold = bold_reading_string(text)
|
||||
expected = \
|
||||
"<p><b>Th</b>is <b>i</b>s a <b>te</b>st <b>o</b>f " + \
|
||||
"<b>embol</b>dening</p><p><b>Wi</b>th <b>mo</b>re " + \
|
||||
"<b>th</b>an <b>o</b>ne <b>parag</b>raph.</p>"
|
||||
"<b>embold</b>ening</p><p><b>Wi</b>th <b>mo</b>re " + \
|
||||
"<b>th</b>an <b>on</b>e <b>parag</b>raph.</p>"
|
||||
if text_bold != expected:
|
||||
print(text_bold)
|
||||
assert text_bold == expected
|
||||
|
@ -6731,10 +6731,10 @@ def _test_bold_reading() -> None:
|
|||
print(text_bold)
|
||||
assert text_bold == expected
|
||||
|
||||
text = "There's some quoted text here"
|
||||
text = "There's the quoted text here"
|
||||
text_bold = bold_reading_string(text)
|
||||
expected = \
|
||||
"<b>The</b>re's <b>so</b>me <b>quo</b>ted <b>te</b>xt <b>he</b>re"
|
||||
"<b>Ther</b>e's <b>th</b>e <b>quo</b>ted <b>te</b>xt <b>he</b>re"
|
||||
if text_bold != expected:
|
||||
print(text_bold)
|
||||
assert text_bold == expected
|
||||
|
|
Loading…
Reference in New Issue