silverbulletmd / silverbullet

The hackable notebook
https://silverbullet.md
MIT License
2.01k stars 138 forks source link

Table of Contents Link Rendering #867

Closed adamsih300u closed 2 weeks ago

adamsih300u commented 1 month ago

Good morning,

I have set up several 'ToDo' headers on my Index page that reference various tagged tasks that I keep on a separate page. I have made the index headers link to the same header of the main Tasks page so I can quickly add or remove items to those categories but still have an at-a-glance view on the Index page. The Table of Contents at the top does not render the various header links in the 'pretty' way, but instead displays the Markdown code used to generate the internal link. image It'd be great if the Table of Contents could render this the same as the appearance of the header below. image

MrMugame commented 3 weeks ago

This is actually an interesting problem. What happens here is that the toc plug gets the headings and turns them back into their markdown representation cutting of the hashtags in the front. So what ultimately gets rendered here is something likes this [[link_to_heading|[[ToDo#Home|Home ToDo]]]]. This doesn't work as the links are parsed using a regex, which uses [^\]]+ to parse the alias. That's why the last two braces are also not part of the link, the regex doesn't keep track of the nesting here (because it can't) and rather just takes the first best thing. This also means that stuff like a highlighted heading (# ==heading==) doesn't get rendered. The problem here now is that, no matter if the markdown in the alias should actually get rendered or not, the lezer plugin can't properly parse it, at least not to my knowledge. And the second questions is: If nested links get rendered, where do they link to? The deepest link? Another solution would be to just handle a link in a heading as a special case in toc plug, but that seems like it would delay the issue, not fix it.

adamsih300u commented 2 weeks ago

Working perfectly on the Edge image. Thanks so much!