add useful lua filters

This commit is contained in:
Julien Fastré 2020-09-18 15:50:44 +02:00
parent e86c09c1b1
commit e7bb9d8e8a
4 changed files with 92 additions and 0 deletions

8
format-column.lua Normal file
View File

@ -0,0 +1,8 @@
-- Add a latex insecable space before ":" for words ending with ":"
function Str(elem)
if elem.text:sub(-1) == ":" then
return pandoc.RawInline("latex", elem.text:gsub(":", "~:"))
else
return elem
end
end

51
format-link.lua Normal file
View File

@ -0,0 +1,51 @@
if FORMAT:match 'latex' then
function Link (elem)
local abbrev = ''
if elem.c[3][1]:sub(2, 4) == 'fig' then
abbrev = 'fig.'
end
if elem.c[3][1]:sub(2, 4) == 'sec' then
abbrev = 'section'
end
if elem.c[1][2][1] == 'uri' then
return elem
else
if elem.c[2][1] ~= nil then
if elem.c[2][1].text == 'x' then
return {
pandoc.Str(abbrev),
pandoc.RawInline('latex', '~\\nameref{'),
pandoc.RawInline('latex', elem.c[3][1]:sub(2)),
pandoc.RawInline('latex', '}'),
pandoc.Str(', page'),
pandoc.RawInline('latex', '~\\pageref{'),
pandoc.RawInline('latex', elem.c[3][1]:sub(2)),
pandoc.RawInline('latex', '}')
}
end
return {
elem,
pandoc.Str(' ('),
pandoc.Str(abbrev),
pandoc.RawInline('latex', '~\\ref{'),
pandoc.RawInline('latex', elem.c[3][1]:sub(2)),
pandoc.RawInline('latex', '}'),
pandoc.Str(', page'),
pandoc.RawInline('latex', '~\\pageref{'),
pandoc.RawInline('latex', elem.c[3][1]:sub(2)),
pandoc.RawInline('latex', '}'),
pandoc.Str(')'),
}
end
end
end
end

25
format-quote.lua Normal file
View File

@ -0,0 +1,25 @@
-- fully copied from https://gist.github.com/niklaskorz/c9d55b157078dd1e1f5badad15093a72
local double_quotes = {"»", "«"}
local single_quotes = {"", ""}
function get_preferences(m)
if m.double_quotes and m.double_quotes[1] and m.double_quotes[2] then
double_quotes = { m.double_quotes[1][1].c, m.double_quotes[2][1].c }
end
if m.single_quotes and m.single_quotes[1] and m.single_quotes[2] then
single_quotes = { m.single_quotes[1][1].c, m.single_quotes[2][1].c }
end
end
function replace_quotes(elem)
local quotes = double_quotes
if elem.quotetype == "SingleQuote" then
quotes = single_quotes
end
return {pandoc.Str(quotes[2]), pandoc.RawInline('latex', '~')} .. elem.content .. {pandoc.RawInline('latex', '~'), pandoc.Str(quotes[1])}
end
return {
{ Meta = get_preferences },
{ Quoted = replace_quotes },
}

8
format-semi-column.lua Normal file
View File

@ -0,0 +1,8 @@
-- Add a latex insecable space before ";" for words ending with ";"
function Str(elem)
if elem.text:sub(-1) == ";" then
return pandoc.RawInline("latex", elem.text:gsub(";", "~;"))
else
return elem
end
end