Skip to content

Don't insert hard breaks inside multi-line inline HTML tags - #755

Open
Enesuygurs wants to merge 2 commits into
trentm:masterfrom
Enesuygurs:fix/breaks-inside-html-tags
Open

Enesuygurs wants to merge 2 commits into
trentm:masterfrom
Enesuygurs:fix/breaks-inside-html-tags

Conversation

@Enesuygurs

Copy link
Copy Markdown

Hard breaks are added with a plain regex over the span text, so a line ending inside an inline HTML tag gets a <br /> too. With break-on-newline this happens to any tag whose attributes are split across lines:

markdown2.markdown('Look at <img src="cat.png"\n     alt="A cat"> this.', extras=['break-on-newline'])
<p>Look at <img src="cat.png"<br />
     alt="A cat"> this.</p>

The browser ends the <img> at the <br /> and shows alt="A cat"> as text. Inline links with a wrapped title are affected the same way (title="multi<br />\nline title"), and so are the default two-space breaks when the spaces are inside a tag.

The core hard-break substitution and the breaks extra now share a _do_hard_breaks helper. It swaps tags that contain a newline for placeholders, applies the break regex, and then restores the tags. It uses _sorta_html_tokenize_re, the same approach smarty-pants has used since #735. Single-line tags aren't touched, so the ul/ol/li lookahead and everything outside tags behave as before. The extra pass only runs when the text contains both < and a newline.

I ran every .text file in the test dirs through master and this branch with breaks in each mode, with and without safe mode, plus a run combined with other extras. Apart from the new cases, the output is identical.

I added the break_on_newline_html_tags and hard_break_html_tags test cases, which both fail on master. make testone and make testredos pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant