Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process inline tags as HTML blocks when they span multiple lines (#571) #572

Merged
merged 2 commits into from Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -7,6 +7,7 @@
- [pull #568] Add `prepend` arg to toc extra (#397)
- [pull #569] Process HTML comments as markdown in 'escape' safe mode
- [pull #570] Fix syntax warnings in test suite
- [pull #572] Process inline tags as HTML blocks when they span multiple lines (#571)


## python-markdown2 2.4.13
Expand Down
13 changes: 13 additions & 0 deletions lib/markdown2.py
Expand Up @@ -833,6 +833,11 @@ def _detab(self, text):
_block_tags_b = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math'
_block_tags_b += _html5tags

_span_tags = (
'a|abbr|acronym|b|bdo|big|br|button|cite|code|dfn|em|i|img|input|kbd|label|map|object|output|q'
'|samp|script|select|small|span|strong|sub|sup|textarea|time|tt|var'
)

_liberal_tag_block_re = re.compile(r"""
( # save in \1
^ # start of line (with re.M)
Expand Down Expand Up @@ -927,6 +932,14 @@ def _hash_html_blocks(self, text, raw=False):
# Now match more liberally, simply from `\n<tag>` to `</tag>\n`
text = self._liberal_tag_block_re.sub(hash_html_block_sub, text)

# now do the same for spans that are acting like blocks
# eg: an anchor split over multiple lines for readability
text = self._strict_tag_block_sub(
text, self._span_tags,
# inline elements can't contain block level elements, so only span gamut is required
lambda t: hash_html_block_sub(self._run_span_gamut(t))
)

# Special case just for <hr />. It was easier to make a special
# case than to make the other regex more complicated.
if "<hr" in text:
Expand Down
7 changes: 7 additions & 0 deletions test/tm-cases/block_like_spans.html
@@ -0,0 +1,7 @@
<a href="www.google.com">

<img src="image.jpg" width="300px" height="auto" alt="Sample image"/>

Some <strong>markdown</strong> text as well, but <em>no</em> block level elements, since we're still <a href="https://google.com">inside a span</a>

</a>
7 changes: 7 additions & 0 deletions test/tm-cases/block_like_spans.text
@@ -0,0 +1,7 @@
<a href="www.google.com">

<img src="image.jpg" width="300px" height="auto" alt="Sample image"/>

Some **markdown** text as well, but _no_ block level elements, since we're still [inside a span](https://google.com)

</a>