kramdown icon indicating copy to clipboard operation
kramdown copied to clipboard

Incorrect text added after unordered lists

Open gravitystorm opened this issue 2 months ago • 1 comments

This is very similar to https://github.com/gettalong/kramdown/issues/636 but I thought I should open a new issue since I'm not sure if it will have a different cause or a different fix.

Using a similar testcase I have:

require 'kramdown'

s = <<END
<div class="navbar">
  <div markdown="1">
* one
  </div>
</div>
END
h = Kramdown::Document.new(
      s, :auto_ids => false, :entity_output => :numeric
).to_html
puts h

...results in unexpected escaped text being added to the output:

<div class="navbar">
  <div>
    <ul>
      <li>one
&lt;/div&gt;</li>
    </ul>
  </div>
</div>

There's three things required for this to be triggered:

  • It only happens with unordered lists. Ordered lists don't show the same behavior
s = <<END
<div class="navbar">
  <div markdown="1">
1. one
  </div>
</div>
END
<div class="navbar">
  <div>
    <ol>
      <li>one</li>
    </ol>
  </div>
</div>
  • If anything comes after the list, for example either more text (e.g. a new paragraph) or even just an inline attribute list, there's no bug
s = <<END
<div class="navbar">
  <div markdown="1">
* one
{:.foo}
  </div>
</div>
END
<div class="navbar">
  <div>
    <ul class="foo">
      <li>one</li>
    </ul>
  </div>
</div>
  • The outer div isn't actually necessary, the bug is only triggered when the markdown-equals-one div is indented
s = <<END
  <div markdown="1">
* one
  </div>
END
<div>
  <ul>
    <li>one
&lt;/div&gt;</li>
  </ul>
</div>

vs

s = <<END
<div markdown="1">
* one
</div>
END
<div>
  <ul>
    <li>one</li>
  </ul>
</div>

I hope this is enough information, please let me know if I can help further!

gravitystorm avatar Oct 20 '25 15:10 gravitystorm

It will get a similar result with ordered lists, too, if the following </div> is indented with one more space (so as to be part of the list item content).

gettalong avatar Oct 20 '25 20:10 gettalong