Skip to content

Commit

Permalink
markdown: stricter detection of embedded markup
Browse files Browse the repository at this point in the history
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 #1761
  • Loading branch information
sebix committed Sep 13, 2024
1 parent 33d169e commit 52092dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/moin/converters/_tests/test_markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ def test_wikilinks(self, input, output):
def test_admonition(self, input, output):
self.do(input, output)

data = [
(
"one < two",
'<p>one &lt; two</p>',
),
(
'[[one]] < two',
'<p><a xlink:href="wiki.local:one">one</a> &lt; two</p>',
),
(
'pre <strong>bold</strong> post',
'<div><p>pre <strong>bold</strong> post</p></div>',
),
]

@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)
Expand Down
3 changes: 2 additions & 1 deletion src/moin/converters/markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pre> tag
Expand Down

0 comments on commit 52092dc

Please sign in to comment.