discourse-auto-bookmarks is a Discourse plugin for adding automatic HTML bookmarks to topics and easily get a sharable link which points at specific parts of the text.
Installation
Follow Install a Plugin
how-to from the official Discourse Meta, using git clone https://github.com/acaporrini/discourse-auto-bookmarks.git
as the plugin command.
Usage
Hover over any h1,h2,h3,h4,h5,h6 header in your topics, a small bookmark icon will appear:
It looks like this adds #target links to H[1-6], right? I’ve seen discussion about this before and the solution was to insert HTML in the Markdown to create the targets. It seems like it’d be easy enough to roll that into core.
When @eviltrout added the anchor functionality in core he did postpone the automagic anchor creation because it’s not that simple, since you need to pick up a pattern, parse the entire post to deduplicate anchors, etc
That explains it. I mostly think that anyone who cares about the ability to link to headings would also bother to make them unique. It doesn’t seem that bad if a link goes the wrong place if someone is careless. That’s what HTML does, after all. (But maybe there’s something else I’m missing.)
Nice work, @acaporrini! Thanks for contributing this nifty plugin. Is there any way you could envision adding a shortcode e.g. [toc] to generate a table of contents of headings and sub-headings within a post? This would make a long termdream a reality for me.
I’m not sure this blue bookmark icon is really needed - it would be fine, in my view, for this to be a hidden feature that power users can use to deep link to sections within posts.
I’m noticing an odd bug on my site - see screenshot. The alignment is off and all but first line get beginning cut off when a heading is shown that is long and goes over one line.
I don’t think we’d need to rely on hover and agree it is noisy. Maybe headings can simply become links to themselves that can be selected via long press or ctrl/right click? Only issue there would be headings where people create links as in eg below, but not sure this would matter for the vast majority of cases.
# [this is a heading](https://someurl.com)
I still like @mcwumbly’s suggestion from back in the day: