Skip to content

Commit 4722442

Browse files
Merge pull request #572 from Crozzers/fix-block-like-spans
Process inline tags as HTML blocks when they span multiple lines (#571)
2 parents 54a9dd2 + eb9afb8 commit 4722442

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [pull #568] Add `prepend` arg to toc extra (#397)
88
- [pull #569] Process HTML comments as markdown in 'escape' safe mode
99
- [pull #570] Fix syntax warnings in test suite
10+
- [pull #572] Process inline tags as HTML blocks when they span multiple lines (#571)
1011

1112

1213
## python-markdown2 2.4.13

lib/markdown2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ def _detab(self, text):
833833
_block_tags_b = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math'
834834
_block_tags_b += _html5tags
835835

836+
_span_tags = (
837+
'a|abbr|acronym|b|bdo|big|br|button|cite|code|dfn|em|i|img|input|kbd|label|map|object|output|q'
838+
'|samp|script|select|small|span|strong|sub|sup|textarea|time|tt|var'
839+
)
840+
836841
_liberal_tag_block_re = re.compile(r"""
837842
( # save in \1
838843
^ # start of line (with re.M)
@@ -927,6 +932,14 @@ def _hash_html_blocks(self, text, raw=False):
927932
# Now match more liberally, simply from `\n<tag>` to `</tag>\n`
928933
text = self._liberal_tag_block_re.sub(hash_html_block_sub, text)
929934

935+
# now do the same for spans that are acting like blocks
936+
# eg: an anchor split over multiple lines for readability
937+
text = self._strict_tag_block_sub(
938+
text, self._span_tags,
939+
# inline elements can't contain block level elements, so only span gamut is required
940+
lambda t: hash_html_block_sub(self._run_span_gamut(t))
941+
)
942+
930943
# Special case just for <hr />. It was easier to make a special
931944
# case than to make the other regex more complicated.
932945
if "<hr" in text:

test/tm-cases/block_like_spans.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<a href="www.google.com">
2+
3+
<img src="image.jpg" width="300px" height="auto" alt="Sample image"/>
4+
5+
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>
6+
7+
</a>

test/tm-cases/block_like_spans.text

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<a href="www.google.com">
2+
3+
<img src="image.jpg" width="300px" height="auto" alt="Sample image"/>
4+
5+
Some **markdown** text as well, but _no_ block level elements, since we're still [inside a span](https://google.com)
6+
7+
</a>

0 commit comments

Comments
 (0)