gettalong / kramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
http://kramdown.gettalong.org
Other
1.72k stars 271 forks source link

incorrect text inserted after nested spans #636

Open mattneub opened 4 years ago

mattneub commented 4 years ago

Run the following:

s = <<END
<div class="navbar">
<span style="white-space:nowrap" markdown="1">
<span class="parent"><a href="tech">Technical Details</a></span>
</span>
&nbsp;&nbsp;&nbsp;
</div>
END
h = Kramdown::Document.new(
      s, :auto_ids => false, :entity_output => :numeric
).to_html
puts h

The output is:

<div class="navbar">
<span style="white-space:nowrap">
<span class="parent"><a href="tech">Technical Details</a></span></span>
&lt;/span&gt;
&nbsp;&nbsp;&nbsp;
</div>

The bug is the extra &lt;/span&gt; inserted into the text.

I can see a way of working around this, and I probably will do so; but this is new behavior that is affecting a longstanding web site of mine (though I can't specify the kramdown update in which the problem started, sorry) so perhaps it counts as a genuine bug.

gettalong commented 4 years ago

This behaviour has changed in version 1.11.0 - have you been running a version older than this before? Have to dig a bit to find out why this behaviour changed because it probably shouldn't have.

Why are you using markdown="1" in the first <span> element? This seems to be causing the issue.

mattneub commented 4 years ago

Yes, clearly I was using an older version of kramdown the last time I built my site. The change seems surprising; what I'm doing was never obviously forbidden by the kramdown syntax rules — nested <span> is legal, and kramdown probably shouldn't care at what level the markdown="1" occurs — and injecting &lt;/span&gt; into my text seems just wrong. The workaround from my end is to move that markdown="1" into the inner <span> element, or remove the nesting entirely (i.e. have just one level of <span>). There is more going on here at kramdown's end; for example, if you remove the outer <div> the issue doesn't arise.