Skip to content

Commit

Permalink
Consolidate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Jan 25, 2025
1 parent dbddf88 commit 4887c9e
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions markdown/extensions/md_in_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def handle_starttag(self, tag, attrs):
self.handle_empty_tag(data, True)
return

if tag in self.block_level_tags and (self.at_line_start() or self.intail):
if (
tag in self.block_level_tags and
(self.at_line_start() or self.intail or self.mdstarted and self.mdstarted[-1])
):
# Valueless attribute (ex: `<tag checked>`) results in `[('checked', None)]`.
# Convert to `{'checked': 'checked'}`.
attrs = {key: value if value is not None else key for key, value in attrs}
Expand All @@ -131,20 +134,6 @@ def handle_starttag(self, tag, attrs):
attrs['markdown'] = state
self.treebuilder.start(tag, attrs)

elif not self.inraw and tag in self.block_level_tags and self.mdstarted and self.mdstarted[-1]:
# Nested one-liner block tags `<tag><tag>...`
attrs = {key: value if value is not None else key for key, value in attrs}
state = self.get_state(tag, attrs)
if 'p' in self.mdstack and tag in self.block_level_tags:
# Close unclosed 'p' tag
self.handle_endtag('p')
self.mdstate.append(state)
self.mdstack.append(tag)
self.mdstarted.append(True)
attrs['markdown'] = state
self.treebuilder.start(tag, attrs)
return

else:
# Span level tag
if self.inraw:
Expand Down

0 comments on commit 4887c9e

Please sign in to comment.