Compare commits

..

2 Commits

Author SHA1 Message Date
Bastien Dumont
2f93c19908 Création de /misc et ajout de petits filtres 2024-05-24 00:39:33 +02:00
Bastien Dumont
c4c2526643 Implementation of “position” 2022-09-27 22:09:36 +02:00
6 changed files with 78 additions and 6 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

@ -130,3 +130,5 @@ mrgnn-define-renderings:
In that case, you will have to define `\mrgnnTerm` in your LaTeX or ConTeXt template. This macro takes one argument, which is the result of the processing of `note-text`.
The position of the instructions about the marginal note in the output file can be set _via_ the variable `position`. They can be placed `after` (default) or `before` the in-text content.

View File

@ -21,6 +21,8 @@ local PLACEHOLDER_REGEX = PLACEHOLDER_BEGIN ..
PLACEHOLDER_LABEL .. PLACEHOLDER_END
-- String indicating an indefined value in the output
local UNDEFINED = '??'
-- Default value for "position" ("before" or "after").
local POS_DEFAULT = 'after'
local DOCX_TOOLTIP_ANCHOR = '*'
local DOCX_TOOLTIP_ANCHOR_SYTLE = 'Tooltip anchor'
@ -89,7 +91,7 @@ function add_rendering(config, class,
body_text, note_text,
docx_body_text, docx_note_text,
odt_body_text, odt_note_text,
csname)
csname, position)
-- The values are plain strings (not the empty string!) or nil.
config[class] = {
body_text = body_text,
@ -98,7 +100,8 @@ function add_rendering(config, class,
docx_note_text = docx_note_text,
odt_body_text = odt_body_text,
odt_note_text = odt_note_text,
csname = csname
csname = csname,
position = position
}
end
@ -125,7 +128,8 @@ local function get_renderings_config(meta)
or this_value['body-text']),
meta_to_str(this_value['odt-note-text']
or this_value['note-text']),
meta_to_str(this_value['csname'])
meta_to_str(this_value['csname']),
meta_to_str(this_value['position']) or POS_DEFAULT
)
end
end
@ -526,6 +530,7 @@ local function render_margin_notes(span)
if span.classes:includes(class_name) then
local render_note = config[class_name].render.note
local render_body = config[class_name].render.body
local note_position = config[class_name].position
local margin_note = {}
local body = {}
if render_note then
@ -536,7 +541,19 @@ local function render_margin_notes(span)
body = render_body(span.content, span.attributes)
end
span.content = body
return { span, unpack_table(margin_note) }
local span_with_note = {}
if note_position == 'before' then
span_with_note = margin_note
insert_in_table(span_with_note, span)
elseif note_position == 'after' then
span_with_note = { span, unpack_table(margin_note) }
else
error('Invalid value "' .. note_position .. '" ' ..
'for "position" in the definition of ' ..
'the margin-note class "' .. class_name '". ' ..
'Expected "before" or "after".')
end
return span_with_note
end
end
end

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