[kramdown-users] why can't kramdown just leave my HTML alone?

Thomas Leitner t_leitner at gmx.at
Wed Aug 4 02:02:09 EDT 2010

On 2010-07-21 20:14 -0700 Matt Neuburg wrote:
> require 'rubygems'
> require 'kramdown'
> s = '<div markdown="0">'
> s += '<img src="dummy.png" alt="nothing" />'
> s += '</div>'
> puts Kramdown::Document.new(s).to_html
> #=> <div><img alt="nothing" src="dummy.png" /></div>
> But that isn't what I said, is it? Why can't kramdown just leave my
> img tag alone? I might have a reason to have the src attribute come
> first. This is just not nice behavior.

When you put `markdown="0"` in an HTML/XML tag it just says that the
content should not be parsed with the kramdown parser but with the raw
HTML parser.

One reason why HTML has to be parsed is that the `markdown` attribute
may appear in a nested HTML tag, e.g.:

      <p>Some ordinary HTML paragraph</p>
      <blockquote markdown="1">
    This is parsed with the *kramdown* parser!

Another reason is that the output produced by kramdown needs to valid
HTML, always. So it has to parse HTML in order to ensure the validness
and also correct small problems.

The parsed HTML tags are converted to Element objects of type
`:html_element` and the tag attributes are just key-value associations
stored in the Element object. The order of HTML attributes when
parsing is not important as far as I know... Since the order is not
preserved when parsing HTML attributes I decided to output HTML
attributes alphabetically.

-- Thomas

More information about the kramdown-users mailing list