diff --git a/doc/Makefile b/doc/Makefile index e49236c..883fb18 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -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 diff --git a/doc/filters/add-anchors.lua b/doc/filters/add-anchors.lua new file mode 100644 index 0000000..0e09dc7 --- /dev/null +++ b/doc/filters/add-anchors.lua @@ -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 diff --git a/doc/res/style.css b/doc/res/style.css index 8857bbf..ee5746f 100644 --- a/doc/res/style.css +++ b/doc/res/style.css @@ -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 }