-
Notifications
You must be signed in to change notification settings - Fork 878
md_in_html can process content out of order if block HTML is nested under it #1502
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
Comments
Let me be clear, this is a processing order problem, not an insertion order problem. The order is inserted properly, but the unexpected order of when a block processor sees these lines is wrong which makes it difficult for an extension to discern when and where the lines actually occurred. |
Just curious, does this still occur if your start and end tags are not separated by raw HTML? For example with this input:
Or how about if there is not blank lines?
I'm just trying to work out what might be causing this. |
Something that is helpful when debugging raw HTML is to check the >>> md = markdown.Markdown()
>>> md.convert('<div class="my-div" markdown>\n\n/// 1\n\n<p>\nHello i\'m a \'p\' in a tab which in in a div!\n</p>\n\n/// 2\n\n<div>')
'<div class="my-div" markdown>\n\n/// 1\n\n<p>\nHello i\'m a \'p\' in a tab which in in a div!\n</p>\n\n/// 2\n\n<div>'
>>> md.htmlStash.rawHtmlBlocks
[ '<div class="my-div" markdown>\n\n/// 1\n\n<p>\nHello i\'m a \'p\' in a tab which in in a div!\n</p>\n\n/// 2\n\n<div>\n\n'] |
It only happens with raw HTML between them. |
I'll try to take a look at this sometime soon as well. I had a separate issue related to the opposite ( |
It seems that I can probably fix the ordering issue, but it looks like it won't matter as the real problem is how "markdown" HTML blocks work. Apparently, when processing a "markdown" block, the nested block HTML elements inside it are already real HTML elements. So a plugin like the fenced Block plugins I developed won't work with this setup because the elements are not being passed as placeholders that are expanded as they are processed. A situation like the following, where a nested HTML block is fenced, the fenced block will never see the HTML element as a child under it.
Ideally If we were just to accept that nested HTML will be real elements in these case, I'd probably have to rework I'll have to work on some custom solutions locally in my project to see what is the most viable and cleanest approach before proposing anything. In the worst case, if the changes are not desired here, I may have to provide a custom |
So, I was able to modify |
Draft PR #1503 is up with passing with all unit tests passing. |
…#1503) Ensure `md_in_html` processes content inside a "markdown" block the same way content is processed outside of a "markdown" block. - Flatten the HTML content into placeholders so that the parser will treat the "markdown" block content in the same way it does when `md_in_html` is not enabled. The placeholders are expanded once the parser reaches them in a linear fashion. This allows extensions to deal with HTML content and consume it the same way it deals with them with them when the content is not nested under a "markdown" block. - Instead of content being processed in dummy tags, content is now processed under the real parent allowing extensions to have better context to make better decisions. Additionally, fix some issues with tags and inline code. Also, fix some issues with one-liner block tags, e.g. `<tag><tag>...` Resolves #1502 Resolves #1075 Resolves #1074
I have Block plugins that expect a start
/// start
and end///
. In almost all cases, it seems it is a reasonable assumption that Python Markdown will process the start before the end allowing the plugin to work.In a case like below, this holds true. I add some logging to show when the processed lines are encountered.
Order logged:
A problem is introduced though when
md_in_html
is used.Order logged:
As we can see the order of processing is now out of order, and since our extension relies on this order, the extension also breaks.
If the wrapping tag is inline, there is no problem. If the nested tag is inline, there is also no problem. So this is only when block tags are used within a block tag being processed by
md_in_html
.The text was updated successfully, but these errors were encountered: