Skip to content

Nested one-liners broken with md_in_html #1074

Closed

Description

@git1sal

Version 3.3.3. I've found several anomalies in the behavior of nested markdown=1 blocks. Here's one that's probably diagnostic:

markdown.markdown('<div class="outer" markdown="block"><div class="inner" markdown="block">*foo*</div></div>', extensions=["extra"])

returns:

'<p><div class="inner" markdown="block"><div class="outer" markdown="block">*foo*</div></p>\n</div>'

The inner <div> is now outside.

Other weird things in this example are the addition of the <p> tags, which are unmatched, and a stray \n .

Activity

  1. git1sal commented on Nov 23, 2020

    @git1sal
    Author

    Oh, I should have mentioned also that the actual content *foo* does not get markdownized in this test case.

  2. waylan commented on Nov 23, 2020

    @waylan
    Member

    I'm not able to replicate that behavior in any recent version. With versions 3.3.0 through 3.3.3 I get:

    <div class="outer">
    <div class="inner">
    <p><em>foo</em></p>
    </div>
    </div>

    However, I see that in #1069 (which is part of the unreleased version 3.3.4) we broke this and I am getting:

    <div class="outer">
    <p><div class="inner" markdown="block"><em>foo</em></p>
    </div>
    </div>

    That does not turn things 'inside-out,' but it is clearly wrong. and it demonstrates again that our tests for md_in_html are incomplete.

    By the way, there is a clear difference between the inputs:

    <div class="outer" markdown="block">
    <div class="inner" markdown="block">*foo*</div>
    </div>
    

    ... which works fine and ...

    <div class="outer" markdown="block"><div class="inner" markdown="block">*foo*</div></div>
    

    ... which is broken in the current HEAD of master. The later input is also not something we have in our tests.

    The issue is that the nested div does not start at the beginning of a line and therefore is not parsed as a block level element. Under normal circumstances, this would be the correct behavior. However, as it is the first and immediate child of the outer <div> is should still be treated as a block level element. Interestingly, when working on #1069 it occurred to me that this could be an issue, but when the simple fix didn't break any tests, I dismissed the thought. I think we need a more sophisticated manner to determine at_line_start. Sigh.

  3. changed the title [-]Hierarchy of nested <div markdown=1> gets turned inside-out[/-] [+]Nested one-liners broken with md_in_html[/+] on Nov 23, 2020
  4. added
    bugBug report.
    confirmedConfirmed bug report or approved feature request.
    extensionRelated to one or more of the included extensions.
    on Nov 23, 2020
  5. git1sal commented on Nov 24, 2020

    @git1sal
    Author

    Thank you very much—inserting newlines resolved the problem for me.

    Thank you for the amazing work you are doing on this package!

  6. added a commit that references this issue on Jan 25, 2025
    08a4137
  7. added a commit that references this issue on Jan 28, 2025
    f2ae4e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug report.confirmedConfirmed bug report or approved feature request.extensionRelated to one or more of the included extensions.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions