From 52092dc148693cb1e76a426c1e162ada582c9b77 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 13 Sep 2024 07:48:05 +0200 Subject: [PATCH] markdown: stricter detection of embedded markup instead of only checking only for the existence of `<`, check for text directly behind the opening bracket and a closing bracket. This prevents added paragraphs/new lines with just brackets or "arrows" (`<-`) in lines. fixes https://github.com/moinwiki/moin/issues/1761 --- .../converters/_tests/test_markdown_in.py | 21 +++++++++++++++++++ src/moin/converters/markdown_in.py | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/moin/converters/_tests/test_markdown_in.py b/src/moin/converters/_tests/test_markdown_in.py index 92b04c474..f0dd2d57e 100644 --- a/src/moin/converters/_tests/test_markdown_in.py +++ b/src/moin/converters/_tests/test_markdown_in.py @@ -182,6 +182,27 @@ def test_wikilinks(self, input, output): def test_admonition(self, input, output): self.do(input, output) + data = [ + ( + "one < two", + '

one < two

', + ), + ( + '[[one]] < two', + '

one < two

', + ), + ( + 'pre bold post', + '

pre bold post

', + ), + ] + + @pytest.mark.parametrize("input,output", data) + def test_embedded_markup(self, input, output): + """Test embedded markup in markdown""" + self.do(input, output) + + def serialize_strip(self, elem, **options): result = serialize(elem, namespaces=self.namespaces, **options) return self.output_re.sub("", result) diff --git a/src/moin/converters/markdown_in.py b/src/moin/converters/markdown_in.py index 7691c7c05..e2576d23c 100644 --- a/src/moin/converters/markdown_in.py +++ b/src/moin/converters/markdown_in.py @@ -531,7 +531,8 @@ def convert_embedded_markup(self, node): """ for idx, child in enumerate(node): if isinstance(child, str): - if "<" in child: + # search for HTML tags + if re.search("<[^ ].*?>", child): node[idx] = self.embedded_markup(child) # child is immutable string, so must do node[idx] else: # do not convert markup within a
 tag