Mise en place de l'architecture générale sans code spécifique aux formats

This commit is contained in:
Bastien Dumont 2021-10-19 09:18:19 +02:00
parent 3e782fe447
commit d8340c7ed3
3 changed files with 68 additions and 22 deletions

View File

@ -67,12 +67,14 @@ If you want to know more about _L'Affaire Lerouge_, see [publication>reception]{
The separator (here `>`) can be set to any string composed of characters other than alphanumeric, period, colon, underscore, hyphen and space.
In LaTeX and ConTeXt output, the page range will be printed as a simple page reference if the page numbers are identical. You can provide your own definition of the macro `\tcrfpagerangeref{<label1>}{<label2>}` in the preamble. In DOCX and ODT/Opendocument output, the same result can be achieved in a word processor by the means of automatic search and replace with regular expressions.
In LaTeX and ConTeXt output, the page range will be printed as a simple page reference if the page numbers are identical. You can provide your own definition of the macro `\tcrfpagerangeref[<prefixed?>]{<label1>}{<label2>}` in the preamble. In DOCX and ODT/Opendocument output, the same result can be achieved in a word processor by the means of automatic search and replace with regular expressions.
## Enumerations
Rather
Enumerations are only supported for references to page and note numbers.
## Customization
The following metadata fields can be set as strings:
@ -86,6 +88,9 @@ The following metadata fields can be set as strings:
* `tcrf-note-prefix`:
* “note” prefix;
* defaults to `n. `.
* `tcrf-notes-prefix`:
* “notes” prefix;
* defaults to `n. `.
* `tcrf-pagenote-separator`:
* the separator between the references when `type` is set to `pagenote`;
* defaults to `, `.

View File

@ -25,3 +25,5 @@ I want to refer to a note:
* What formats are supported? → See [format]{.ref}.
* What if the note contains multiple spans with identifiers? → See [which-identifier]{.ref}.
* What happens if a span in contained in a span? → See [nested-spans]{.ref}.
* What are the notes? → [my-evaluation;format;refer-to-note]{.ref type=note}
* Where are the notes? → [my-evaluation;format]{.ref}

View File

@ -1,6 +1,8 @@
-- TODO : permettre la citation de références multiples avec un seul préfixe
-- [ref-one, ref-two>ref-four, ref-three]{.ref} → pp. 1, 3-6 et 12
-- Compléter README et test une fois que ce sera fait.
-- TODO : créer des commandes latex et context pour les énumérations
-- de notes et de pages sur le modèle de \tcrfpagerangeref
-- Begin of initialization
@ -50,6 +52,7 @@ local config = {
page_prefix = 'p. ',
pages_prefix = 'p. ',
note_prefix = 'n. ',
notes_prefix = 'n. ',
pagenote_order = 'pagefirst',
pagenote_separator = ', ',
pagenote_at_end = '',
@ -366,38 +369,53 @@ local function insert_page_target_in_xml(target)
end
end
local function format_page_reference(target)
if RAW_ATTRIBUTE == 'context' then
return config.page_prefix .. '\\at[' .. target .. ']'
elseif RAW_ATTRIBUTE == 'latex' then
return config.page_prefix .. '\\pageref{' .. target .. '}'
elseif RAW_ATTRIBUTE == 'opendocument' then
return config.page_prefix .. insert_page_target_in_xml(target)
elseif RAW_ATTRIBUTE == 'openxml' then
return config.page_prefix .. insert_page_target_in_xml(target)
local function format_prefix(info_type, is_enumeration)
if not is_enumeration then
return config[info_type .. '_prefix']
elseif RAW_ATTRIBUTE == 'context' or RAW_ATTRIBUTE == 'latex' then
return ''
elseif RAW_ATTRIBUTE == 'opendocument' or RAW_ATTRIBUTE == 'openxml' then
return config[info_type .. 's_prefix']
end
end
local function format_pagerange_reference(first, second)
local function format_page_reference(target)
if RAW_ATTRIBUTE == 'context' then
return '\\at[' .. target .. ']'
elseif RAW_ATTRIBUTE == 'latex' then
return '\\pageref{' .. target .. '}'
elseif RAW_ATTRIBUTE == 'opendocument' then
return insert_page_target_in_xml(target)
elseif RAW_ATTRIBUTE == 'openxml' then
return insert_page_target_in_xml(target)
end
end
local function format_pagerange_reference(first, second, is_prefixed)
if RAW_ATTRIBUTE == 'context' or RAW_ATTRIBUTE == 'latex' then
return '\\tcrfpagerangeref{' .. first .. '}{' .. second .. '}'
local bracketed_arg = ''
if is_prefixed then bracketed_arg = 'prefixed' end
-- TODO : implémenter l'argument entre crochets
return '\\tcrfpagerangeref[' .. bracketed_arg .. ']{' .. first .. '}{' .. second .. '}'
elseif RAW_ATTRIBUTE == 'opendocument' or RAW_ATTRIBUTE == 'openxml' then
return config.pages_prefix .. insert_page_target_in_xml(first) ..
local to_return = ''
if is_prefixed then to_return = config.pages_prefix end
return to_return .. insert_page_target_in_xml(first) ..
config.range_separator .. insert_page_target_in_xml(second)
end
end
local function format_note_reference(target)
if RAW_ATTRIBUTE == 'context' then
return config.note_prefix .. '\\in[' .. spans_to_note_labels[target] .. '_note' .. ']'
return '\\in[' .. spans_to_note_labels[target] .. '_note' .. ']'
elseif RAW_ATTRIBUTE == 'latex' then
return config.note_prefix .. '\\ref{' .. target .. '}'
return '\\ref{' .. target .. '}'
elseif RAW_ATTRIBUTE == 'opendocument' then
return config.note_prefix .. '<text:note-ref text:note-class="footnote"' ..
return '<text:note-ref text:note-class="footnote"' ..
' text:reference-format="text" text:ref-name="' ..
spans_to_note_labels[target] .. '">000</text:note-ref>'
elseif RAW_ATTRIBUTE == 'openxml' then
return config.note_prefix ..
return
'<w:r><w:fldChar w:fldCharType="begin" w:dirty="true"/></w:r>' ..
'<w:r><w:instrText xml:space="preserve"> NOTEREF ' ..
target .. '_Note' .. ' \\h </w:instrText></w:r>' ..
@ -409,10 +427,12 @@ end
local function format_pagenote_reference(target)
if config.pagenote_order == 'pagefirst' then
return format_page_reference(target) .. config.pagenote_separator ..
return format_prefix('page', false) .. format_page_reference(target) ..
config.pagenote_separator .. format_prefix('note', false) ..
format_note_reference(target) .. config.pagenote_at_end
elseif config.pagenote_order == 'notefirst' then
return format_note_reference(target) .. config.pagenote_separator ..
return format_prefix('note', false) .. format_note_reference(target) ..
config.pagenote_separator .. format_prefix('page', false) ..
format_page_reference(target) .. config.pagenote_at_end
else
error('tcrf-pagenote-order must be set either to pagefirst or notefirst.')
@ -421,7 +441,8 @@ end
local function format_reference(target, info_type)
if info_type == 'page' and target.is_range then
return format_pagerange_reference(target.first, target.second)
return format_pagerange_reference(target.first, target.second,
not target.is_enumeration)
elseif info_type == 'page' then
return format_page_reference(target.first)
elseif info_type == 'note' then
@ -434,13 +455,31 @@ local function format_reference(target, info_type)
end
end
local function make_reference_head(info_type, is_enumeration)
if info_type == 'page' or info_type == 'note' then
return format_prefix(info_type, is_enumeration)
else
return ''
end
end
local function make_reference_body(target, info_type)
end
local function make_reference_tail(info_type)
end
local function make_reference(span)
if has_class(span, 'ref') then
local target = analyze_reference_span(span)
if not target.is_external then
local info_type = span.attributes.type or config.default_info_type
local formatted_reference = format_reference(target, info_type)
span.content[1] = pandoc.RawInline(RAW_ATTRIBUTE, formatted_reference)
local head = make_reference_head(info_type, target.is_enumeration)
local body = make_reference_body(target, info_type)
local tail = make_reference_tail(info_type)
span.content[1] = pandoc.RawInline(RAW_ATTRIBUTE, head .. body .. tail)
return span
end
end