kovetskiy / mark

Sync your markdown files with Confluence pages.
https://samizdat.dev
Apache License 2.0
1.01k stars 153 forks source link

support for header custom anchor ids #519

Open lila opened 4 hours ago

lila commented 4 hours ago

Is your feature request related to a problem? Please describe.

if the markdown contains custom header anchor ids, then the cross referencing links that are produced by mark don't respect the custom ids. in fact, the custom ids become visible in the html as part of the header.

markdown custom header ids are pretty common: https://www.markdownguide.org/extended-syntax/#heading-ids

when using mark, my header is for example:

# Leveling Guide {#leveling-guide}

the html for this fragment becomes:

<h1 id="leveling-guide-leveling-guide">Leveling Guide {#leveling-guide}</h1>

see what it did there? it concatenated the custom id with the regular default header id.

but the references to that anchor are still

<p><a href="#leveling-guide"><strong>Leveling Guide     4</strong></a></p>

so perhaps this is a bug. at the end of the day, the anchor custom id shows up visible in the html and the links are broken.

Describe the solution you'd like

the custom anchor id should not be visible in the html, and the html anchor should exactly match the custom id if present.

<h1 id="leveling-guide">Leveling Guide</h1>

Describe alternatives you've considered

given that my markdown is being exported from google docs, i don't have any options execept to manually remove the custom id specs.

Additional context

i think this is a bug not a feature request. cheers,

. k

lila commented 3 hours ago

i guess i can strip out the custom anchor ids with a sed script. then the html output is consistent.

however, confluence messes with the ids as well. when i push to confluence and look at the html, it comes out as:

<h1 id="InterviewGuidelines-LevelingGuide">Leveling Guide</h1>

where the first part is the pagename and the second is the header. while my references are still:

https://<stuff>#leveling-guide

:-(. oh well...

mrueg commented 3 hours ago

anchors currently have some more issues, still something that needs to be looked at. If you have time to look into a fix, a PR is welcome! See also: https://github.com/kovetskiy/mark/issues/47 https://github.com/kovetskiy/mark/issues/492