From d8340c7ed36c821c294a35ecc95222c2a0e0df40 Mon Sep 17 00:00:00 2001 From: Bastien Dumont Date: Tue, 19 Oct 2021 09:18:19 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20en=20place=20de=20l'architecture=20g?= =?UTF-8?q?=C3=A9n=C3=A9rale=20sans=20code=20sp=C3=A9cifique=20aux=20forma?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++- sample.md | 2 ++ text-crossrefs.lua | 81 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b4c2037..8ad860b 100644 --- a/README.md +++ b/README.md @@ -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{}{}` 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[]{}{}` 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 `, `. diff --git a/sample.md b/sample.md index 13c7f35..e78a2cf 100644 --- a/sample.md +++ b/sample.md @@ -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} diff --git a/text-crossrefs.lua b/text-crossrefs.lua index f4a62f3..ad959b7 100644 --- a/text-crossrefs.lua +++ b/text-crossrefs.lua @@ -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 .. '000' elseif RAW_ATTRIBUTE == 'openxml' then - return config.note_prefix .. + return '' .. ' NOTEREF ' .. target .. '_Note' .. ' \\h ' .. @@ -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