From ea6520c7fbb12219ac7d635ec4177674fc0b222f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 24 Mar 2022 14:08:07 +0000 Subject: [PATCH] Avoid emboldening spaces within markup --- content.py | 9 +++++++-- tests.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/content.py b/content.py index c8000411a..77391ce5a 100644 --- a/content.py +++ b/content.py @@ -1334,12 +1334,17 @@ def bold_reading_string(text: str) -> str: add_paragraph_markup = True paragraphs = text.split('\n') parag_ctr = 0 - new_text = '' + new_text = '' 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(':'): diff --git a/tests.py b/tests.py index 838c669d1..fb4ef453c 100644 --- a/tests.py +++ b/tests.py @@ -6720,6 +6720,17 @@ def _test_bold_reading() -> None: print(text_bold) assert text_bold == expected + text = '

This is a test with markup containing spaces

' + text_bold = bold_reading_string(text) + expected = \ + '

This is a test ' + \ + 'with ' + \ + 'markup containing spaces

' + if text_bold != expected: + print(text_bold) + assert text_bold == expected + def run_all_tests(): base_dir = os.getcwd()