Skip to content

Commit 0cc9aa4

Browse files
committed
Better avoidance of tags in inline code
1 parent 7759343 commit 0cc9aa4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

markdown/extensions/md_in_html.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,13 @@ def handle_empty_tag(self, data, is_block):
253253
if self.inraw or not self.mdstack:
254254
super().handle_empty_tag(data, is_block)
255255
else:
256-
if self.at_line_start() and is_block:
257-
self.handle_data('\n' + self.md.htmlStash.store(data) + '\n\n')
256+
if self.at_line_start() or self.intail:
257+
if is_block:
258+
self.handle_data('\n' + self.md.htmlStash.store(data) + '\n\n')
259+
else:
260+
self.handle_data(self.md.htmlStash.store(data))
258261
else:
259-
self.handle_data(self.md.htmlStash.store(data))
262+
self.treebuilder.data(data)
260263

261264
def parse_pi(self, i: int) -> int:
262265
if self.at_line_start() or self.intail or self.mdstack:

markdown/inlinepatterns.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ def build_inlinepatterns(md: Markdown, **kwargs: Any) -> util.Registry[InlinePro
158158
AUTOMAIL_RE = r'<([^<> !]+@[^@<> ]+)>'
159159
""" Match an automatic email link (`<[email protected]>`). """
160160

161-
HTML_RE = r'(<(\/?[a-zA-Z][^<>@ ]*( [^<>]*)?|!--(?:(?!<!--|-->).)*--)>)'
161+
HTML_RE = (
162+
r'(<(\/?[a-zA-Z][^<>@ ]*( [^<>]*)?|' # Tag
163+
r'!--(?:(?!<!--|-->).)*--|' # Comment
164+
r'[?](?:(?!<[?]|[?]>).)*[?]|' # Processing instruction
165+
r'<!\[CDATA\[(?:(?!<!\[CDATA\[|\]\]).)*\]\]|' # `CDATA`
166+
')>)'
167+
)
162168
""" Match an HTML tag (`<...>`). """
163169

164170
ENTITY_RE = r'(&(?:\#[0-9]+|\#x[0-9a-fA-F]+|[a-zA-Z0-9]+);)'

0 commit comments

Comments
 (0)