summaryrefslogtreecommitdiffstats
path: root/filters/common_actions.lua
blob: 262f086a85326cf332111f9f07bddaa38f8ad209 (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
function CodeBlock(el)
    if el.classes[1] == "plain" then
        el = pandoc.Div({el}, {class = 's-code'})
    else
        local formatted = pandoc.pipe('pygmentize', {
            '-l', el.classes[1], '-f', 'html', '-O',
            'cssclass=s-code s-code--highlight'
        }, el.text)
        el = pandoc.RawBlock('html', formatted)
    end

    return el
end

function Header(el)
    if el.level == 1 then
        local newchildren = pandoc.List()

        newchildren:insert(pandoc.Span(el.content, {class = 's-body__title-inner'}))

        el.content = newchildren
    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