Création de /misc et ajout de petits filtres

This commit is contained in:
Bastien Dumont 2024-05-24 00:39:33 +02:00
parent c4c2526643
commit 2f93c19908
4 changed files with 55 additions and 2 deletions

View File

@ -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).

View File

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

31
misc/espaces-fines.lua Normal file
View File

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

View File

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