summaryrefslogtreecommitdiffstats
path: root/filters/common_actions.lua
blob: 5b6c86b2203a5503873aa39c8388950d8b86e84e (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
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
    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