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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
-- pandoc filters for www.btbytes.com
-- typical invocation:
-- pandoc -C -s --csl=../csl/jcsl.csl --bibliography=../bib/nbrefs.bib --lua-filter=../../pandoc/filters.lua tst.md -o tst.html

-- generated by ChatGPT and modified by me
-- function Str(elem)
--     local text = elem.text

--     -- Pattern for [[Article|/log/foo.html]]
--     local linked_pattern = "%[%[(.-)|(/.-)%]%]"
--     -- Pattern for [[Random Forests|random-forests]]
--     local simple_pattern = "%[%[(%w+)%]%]"
--     -- Pattern for [[Random Forests|random-forests]]
--     local title_wikilink_pattern = "%[%[(.- +)|(%w-)%]%]"

--     local replacement = text:gsub(linked_pattern, function(label, link)
--         return '<a href="' .. link .. '" class="wikilink fa-thin fa-location-dot">' .. label .. '</a>'
--     end)

--     replacement = replacement:gsub(simple_pattern, function(tag)
--         return '<a href="/' .. tag .. '.html" class="wikilink fa-thin fa-location-dot">' .. tag .. '</a>'
--     end)

--     replacement = replacement:gsub(title_wikilink_pattern, function(label, tag)
--         return '<a href="/' .. tag .. '.html" class="wikilink fa-thin fa-location-dot">' .. label .. '</a>'
--     end)

--     if replacement ~= text then
--         return pandoc.RawInline('html', replacement)
--     end
-- end
function Str(elem)
    local text = elem.text

    -- Pattern to match [[label|link]]
    local label_link_pattern = "%[%[(.-)|(/.-)%]%]" --"%[%[(.-)|(/?.-)%]%]"

    -- Pattern to match [[link]] where link doesn't contain spaces
    local simple_link_pattern = "%[%[([^%s]+)%]%]"

    -- Pattern to match [[label|simple-link]]
    local label_simple_link_pattern = "%[%[(.-)|([^%s]+)%]%]"

    -- Replacement for the label|link pattern
    text = text:gsub(label_link_pattern, function(label, link)
        return '<a href="' .. link .. '" class="wikilink">' .. label .. '</a>'
    end)

    -- Replacement for the label|simple-link pattern
    text = text:gsub(label_simple_link_pattern, function(label, link)
        return '<a href="/' .. link .. '.html" class="wikilink">' .. label .. '</a>'
    end)

    -- Replacement for the simple link pattern
    text = text:gsub(simple_link_pattern, function(link)
        return '<a href="/' .. link .. '.html" class="wikilink">' .. link .. '</a>'
    end)

    if text ~= elem.text then
        return pandoc.RawInline('html', text)
    end
end


-- generated by ChatGPT and modified by me
function Link(el)
    local patterns = {
        ["https://www.youtube.com/"] = '<i class="fa fa-youtube"></i>',
        ["https://twitter.com/"] = '<i class="fa fa-twitter"></i>',
        ["https://x.com/"] = '<i class="fa fa-twitter"></i>',
        ["https://github.com/"] = '<i class="fa fa-github"></i>',
        ["https://gist.github.com/"] = '<i class="fa fa-github"></i>'
    }

    for prefix, icon_html in pairs(patterns) do
        if el.target:sub(1, #prefix) == prefix then
            local icon = pandoc.RawInline('html', icon_html)
            table.insert(el.content, 1, icon)
            break
        end
    end

    return el
end