russross / blackfriday

Blackfriday: a markdown processor for Go
Other
5.45k stars 601 forks source link

Self-linking headers #452

Open 9999years opened 6 years ago

9999years commented 6 years ago

Currently, headers create ids for intra-document linking. i.e. # Misc. is rendered as <h1 id="misc">Misc.</h1>. This allows linking to that particular header with something like page#misc. However, accessing that link as a user is quite difficult. I’d like to wrap the <h1> in an <a> (or vice-versa) so I can create links users can click on to share. I think this should be optional, if only for back-compat.

Current behavior:

# Misc. → <h1 id="misc">Misc.</h1>

Desired behavior:

# Misc. → <h1> id="misc"><a href="#misc">Misc.</h1>

Somewhat related to this (although I’d imagine more difficult to implement) is a table of contents, which would ideally be available as an extension with a table generated after the first section, Wikipedia-style. But those are just thoughts that I’m frankly not invested in enough at the moment to work on seriously, so I won’t open a new issue (unless requested).

rtfb commented 6 years ago

An option to linkify headers sounds useful, could be a good pick for a beginning contributor.

There is already a flag for extracting a table of contents: https://github.com/russross/blackfriday/blob/v2/html.go#L49