summaryrefslogtreecommitdiffstats
path: root/filters/vars.lua
blob: 61803cb3d1541be85c5ff1f9f5a048cbe6a734e2 (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 utils = require 'pandoc.utils'
local common = require 'scripts.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
            var = var[parts[i]]

            if not var then
                return el
            end
        end

        return pandoc.Str(prefix .. utils.stringify(var) .. suffix)
    end

    return el
end

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