From 5a039e9d077fb05d554a3ea33f1594f8f4fa0e37 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Thu, 3 Jun 2021 18:40:55 +0200 Subject: Generate anchor in body headings --- filters/common_actions.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'filters') diff --git a/filters/common_actions.lua b/filters/common_actions.lua index 5b6c86b..8383ada 100644 --- a/filters/common_actions.lua +++ b/filters/common_actions.lua @@ -1,15 +1,12 @@ function CodeBlock(el) if el.classes[1] == "plain" then - el = pandoc.Div({el}, {class = 's-code'}) + el = pandoc.Div({ el }, { class = 's-code' }) elseif el.classes[1] then local formatted = pandoc.pipe('pygmentize', { - '-l', el.classes[1], '-f', 'html', '-O', - 'cssclass=s-code s-code--highlight' + '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight', }, el.text) - if formatted then - el = pandoc.RawBlock('html', formatted) - end + if formatted then el = pandoc.RawBlock('html', formatted) end end return el @@ -18,11 +15,17 @@ end function Header(el) if el.level == 1 then local newchildren = pandoc.List() - - newchildren:insert(pandoc.Span(el.content, {class = 's-headlines__title-inner'})) - + newchildren:insert(pandoc.Span(el.content, { class = 's-headlines__title-inner' })) el.content = newchildren end + + if el.level <= 3 and el.identifier ~= '' then + el.content:insert(pandoc.Space()) + el.content:insert(pandoc.Link(pandoc.RawInline('html', + ''), + '#' .. el.identifier, nil, { class = 's-headlines__link' })) + end + return el end @@ -36,7 +39,7 @@ function Div(el) for _, children in ipairs(el.content[1].content) do newchildren:insert(pandoc.RawBlock('html', - '
  • ')) + '
  • ')) newchildren:extend(children) newchildren:insert(pandoc.RawBlock('html', '
  • ')) end -- cgit v1.2.3-54-g00ecf