-- 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