leandrocp / mdex

A fast 100% CommonMark-compatible GitHub Flavored Markdown parser and formatter for Elixir.
https://mdex-c31.pages.dev
MIT License
83 stars 6 forks source link

How to use header_ids from extension options? #20

Closed mayel closed 9 months ago

mayel commented 9 months ago

Thanks for this much-needed library :)

I was wondering how to use that option: https://docs.rs/comrak/latest/comrak/struct.ExtensionOptions.html#structfield.header_ids

Maybe something like header_ids: fn text -> slug(text) end ?

leandrocp commented 9 months ago

Thanks for this much-needed library :)

Thanks!

I was wondering how to use that option

There you go:

MDEx.to_html("# README", extension: [header_ids: "user-content-"]) |> IO.puts()
#=> <h1><a href="#readme" aria-hidden="true" class="anchor" id="user-content-readme"></a>README</h1>

Manipulating the content of each node will be possible with #9 - that's something I'm still working and will be released soon.

mayel commented 9 months ago

@leandrocp thanks! Seems the title is already turned into a slug by default :)