Skip to content

Support Markdown Render Hooks for Headers #6713

@frerich

Description

@frerich

A useful feature provided by many web applications is the ability to conveniently get a link referencing a specific header in the page. People can then bookmark or share the link in order to reference an individual section. Consider e.g. the Effective Go page and try hovering the mouse above any of the headers with a blue background: the shown paragraph symbol is a link to the respective header. Copying the address of the link gets you the URL referencing the header.

Right now, automatically adding such anchor links is possible in Hugo by filtering the entire HTML markup of a page, e.g. given a partial add-header-anchors.html with

{{ . | replaceRE "(<h[1-9] id=\"([^\"]+)\".+)(</h[1-9]+>)" `${1}<a href="#${2}" class="header-anchor" ariaLabel="Anchor">&para;</a>${3}` | safeHTML }}

One can use

{{ .Content | partial "add-header-anchors" }}

With the advent of Markdown render hooks, this seems like a hack. Instead, it would be great if the HTML generated for headers could be customised using a hook such as layouts/_default/_markup/render-header.html

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions