diff --git a/README.md b/README.md index ce3c66e..8aa7e59 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ A collection of Lua filters for [Pandoc](https://pandoc.org/), mainly targeting academic wrinting in social sciences and the humanities. -All filters are under the MIT License. Issues and pull requests are -wellcome: you can register via +All filters are under the MIT License, except those under `/misc`, +which are trivial scripts in the public domain. +Issues and pull requests are wellcome: you can register via [OpenID](https://en.wikipedia.org/wiki/OpenID). diff --git a/misc/en-dash-to-hyphen-in-ranges.lua b/misc/en-dash-to-hyphen-in-ranges.lua new file mode 100644 index 0000000..1df7934 --- /dev/null +++ b/misc/en-dash-to-hyphen-in-ranges.lua @@ -0,0 +1,5 @@ +function Str (s) + if string.match(s.text, '[0-9mdclxviA-C]+–[0-9mdclxviB-D]+') then + return pandoc.Str(string.gsub(s.text, '–', '-')) + end +end diff --git a/misc/espaces-fines.lua b/misc/espaces-fines.lua new file mode 100644 index 0000000..f48e316 --- /dev/null +++ b/misc/espaces-fines.lua @@ -0,0 +1,31 @@ +-- Transforme une espace insécable normale en espace fine insécable +-- selon les conventions de la typographie française. + +-- Lorsqu'un point-virgule est protégé dans une citation, il est représenté +-- comme un objet Str à lui tout seul dans l'AST. La fonction Inlines sert +-- à normaliser cette séquence avant le traitement par la fonction Str et +-- prévient d'autres anomalies de ce type. + +function Inlines(inlines) + for i = #inlines-1, 2, -1 do + if inlines[i].t == "Str" and string.match(inlines[i].text, "^[;!?]$") + and inlines[i-1].t == "Str" and string.match(inlines[i-1].text, ".* $") + then + inlines[i-1].text = inlines[i-1].text .. inlines[i].text + inlines:remove(i) + end + end + return inlines +end + +function Str(elem) + if string.match(elem.text, ".* [;!?]$") then + new, _ = string.gsub(elem.text, " ([;!?])", utf8.char(8239) .. "%1") + return pandoc.Str(new) + end +end + +return { + { Inlines = Inlines }, + { Str = Str } +} diff --git a/misc/remove-leading-softbreaks-footnotes.lua b/misc/remove-leading-softbreaks-footnotes.lua new file mode 100644 index 0000000..cc7bc9d --- /dev/null +++ b/misc/remove-leading-softbreaks-footnotes.lua @@ -0,0 +1,16 @@ +--[[ + When a long footnote is inserted like this^[ + Here is my footnote. + It spans several lines! + ], Pandoc retains the initial line break in the AST, + causing the insertion of a space + at the beginning of the footnote in the output. + This filter removes any line break + at the beginning of a footnote. +]]-- + +function Note(note) + local content = note.content[1].content + if content[1].t == 'SoftBreak' then table.remove(content, 1) end + return note +end