[feature] improve internal links
Hi,
It could be great to implement some function which slugify titles and purpose those as #targets for URL of link.
Implemented in #520 — this issue closes when that merges.
Half of what you asked for was already there and easy to miss: comrak puts an id on every heading, and [text](#that-id) jumps to it. What was missing is that nothing ever offered the ids, so writing one meant doing the slug rules by hand — lowercase, drop the punctuation comrak drops, hyphenate the spaces — and getting it wrong gives you a link that looks right and lands nowhere.
Now the headings complete as you type a link target:
[text](# → inserts the slug 11-mermaid-diagrams
[[# → inserts the heading 11. Mermaid Diagrams
Two spellings because they resolve differently: the inline form needs the slug itself, while a [[#…]] wikilink names the heading by text and Markpad anchorizes it when rendering. The list is labelled by the heading, so you type a word of it — "mermaid" — rather than guessing the slug, and it is ordered by position in the document rather than alphabetically.
Two things worth knowing:
-
The list is computed by the same parser and the same anchorizer that render the document, not by a second implementation. So a suggested slug is the id that is actually on the page — including a repeated heading, where the second one is
objectives-1and offering the bare slug would quietly link to the first. -
[[other-note#deliberately offers nothing. Those are another file's headings and the editor does not have them; suggesting this document's would be worse than suggesting nothing.
Not in a release yet; it will be in the next one.