kramdown / parser-gfm

kramdown-parser-gfm provides a kramdown parser for the GFM dialect of Markdown
Other
55 stars 14 forks source link

Update parser to respect 'transliterated_header_ids' kramdown option #22

Closed kill9zombie closed 3 years ago

kill9zombie commented 3 years ago

A possible fix for #21

While the IDs don't perfectly match what we see from the kramdown parser, they are all transliterated by kramdown's HTML converter.

One line that isn't exactly the same (all with transliterated_header_ids set to true) :

Current GFM parser: <h3 id="with-äspace">with  ä space</h3> Current kramdown parser: <h3 id="with-nbspaumlnbspspace">with  ä space</h3> This PR: <h3 id="with--a-space">with  ä space</h3>

All other test case lines are the same as the kramdown parser.

By not setting an ID in the parser, we'll trigger the converter to add one (which is what happens with the kramdown parser): https://github.com/gettalong/kramdown/blob/master/lib/kramdown/converter/html.rb#L143

ashmaroli commented 3 years ago

How about merging the two similar branches into:

elsif child.type == :header && @options[:auto_ids]
  if @options[:transliterated_header_ids]
    # Let the kramdown converter create the ID
    child
  elsif !child.attr.key?('id')
    child.attr['id'] = generate_gfm_header_id(child.options[:raw_text])
    child
  end
...
kill9zombie commented 3 years ago

Hello

I'm not entirely sure which two branches, but the example above looks good to me. Thanks

ashmaroli commented 3 years ago

Thank you for improving the GFM Parser, @kill9zombie