The discussion centers around handling and hiding automatically generated anchors when posting Markdown content in Discourse. Nihokam initially sought a way to hide these anchors, as they interfere with cross-referencing in externally used Markdown documents.
Arkshine explained Discourse uses MarkdownIt, based on CommonMark, which doesn’t natively support header IDs, but Discourse generates them automatically using patterns like h-{headingId} or p-{postId}-h-{headingId}see post #2. They suggested using manual HTML anchors <a name="anchor_name"></a> as an alternative and linked to a Discourse Table of Contents component (https://meta.discourse.org/t/discotoc-automatic-table-of-contents/111143).
Nihokam decided to pre-process the Markdown before posting. Arkshine then offered a Discourse plugin (https://github.com/Arkshine/discourse-custom-anchor-id) allowing custom anchor IDs next to headings (e.g., ## My Heading {#custom_section}). Nihokam will check with their administrator about installing the plugin. Finally, mrmowji questioned the anchor generation patterns, noting discrepancies on meta.discourse.org, and asked if there are any related settings.
Hey community, I am using a discourse site to publish some specs that are primarily written in markdown, but I came to the problem that the anchors used for the headers are being rendered, while they should be hidden.
The issue is more because we are publishing the markdowns used for other reasons in discourse as well, so the people who keep the documents use these anchors for cross-reference when merging multiple markdowns in a single document.
I think I will make some sort of script to clean up before posting the content.
It works alongside Discourse’s automatic heading anchors.
Note that it’s basic support. There are probably a lot of variants, but this plugin supports only the following:
@Arkshine Do you know how anchors in Discourse (the current website) are generated? Asking because they don’t seem to follow the patterns you shared. For example, see this: