summaryrefslogtreecommitdiffstats
path: root/filters/common_actions.lua
blob: 9ebcf17dcdbef007c4096e7b8c2eb07118a0f4f7 (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
function CodeBlock(el)
    if next(el.classes) == nil then
        el.classes = el.classes .. {'c-page__prefixed', 'c-page__prefixed--pre'}
    elseif 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
        el.classes = el.classes .. {'c-page__prefixed', 'c-page__prefixed--h1'}
    elseif el.level == 2 then
        el.classes = el.classes .. {'c-page__prefixed', 'c-page__prefixed--h2'}
    elseif el.level == 3 then
        el.classes = el.classes .. {'c-page__prefixed', 'c-page__prefixed--h3'}
    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 k, 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