blackstork-io / fabric

An open-source command-line tool for reporting workflow automation and a configuration language for reusable templates. Reporting-as-Code
https://blackstork.io/fabric/
Apache License 2.0
10 stars 0 forks source link

Use unique anchors in ToC links #164

Open traut opened 3 weeks ago

traut commented 3 weeks ago

ToC is rendered with local markdown links. At the moment, the anchors (hash in the URL) are derived from the title, which creates an issue when similar titles are used:

- [192.168.XX.201](#192.168.xx.201)
   - [Screenshots](#screenshots)
   - [Steps](#steps)
- [192.168.XX.240](#192.168.xx.240)
   - [PoC Code](#poc-code)
   - [Screenshots](#screenshots)
   - [Steps](#steps)

The anchors should be suffixed with -<number> if there if there are duplicates, for example:

- [192.168.XX.201](#192.168.xx.201)
   - [Screenshots](#screenshots)
   - [Steps](#steps)
- [192.168.XX.240](#192.168.xx.240)
   - [PoC Code](#poc-code)
   - [Screenshots](#screenshots-1)
   - [Steps](#steps-1)

Uniqueness

First iteration

The problem is that we can not be sure that the user's Markdown rendered will de-duplicate links similarly - by adding -<num> -- as the Github Markdown renderer does. This is ok for the first iteration.

Proper fix

Since generic Markdown schema does not allow custom anchors on titles, another way to enable uniqueness here is to reformat the duplicate titles as HTML tags: instead of

## Steps

create

<h2 id="steps-1">Steps</h2>

This complicates the logic—the ToC plugin would need to reprocess already produced Markdown strings to rewrite the headers. This is a good second iteration

References

traut commented 3 weeks ago

in addition, # breaks the anchor:

[Target #1 - 192.168.x.1](#target-#1---192.168.x.1)

We should follow GitHub Markdown schema here and skip # character

traut commented 6 days ago

moved to milestone 0.5 to wait for https://github.com/blackstork-io/fabric/issues/159 as it is an enabler for this issue