Compare commits

..

No commits in common. "5ed8f515a9eb2f772cfbb96035c45ea77c2c70f2" and "ea71cae43ce2ba6781d0a63cb2e82fb644d6f932" have entirely different histories.

2 changed files with 36 additions and 45 deletions

View File

@ -22,7 +22,7 @@
, Space
, Str "published"
, Space
, Str ""
, RawInline (Format "latex") "\\label{publication}"
, Span
( "publication" , [] , [] )
[ Emph [ Str "L\8217Affaire" , Space , Str "Lerouge" ]
@ -43,7 +43,7 @@
, Space
, Str "very"
, Space
, Str ""
, RawInline (Format "latex") "\\label{my-evaluation}"
, Span
( "my-evaluation" , [] , [] )
[ Str "fine"
@ -60,7 +60,7 @@
, RawInline (Format "latex") ""
]
, Para
[ Str ""
[ RawInline (Format "latex") "\\label{reception}"
, Span
( "reception" , [] , [] )
[ Str "It"
@ -148,7 +148,7 @@
, RawInline (Format "latex") ""
, Note
[ Para
[ Str ""
[ RawInline (Format "latex") "\\label{format}"
, Span
( "format" , [] , [] )
[ Str "Whatever" , Space , Str "format" ]
@ -161,7 +161,7 @@
, Space
, Str "can"
, Space
, Str ""
, RawInline (Format "latex") "\\label{refer-to-note}"
, Span
( "refer-to-note" , [] , [] )
[ Str "refer"
@ -181,7 +181,7 @@
, Space
, Str "of"
, Space
, Str ""
, RawInline (Format "latex") "\\label{which-identifier}"
, Span
( "which-identifier" , [] , [] )
[ Str "any"
@ -198,7 +198,7 @@
, Space
, Str "even"
, Space
, Str ""
, RawInline (Format "latex") "\\label{nested-spans}"
, Span
( "nested-spans" , [] , [] )
[ Str "nest" , Space , Str "spans" ]
@ -209,7 +209,7 @@
, RawInline (Format "latex") ""
]
, Para
[ Str ""
[ RawInline (Format "latex") "\\label{toc-notes-begin}"
, Span
( "toc-notes-begin" , [] , [] )
[ Str "I"
@ -384,12 +384,15 @@
]
]
]
, Para [ Str "" , Span ( "toc-notes-end" , [] , [] ) [] ]
, Para
[ Str ""
[ RawInline (Format "latex") "\\label{toc-notes-end}"
, Span ( "toc-notes-end" , [] , [] ) []
]
, Para
[ RawInline (Format "latex") "\\label{doubledlbl}"
, Span
( "doubledlbl" , [] , [ ( "refanchor" , "both" ) ] )
[ Str ""
[ RawInline (Format "latex") "\\label{doubledlbl-beg}"
, Span ( "doubledlbl-beg" , [] , [] ) []
, Str "A"
, Space
@ -410,12 +413,12 @@
, Str "page"
, Space
, Str "break."
, Str ""
, RawInline (Format "latex") "\\label{doubledlbl-end}"
, Span ( "doubledlbl-end" , [] , [] ) []
]
]
, Para
[ Str ""
[ RawInline (Format "latex") "\\label{lblatend}"
, Span
( "lblatend" , [] , [ ( "refanchor" , "end" ) ] )
[ Str "And"
@ -433,7 +436,7 @@
, Str "the"
, Space
, Str "end."
, Str ""
, RawInline (Format "latex") "\\label{lblatend}"
, Span ( "lblatend" , [] , [] ) []
]
]

View File

@ -15,10 +15,6 @@ local PLACE_LABEL_ATTR = 'refanchor'
local IS_CONFIG_ARRAY = { ['additional_types'] = true }
local RAW_ATTRIBUTE
local function warning(message)
io.stderr:write('WARNING [text-crossrefs]: ' .. message .. '\n')
end
-- ConTeXt-specific tweak in order to add the label to the footnote
--[[
Placing the label in square brackets immediatly after \footnote
@ -216,8 +212,8 @@ local function control_label_placement(span)
span.content:insert(pandoc.Span({}, { id = id .. '-end' }))
span.identifier = nil
elseif label_placement ~= 'beg' then
warning('Invalid value ' .. label_placement .. ' on attribute ' .. PLACE_LABEL_ATTR .. ': ' ..
'shoud be “beg” (default), “end” of “both”. Using the defaults.')
error('Invalid value ' .. label_placement .. ' on attribute ' .. PLACE_LABEL_ATTR .. ': ' ..
'shoud be “beg” (default), “end” of “both”.')
end
end
return span
@ -241,14 +237,14 @@ local function labelize_span(span)
end
end
local labels_in_current_note = {}
local current_note_labels = {}
local collect_note_labels = {
Span = function(span)
if span.identifier ~= ''
and (config.only_explicit_labels == 'false' or span.classes:includes('label'))
then
table.insert(labels_in_current_note, span.identifier)
table.insert(current_note_labels, span.identifier)
end
end
}
@ -261,14 +257,14 @@ local function make_notelabel(pos)
if RAW_ATTRIBUTE == 'openxml' then
raw_code = string.gsub(
'<w:bookmarkStart w:id="{{label}}_Note" w:name="{{label}}_Note"/>',
'{{label}}', labels_in_current_note[1])
'{{label}}', current_note_labels[1])
elseif RAW_ATTRIBUTE == 'context' then
raw_code = '\\withfirstopt[note:' .. labels_in_current_note[1] .. ']'
raw_code = '\\withfirstopt[note:' .. current_note_labels[1] .. ']'
end
elseif pos == 'end' then
if RAW_ATTRIBUTE == 'openxml' then
raw_code = string.gsub('<w:bookmarkEnd w:id="{{label}}_Note"/>',
'{{label}}', labels_in_current_note[1])
'{{label}}', current_note_labels[1])
end
end
return pandoc.RawInline(RAW_ATTRIBUTE, raw_code)
@ -281,18 +277,18 @@ local function labelize_note(note)
return { label_begin, note, label_end }
end
local function map_text_to_note_labels(labels_in_current_note)
local note_label = 'note:' .. labels_in_current_note[1]
for _, label in ipairs(labels_in_current_note) do
text_to_note_labels[label] = note_label
local function map_text_to_note_labels(current_note_labels)
local note_label = 'note:' .. current_note_labels[1]
for _, text_label in ipairs(current_note_labels) do
text_to_note_labels[text_label] = note_label
end
end
function set_notelabels(note)
labels_in_current_note = {}
current_note_labels = {}
pandoc.walk_inline(note, collect_note_labels)
if #labels_in_current_note > 0 then
map_text_to_note_labels(labels_in_current_note)
if #current_note_labels > 0 then
map_text_to_note_labels(current_note_labels)
return labelize_note(note)
end
end
@ -342,8 +338,8 @@ local function parse_next_reference(raw_references, beg_of_search)
if beg_of_search < #raw_references then
-- The delimiter can be composed of more than one character.
local delim_beg, delim_end = string.find(raw_references,
config.references_enum_separator,
beg_of_search, true)
config.references_enum_separator,
beg_of_search, true)
if delim_beg then
reference = string.sub(raw_references, beg_of_search, delim_beg - 1)
next_ref_beg = delim_end + 1
@ -370,17 +366,15 @@ local function parse_references_enum(raw_references)
end
local function error_on_attr(attr_key, attr_value, span_content)
warning('Invalid value "' .. attr_value .. '" for attribute "' .. attr_key ..
error('Invalid value "' .. attr_value .. '" for attribute "' .. attr_key ..
'" in the span with class "' .. TEXT_CROSSREF_CLASS ..
'" whose content is "' .. stringify(span_content) .. '". ' ..
'Using the defaults.')
'" whose content is "' .. stringify(span_content) .. '".')
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, span.content)
ref_type = config.default_reftype
end
return ref_type
end
@ -389,7 +383,6 @@ local function if_prefixed(span)
local prefixed_attr_value = span.attributes[PREFIXED_ATTR] or config.default_prefixref
if prefixed_attr_value ~= 'yes' and prefixed_attr_value ~= 'no' then
error_on_attr(PREFIXED_ATTR, prefixed_attr_value, span.content)
prefixed_attr_value = config.default_prefixref
end
local is_prefixed = true
if prefixed_attr_value == 'no' then is_prefixed = false end
@ -432,12 +425,7 @@ local function make_crossrefenum_references_list(refs, ref_type)
if FORMAT == 'context'
and (ref_type == 'note' or ref_type == 'pagenote')
then
local note_label = text_to_note_labels[anchor]
if note_label then
anchor = note_label
else
warning('Wrong reference to non-existent label "' .. anchor .. '".')
end
anchor = text_to_note_labels[anchor]
end
local texified_ref = '{' .. anchor
if ref.end_of_range then