summaryrefslogtreecommitdiffstats
path: root/filters/common_actions.lua
blob: 8383ada8e4aa0275a00462b8b7c5ed85755bcc08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function CodeBlock(el)
    if el.classes[1] == "plain" then
        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',
        }, el.text)

        if formatted then el = pandoc.RawBlock('html', formatted) end
    end

    return el
end

function Header(el)
    if el.level == 1 then
        local newchildren = pandoc.List()
        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',
            '<svg class="o-icon"><use href="/symbols.svg#icon-link"></use></svg>'),
            '#' .. el.identifier, nil, { class = 's-headlines__link' }))
    end

    return el
end

function Div(el)
    if el.attributes.macro == nil then return el end

    if el.attributes.macro == 'refs' and el.content[1].tag == 'BulletList' then
        local newchildren = pandoc.List()

        newchildren:insert(pandoc.RawBlock('html', '<ul>'))

        for _, children in ipairs(el.content[1].content) do
            newchildren:insert(pandoc.RawBlock('html',
                '<li class="c-page__prefixed c-page__prefixed--ref">'))
            newchildren:extend(children)
            newchildren:insert(pandoc.RawBlock('html', '</li>'))
        end

        newchildren:insert(pandoc.RawBlock('html', '</ul>'))

        el.content = newchildren
    end

    return el.content
end