diff --git a/federation/tests/utils/test_text.py b/federation/tests/utils/test_text.py index 2efa917..fa69b6b 100644 --- a/federation/tests/utils/test_text.py +++ b/federation/tests/utils/test_text.py @@ -83,6 +83,14 @@ class TestFindTags: tags, text = find_tags(source, replacer=self._replacer) assert text == source + def test_start_of_paragraph_in_html_content(self): + source = '

First line

#foobar #barfoo

' + tags, text = find_tags(source) + assert tags == {"foobar", "barfoo"} + assert text == source + tags, text = find_tags(source, replacer=self._replacer) + assert text == '

First line

#foobar/foobar #barfoo/barfoo

' + class TestProcessTextLinks: def test_link_at_start_or_end(self): diff --git a/federation/utils/text.py b/federation/utils/text.py index 9ad2cfe..cebed5a 100644 --- a/federation/utils/text.py +++ b/federation/utils/text.py @@ -33,7 +33,9 @@ def find_tags(text: str, replacer: callable = None) -> Tuple[Set, str]: Returns a set of tags and the original or replaced text. """ found_tags = set() - lines = text.splitlines(keepends=True) + #
and

tags cause issues in us finding words - add some spacing around them + new_text = text.replace("
", "
").replace("

", "

").replace("

", "

") + lines = new_text.splitlines(keepends=True) final_lines = [] code_block = False final_text = None @@ -78,6 +80,8 @@ def find_tags(text: str, replacer: callable = None) -> Tuple[Set, str]: final_lines.append(" ".join(final_words)) if replacer: final_text = "".join(final_lines) + if final_text: + final_text = final_text.replace("
", "
").replace("

", "

").replace("

", "

") return found_tags, final_text or text