doc: add anchor links to headings

This commit is contained in:
Michele Guerini Rocco 2021-12-15 02:31:01 +01:00
parent 861a723ebc
commit 58ee0bdc1b
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
3 changed files with 38 additions and 1 deletions

View File

@ -8,7 +8,7 @@
# Pandoc flags
FLAGS = --filter pandoc-crossref --citeproc --toc --number-sections
PDF_FLAGS = --pdf-engine=xelatex
HTML_FLAGS = --standalone --katex$(KATEX_URL)
HTML_FLAGS = --standalone --katex$(KATEX_URL) --lua-filter filters/add-anchors.lua
# Rebuild everything if the makefile changed
.EXTRA_PREREQS += Makefile

View File

@ -0,0 +1,14 @@
-- 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'} -- attributes
)
h.content:insert(1, anchor_link)
return h
end
end

View File

@ -3,12 +3,35 @@
box-sizing: border-box;
}
/* Make headings smaller */
h1 { font-size: 1.8em }
h2 { font-size: 1.4em }
h3 { font-size: 1.1em }
h1, h2, h3 { margin: 1em 0 }
/* Heading anchors */
.anchor::before {
content: '🔗';
font-size: 80%;
opacity: 0;
margin-right: -1.1em;
position: relative;
left: -1.2em;
z-index: 1;
}
.header-section-number,
.anchor::before { transition: opacity 0.3s ease 0.1s }
.anchor { text-decoration: none }
h1:hover > .anchor::before,
h2:hover > .anchor::before,
h3:hover > .anchor::before { opacity: 1; }
h1:hover > .header-section-number,
h2:hover > .header-section-number,
h3:hover > .header-section-number { opacity: 0; }
/* Match math and normal mode fonts */
body { font-size: 1.1em }
.katex { font-size: 1.0em !important }