Création de /misc et ajout de petits filtres
This commit is contained in:
31
misc/espaces-fines.lua
Normal file
31
misc/espaces-fines.lua
Normal 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 }
|
||||
}
|
||||
Reference in New Issue
Block a user