Avoid unnecessary global variable

This commit is contained in:
Bastien Dumont
2025-12-18 21:47:59 +01:00
parent 77f14a96fe
commit 2eef26a5d9

View File

@ -247,19 +247,19 @@ local function labelize_span(span)
end
end
local labels_in_current_note = {}
local collect_note_labels = {
Span = function(span)
if span.identifier ~= ''
and ((not config.only_explicit_labels) or span.classes:includes('label'))
then
table.insert(labels_in_current_note, span.identifier)
local function collect_note_labels(labels_in_current_note)
return {
Span = function(span)
if span.identifier ~= ''
and ((not config.only_explicit_labels) or span.classes:includes('label'))
then
table.insert(labels_in_current_note, span.identifier)
end
end
end
}
}
end
local function make_notelabel(pos)
local function make_notelabel(pos, labels_in_current_note)
-- About the strategy followed with ConTeXt,
-- see above support_footnote_label_ConTeXt.
local raw_code = ''
@ -275,15 +275,16 @@ local function make_notelabel(pos)
if RAW_ATTRIBUTE == 'openxml' then
raw_code = string.gsub('<w:bookmarkEnd w:id="{{label}}_Note"/>',
'{{label}}', labels_in_current_note[1])
elseif RAW_ATTRIBUTE == 'typst' then
raw_code = '<note:' .. labels_in_current_note[1] .. '>'
end
end
return pandoc.RawInline(RAW_ATTRIBUTE, raw_code)
end
local function labelize_note(note)
local labelized_note
local label_begin = make_notelabel('begin')
local label_end = make_notelabel('end')
local function labelize_note(note, labels_in_current_note)
local label_begin = make_notelabel('begin', labels_in_current_note)
local label_end = make_notelabel('end', labels_in_current_note)
return { label_begin, note, label_end }
end
@ -295,11 +296,11 @@ local function map_text_to_note_labels(labels_in_current_note)
end
function set_notelabels(note)
labels_in_current_note = {}
pandoc.walk_inline(note, collect_note_labels)
local labels_in_current_note = {}
note:walk(collect_note_labels(labels_in_current_note))
if #labels_in_current_note > 0 then
map_text_to_note_labels(labels_in_current_note)
return labelize_note(note)
return labelize_note(note, labels_in_current_note)
end
end