trentm / python-markdown2

markdown2: A fast and complete implementation of Markdown in Python
Other
2.66k stars 433 forks source link

Update `markdown-in-html` extra to handle markdown on same line as HTML (#546) #547

Closed Crozzers closed 11 months ago

Crozzers commented 11 months ago

This PR closes #546 by enabling the markdown-in-html extra to parse snippets where the markdown is on the same line as the HTML block. For example:

<p markdown="1">**text**</p>

The fix works by detecting whether the number of matched lines is less than 3 (meaning opening tag, closing tag and content aren't all on separate lines). The first line is then split after the opening tag, and the last line is split before the closing tag.

['<p markdown="1">**text**</p>']          # initial list of lines
['<p markdown="1">', '**text**</p>']      # after first line is split
['<p markdown="1">', '**text**', '</p>']  # final state

This allows the extra to continue as normal

nicholasserra commented 11 months ago

Thanks!