Implémentation du support pour des types arbitraires pour LaTeX et ConTeXt

This commit is contained in:
Bastien Dumont 2022-11-05 19:35:43 +01:00
parent ef8accbc81
commit bc209420fe

View File

@ -3,6 +3,7 @@ local stringify = pandoc.utils.stringify
local TEXT_CROSSREF_CLASS = 'tcrf'
local REF_TYPE_ATTR = 'reftype'
local PREFIXED_ATTR = 'prefixref'
local IS_CONFIG_ARRAY = { ['additional_types'] = true }
local RAW_ATTRIBUTE
-- ConTeXt-specific tweak in order to add the label to the footnote
@ -94,7 +95,8 @@ local config = {
default_reftype = 'page',
default_prefixref = 'yes',
filelabel_ref_separator = '::',
range_delim_tcrfenum = ' to '
range_delim_tcrfenum = ' to ',
additional_types = {}
}
local accepted_types = {
@ -122,8 +124,16 @@ end
local function set_configuration_item_from_metadata(item, metamap)
metakey = 'tcrf-' .. string.gsub(item, '_', '-')
if metamap[metakey] then
-- The metadata values are Str in MetaInlines.
config[item] = metamap[metakey][1].text
if IS_CONFIG_ARRAY[item] then
-- The metadata values is a list of MetaInlines,
-- each of them contains a single Str.
for _, value_metalist in ipairs(metamap[metakey]) do
table.insert(config[item], value_metalist[1].text)
end
else
-- The metadata value is a single Str in a MetaInlines.
config[item] = metamap[metakey][1].text
end
end
end
@ -136,6 +146,11 @@ local function configure(metadata)
if RAW_ATTRIBUTE == 'openxml' then
format_config_to_openxml()
end
if RAW_ATTRIBUTE == 'context' or RAW_ATTRIBUTE == 'latex' then
for _, additional_type in ipairs(config.additional_types) do
accepted_types[additional_type] = true
end
end
end
-- End of configuration
@ -342,7 +357,7 @@ end
local function get_ref_type(span)
local ref_type = span.attributes[REF_TYPE_ATTR] or config.default_reftype
if not accepted_types[ref_type] then
error_on_attr(REF_TYPE_ATTR, ref_type_attr_value, span.content)
error_on_attr(REF_TYPE_ATTR, ref_type, span.content)
end
return ref_type
end