Skip to content

Commit

Permalink
Add anchor links to all headings
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich committed Dec 5, 2024
1 parent c6391b5 commit e3e6638
Show file tree
Hide file tree
Showing 6 changed files with 831 additions and 481 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%.html: venv
mkdir -p out/$(dir $@)
. $(VENV)/activate && pandoc -t html5 --template=template.html -F code-block-filter.py src/$*.md -o out/$*.html -s --syntax-definition=toml.xml --highlight-style=diesel.theme
. $(VENV)/activate && pandoc -t html5 --template=template.html -F code-block-filter.py --lua-filter=anchor-links.lua src/$*.md -o out/$*.html -s --syntax-definition=toml.xml --highlight-style=diesel.theme

page: index.html compare_diesel.html guides docs news changelog
cp -R assets/ out
Expand Down
16 changes: 16 additions & 0 deletions anchor-links.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- copied from https://github.com/jgm/pandoc-website/blob/master/tools/anchor-links.lua

-- Adds anchor links to headings with IDs.
function Header (h)
if h.identifier ~= '' then
-- an empty link to this header
local anchor_link = pandoc.Link(
{}, -- content
'#' .. h.identifier, -- href
'', -- title
{class = 'anchor', ['aria-hidden'] = 'true'} -- attributes
)
h.content:insert(1, anchor_link)
return h
end
end
Loading

0 comments on commit e3e6638

Please sign in to comment.