JuliaPluto / PlutoUI.jl

https://featured.plutojl.org/basic/plutoui.jl
The Unlicense
299 stars 54 forks source link

TOC indentation is wonky when using MarkdownLiteral for headers #253

Open rgobbel opened 1 year ago

rgobbel commented 1 year ago

I'm not really sure which package this belongs to, whether it be PlutoUI, MarkdownLiteral, or CommonMark, but since the TableOfContents feature is part of PlutoUI, I'm putting it here. I love the fact that MarkdownLiteral adds automatic human-sensible IDs to header cells, but the TOC display is weird: the highlighting is gone, and the indentation is wrong in a few places.

I've attached two notebooks to show the differences, one using only the md non-standard string, and one using @mdx from MarkdownLiteral.

In the meantime I've created a simple @anchor macro to let me put custom anchors wherever I'd like. It gets the job done for me, and gives me control over exactly where the anchors are placed and what's in them. Here's the code:

Using HypertextLiteral
macro anchor(text)
    anchid = replace(lowercase(text), r"(\s)" => "-")
    @htl "<a id=\"$anchid\" href=\"#$anchid\" class=\"anchor\"></a>"
end

MDTOCNotebooks.zip