Enumération fonctionnelle pour opendocument et openxml
This commit is contained in:
parent
1c06aceca3
commit
0bb74650d2
|
@ -107,7 +107,7 @@ The following metadata fields can be set as strings:
|
|||
* the string inserted between to page numbers in a range;
|
||||
* defaults to `-`.
|
||||
* `tcrf-references-enum-separator`:
|
||||
* the string used to separate the elements of an enumeration in a reference span; can be composed of any character not authorized in an identifier other than space or tab;
|
||||
* the character used to separate the elements of an enumeration in a reference span; can be any character not authorized in an identifier other than space or tab;
|
||||
* defaults to `;`.
|
||||
* `tcrf-multiple-delimiter`:
|
||||
* the string inserted between two elements (but the two last ones) in an enumeration;
|
||||
|
|
|
@ -60,6 +60,7 @@ local config = {
|
|||
multiple_before_last = ' and ',
|
||||
references_range_separator = '>',
|
||||
range_separator = '-',
|
||||
references_enum_separator = ';',
|
||||
only_explicit_labels = 'false',
|
||||
default_info_type = 'page',
|
||||
filelabel_ref_separator = '::'
|
||||
|
@ -337,12 +338,21 @@ local function get_second_reference(rawref)
|
|||
if is_reference_valid(ref) then return ref end
|
||||
end
|
||||
|
||||
local function is_ref_enumeration(raw_reference)
|
||||
if string.match(raw_reference, '%' .. config.references_enum_separator) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local function analyze_reference_span(reference_span)
|
||||
if #reference_span.content == 1 and reference_span.content[1].t == 'Str' then
|
||||
raw_reference = reference_span.content[1].c
|
||||
analyzed_reference = {}
|
||||
analyzed_reference.is_external = is_ref_external(raw_reference)
|
||||
analyzed_reference.is_range = is_ref_range(raw_reference)
|
||||
analyzed_reference.is_enumeration = is_ref_enumeration(raw_reference)
|
||||
if analyzed_reference.is_external then
|
||||
analyzed_reference.filelabel = get_extfilelabel(raw_reference)
|
||||
end
|
||||
|
@ -442,7 +452,7 @@ local function format_pagenote_reference(target)
|
|||
end
|
||||
|
||||
local function format_reference(target, info_type)
|
||||
if info_type == 'page' and target.is_range then
|
||||
if info_type == 'page' and target.is_range then
|
||||
return format_pagerange_reference(target.first, target.second,
|
||||
not target.is_enumeration)
|
||||
elseif info_type == 'page' then
|
||||
|
@ -457,20 +467,53 @@ 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
|
||||
local function make_reference_head(info_type, is_enumeration, is_range)
|
||||
if (info_type == 'page' or info_type == 'note') and not is_range then
|
||||
return format_prefix(info_type, is_enumeration)
|
||||
else
|
||||
return ''
|
||||
end
|
||||
end
|
||||
|
||||
local function make_reference_body(target, info_type)
|
||||
|
||||
local function format_all_items_in_enumeration(enum, info_type)
|
||||
local reference_body = ''
|
||||
local enumerated_ref_spans = {}
|
||||
for ref in string.gmatch(enum,
|
||||
'[^%' .. config.references_enum_separator .. ']+') do
|
||||
ref_span = pandoc.Span(ref, {['type'] = info_type})
|
||||
table.insert(enumerated_ref_spans, ref_span)
|
||||
end
|
||||
for i = 1, #enumerated_ref_spans do
|
||||
target_in_enum = analyze_reference_span(enumerated_ref_spans[i])
|
||||
reference_body = reference_body .. format_reference(target_in_enum, info_type)
|
||||
if i < #enumerated_ref_spans then
|
||||
if i < #enumerated_ref_spans-1 then
|
||||
reference_body = reference_body .. config.multiple_delimiter
|
||||
else
|
||||
reference_body = reference_body .. config.multiple_before_last
|
||||
end
|
||||
end
|
||||
end
|
||||
return reference_body
|
||||
end
|
||||
|
||||
local function make_reference_tail(info_type)
|
||||
local function format_enumeration(target, info_type)
|
||||
if RAW_ATTRIBUTE == 'context' or RAW_ATTRIBUTE == 'latex' then
|
||||
-- TODO
|
||||
return format_enumeration_smart(target.first, info_type)
|
||||
elseif RAW_ATTRIBUTE == 'opendocument' or RAW_ATTRIBUTE == 'openxml' then
|
||||
return format_all_items_in_enumeration(target.first, info_type)
|
||||
end
|
||||
end
|
||||
|
||||
local function make_reference_body(target, info_type)
|
||||
local reference_body
|
||||
if target.is_enumeration then
|
||||
reference_body = format_enumeration(target, info_type)
|
||||
else
|
||||
reference_body = format_reference(target, info_type)
|
||||
end
|
||||
return reference_body
|
||||
end
|
||||
|
||||
local function make_reference(span)
|
||||
|
@ -478,10 +521,9 @@ local function make_reference(span)
|
|||
local target = analyze_reference_span(span)
|
||||
if not target.is_external then
|
||||
local info_type = span.attributes.type or config.default_info_type
|
||||
local head = make_reference_head(info_type, target.is_enumeration)
|
||||
local head = make_reference_head(info_type, target.is_enumeration, target.is_range)
|
||||
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)
|
||||
span.content[1] = pandoc.RawInline(RAW_ATTRIBUTE, head .. body)
|
||||
return span
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user