summaryrefslogtreecommitdiffstats
path: root/filters/vars.lua
blob: b0fa66ca3a505ea90a14b9c5ce2babc6fa8d9702 (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
local common = require 'filters.lib.common'

local vars = {}

function meta(meta) vars = meta end

function str(el)
    local prefix, varref, suffix = el.text:match('^(.*)%%([^ ]+)%%(.*)$')

    if varref then
        local parts = varref:split(".")
        local var = vars

        for i = 1, #parts do
            local part = parts[i]
            local v = var[part]

            if not v then return el end

            var = v
        end

        if var then return pandoc.Str(prefix .. var .. suffix) end
    end

    return el
end

return { { Meta = meta }, { Str = str } }