From 81a247c6bf47852f3c9bbfb280c582b70a644761 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 18 Nov 2024 22:09:34 +0100 Subject: [PATCH 01/17] Prevent unintended side-effects of filter functions --- src/resources/filters/normalize/flags.lua | 3 +-- src/resources/filters/quarto-pre/table-captions.lua | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/resources/filters/normalize/flags.lua b/src/resources/filters/normalize/flags.lua index 8815da0a2f..d695d39b45 100644 --- a/src/resources/filters/normalize/flags.lua +++ b/src/resources/filters/normalize/flags.lua @@ -107,8 +107,7 @@ function compute_flags() -- FIXME: are we actually triggering this with FloatRefTargets? -- table captions local kTblCap = "tbl-cap" - local tblCap = extractTblCapAttrib(node,kTblCap) - if hasTableRef(node) or tblCap then + if hasTableRef(node) or node.attr.attributes[kTblCap] then flags.has_table_captions = true end diff --git a/src/resources/filters/quarto-pre/table-captions.lua b/src/resources/filters/quarto-pre/table-captions.lua index ede527f83e..e2fb7525b5 100644 --- a/src/resources/filters/quarto-pre/table-captions.lua +++ b/src/resources/filters/quarto-pre/table-captions.lua @@ -231,7 +231,7 @@ function extractTblCapAttrib(el, name, subcap) else value = pandoc.List({ value }) end - el.attr.attributes[name] = nil + -- el.attr.attributes[name] = nil return value end return nil From 1482bc302e2a07721a1d88b18a9064a878b59c78 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 19 Nov 2024 11:57:33 +0100 Subject: [PATCH 02/17] table-rawhtml: destructively modify the input list Minor performance improvement. --- .../filters/quarto-pre/table-rawhtml.lua | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/resources/filters/quarto-pre/table-rawhtml.lua b/src/resources/filters/quarto-pre/table-rawhtml.lua index 41708cd51b..e36e946c31 100644 --- a/src/resources/filters/quarto-pre/table-rawhtml.lua +++ b/src/resources/filters/quarto-pre/table-rawhtml.lua @@ -14,23 +14,32 @@ function table_merge_raw_html() return { Blocks = function(blocks) - local pendingRaw = pandoc.List() - local merged = pandoc.List() - for i,el in ipairs(blocks) do - if _quarto.format.isRawHtml(el) and el.text:find(patterns.html_table_tag_name) then - pendingRaw:insert(el.text) + local pending_raw = pandoc.List() + local next_element_idx = 1 + for _, el in ipairs(blocks) do + if _quarto.format.isRawHtml(el) and + el.text:find(patterns.html_table_tag_name) then + pending_raw:insert(el.text) else - if #pendingRaw > 0 then - merged:insert(pandoc.RawBlock("html", table.concat(pendingRaw, "\n"))) - pendingRaw = pandoc.List() + if next(pending_raw) then + blocks[next_element_idx] = + pandoc.RawBlock("html", table.concat(pending_raw, "\n")) + pending_raw = pandoc.List() + next_element_idx = next_element_idx + 1 end - merged:insert(el) + blocks[next_element_idx] = el + next_element_idx = next_element_idx + 1 end end - if #pendingRaw > 0 then - merged:insert(pandoc.RawBlock("html", table.concat(pendingRaw, "\n"))) + if #pending_raw > 0 then + blocks[next_element_idx] = + pandoc.RawBlock("html", table.concat(pending_raw, "\n")) + next_element_idx = next_element_idx + 1 end - return merged + for i = next_element_idx, #blocks do + blocks[i] = nil + end + return blocks end } end @@ -54,4 +63,4 @@ function table_respecify_gt_css() return el end } -end \ No newline at end of file +end From 762b65650ace20de02948dde3e449c10fd8ab1ac Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 19 Nov 2024 11:59:36 +0100 Subject: [PATCH 03/17] lightbox: Restart imgCount each time the filter is invoked. This allows to get reproducible output when running the filter multiple times. --- src/resources/filters/layout/lightbox.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/resources/filters/layout/lightbox.lua b/src/resources/filters/layout/lightbox.lua index 15203c120f..d2569bd68d 100644 --- a/src/resources/filters/layout/lightbox.lua +++ b/src/resources/filters/layout/lightbox.lua @@ -176,10 +176,11 @@ function lightbox() return {{ traverse = "topdown", - Meta = function(meta) + Meta = function(meta) -- Set auto lightbox mode, if need be auto = lightbox_module.automatic(meta) == true - end, + imgCount = 0 + end, -- Find images that are already within links -- we'll use this to filter out these images if -- the most is auto From 20155a896b63a28087c55e355327ea5f35e763bd Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 19 Nov 2024 17:26:11 +0100 Subject: [PATCH 04/17] Return modified meta object from init filter If the metadata object is modified in a filter, then it should be returned, as otherwise the changes might be lost. In the given case, the return wasn't necessary, because filters that act only on `Meta` objects are handled specially, in that the filter function is called directly, without doing an actual traversal via `walk`. However, this can lead to unexpected bugs; explicitly returning the modified Meta object is cleaner and more robust. --- src/resources/filters/quarto-init/metainit.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/resources/filters/quarto-init/metainit.lua b/src/resources/filters/quarto-init/metainit.lua index 9c3a22407d..9b63df4121 100644 --- a/src/resources/filters/quarto-init/metainit.lua +++ b/src/resources/filters/quarto-init/metainit.lua @@ -8,6 +8,7 @@ function quarto_meta_init() read_includes(meta) init_crossref_options(meta) initialize_custom_crossref_categories(meta) + return meta end } -end \ No newline at end of file +end From 8bec5e35f6a677a4ad41318a2b125f1204dec2da Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 19 Nov 2024 17:27:38 +0100 Subject: [PATCH 05/17] Fix check for empty captions in parsefiguredivs filters The `long` field of a caption can never be nil, but it can be an empty list. --- src/resources/filters/quarto-pre/parsefiguredivs.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/resources/filters/quarto-pre/parsefiguredivs.lua b/src/resources/filters/quarto-pre/parsefiguredivs.lua index ca075b0a5a..da12f28bb1 100644 --- a/src/resources/filters/quarto-pre/parsefiguredivs.lua +++ b/src/resources/filters/quarto-pre/parsefiguredivs.lua @@ -236,7 +236,7 @@ function parse_floatreftargets() end local caption = refCaptionFromDiv(div) if caption ~= nil then - div.content:remove(#div.content) + div.content:remove() -- drop the last element elseif div.attributes[caption_attr_key] ~= nil then caption = pandoc.Plain(string_to_quarto_ast_inlines(div.attributes[caption_attr_key])) div.attributes[caption_attr_key] = nil @@ -246,10 +246,10 @@ function parse_floatreftargets() local found_caption = false content = _quarto.ast.walk(content, { Table = function(table) - if table.caption.long ~= nil then + -- check if caption is non-empty + if table.caption.long and next(table.caption.long) then found_caption = true caption = table.caption.long[1] -- what if there's more than one entry here? - table.caption.long = nil return table end end From cf1729a7d327394973e9170182cc39d7daa77be9 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 19 Nov 2024 21:20:20 +0100 Subject: [PATCH 06/17] Use proper metadata types when resolving dependencies --- src/resources/pandoc/datadir/init.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/resources/pandoc/datadir/init.lua b/src/resources/pandoc/datadir/init.lua index 1dc45ed14b..4c7f1eecac 100644 --- a/src/resources/pandoc/datadir/init.lua +++ b/src/resources/pandoc/datadir/init.lua @@ -1546,9 +1546,9 @@ local function processTextDependency(dependency, meta) local textLoc = rawText.location if meta[textLoc] == nil then - meta[textLoc] = {} + meta[textLoc] = pandoc.List{} end - table.insert(meta[textLoc], pandoc.RawBlock(FORMAT, rawText.text)) + meta[textLoc]:insert(pandoc.Blocks{pandoc.RawBlock(FORMAT, rawText.text)}) end -- make the usePackage statement @@ -1568,9 +1568,9 @@ local function usePackage(package, option) local headerLoc = resolveLocation(kInHeader) if meta[headerLoc] == nil then - meta[headerLoc] = {} + meta[headerLoc] = pandoc.List{} end - table.insert(meta[headerLoc], usePackage(rawPackage.package, rawPackage.options)) + meta[headerLoc]:insert(usePackage(rawPackage.package, rawPackage.options)) end @@ -1584,28 +1584,28 @@ local function processDependencies(meta) -- holds a list of hashes for dependencies that -- have been processed. Process each dependency -- only once - local injectedText = {} - local injectedFile = {} - local injectedPackage = {} + local injectedText = pandoc.List{} + local injectedFile = pandoc.List{} + local injectedPackage = pandoc.List{} -- each line was written as a dependency. -- process them and contribute the appropriate headers - for line in io.lines(dependenciesFile) do + for line in io.lines(dependenciesFile) do local dependency = json.decode(line) if dependency.type == 'text' then if not utils.table.contains(injectedText, dependency.content) then processTextDependency(dependency, meta) - injectedText[#injectedText + 1] = dependency.content + injectedText:insert(dependency.content) end elseif dependency.type == "file" then if not utils.table.contains(injectedFile, dependency.content.path) then processFileDependency(dependency, meta) - injectedFile[#injectedFile + 1] = dependency.content.path + injectedFile:insert(dependency.content.path) end elseif dependency.type == "usepackage" then if not utils.table.contains(injectedPackage, dependency.content.package) then processUsePackageDependency(dependency, meta) - injectedPackage[#injectedPackage + 1] = dependency.content.package + injectedPackage:insert(dependency.content.package) end end end From 2b7fba14779ebe3498b735efea2c635ed16bc1b3 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Wed, 20 Nov 2024 17:42:47 +0100 Subject: [PATCH 07/17] Ensure that the internal Meta copy is a true, deep copy --- src/resources/filters/customnodes/content-hidden.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/resources/filters/customnodes/content-hidden.lua b/src/resources/filters/customnodes/content-hidden.lua index f27af5a541..9117085009 100644 --- a/src/resources/filters/customnodes/content-hidden.lua +++ b/src/resources/filters/customnodes/content-hidden.lua @@ -105,7 +105,8 @@ local _content_hidden_meta = nil function content_hidden_meta(meta) -- return { -- Meta = function(meta) - _content_hidden_meta = meta + -- The call to `pandoc.Meta` ensures that we hold a copy. + _content_hidden_meta = pandoc.Meta(meta) -- end -- } end From a0acec2a20466bd045088f403f452c74ce555fc0 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Wed, 20 Nov 2024 18:58:42 +0100 Subject: [PATCH 08/17] Don't add number values to the metadata object --- src/resources/filters/quarto-post/typst.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/resources/filters/quarto-post/typst.lua b/src/resources/filters/quarto-post/typst.lua index 4a2e7f8d6f..d5c1286333 100644 --- a/src/resources/filters/quarto-post/typst.lua +++ b/src/resources/filters/quarto-post/typst.lua @@ -19,7 +19,9 @@ function render_typst() return { { Meta = function(m) - m["toc-depth"] = PANDOC_WRITER_OPTIONS["toc_depth"] + -- This should be a number, but we must represent it as a string, + -- as numbers are disallowed as metadata values. + m["toc-depth"] = tostring(PANDOC_WRITER_OPTIONS["toc_depth"]) m["toc-indent"] = option("toc-indent") if m["number-depth"] then number_depth = tonumber(pandoc.utils.stringify(m["number-depth"])) From b3a04720549d240a4d66e3f6fb0f8cfa1c1907c2 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Thu, 21 Nov 2024 11:28:20 +0100 Subject: [PATCH 09/17] Custom nodes: cleanup code for slots/forwarder --- src/resources/filters/ast/customnodes.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/resources/filters/ast/customnodes.lua b/src/resources/filters/ast/customnodes.lua index ca61ebc39b..0b1c5d8550 100644 --- a/src/resources/filters/ast/customnodes.lua +++ b/src/resources/filters/ast/customnodes.lua @@ -416,13 +416,15 @@ _quarto.ast = { -- luacov: enable end - local forwarder = { } + local forwarder if tisarray(handler.slots) then + forwarder = pandoc.List{} for i, slot in ipairs(handler.slots) do forwarder[slot] = i end - else - forwarder = handler.slots + elseif handler.slots ~= nil then + warn('Expected `slots` to be either an array or nil, got ' .. + tostring(handler.slots)) end quarto[handler.ast_name] = function(params) From fb6a801052d629a756088c5be1e76410636b5262 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Thu, 21 Nov 2024 11:28:47 +0100 Subject: [PATCH 10/17] Fix type of return value in typst filter function --- src/resources/filters/quarto-post/typst.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/filters/quarto-post/typst.lua b/src/resources/filters/quarto-post/typst.lua index d5c1286333..8ebd9c8759 100644 --- a/src/resources/filters/quarto-post/typst.lua +++ b/src/resources/filters/quarto-post/typst.lua @@ -140,7 +140,7 @@ function render_typst_fixups() end img.attributes["fig-align"] = nil - return pandoc.Inlines({ + return pandoc.Plain({ pandoc.RawInline("typst", "#align(" .. align .. ")["), img, pandoc.RawInline("typst", "]"), From 8c25e4c1bfd53242075e4e06105452f247da5eac Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Fri, 22 Nov 2024 14:44:45 +0100 Subject: [PATCH 11/17] Fix type in Caption --- src/resources/filters/quarto-pre/parsefiguredivs.lua | 2 +- src/resources/filters/quarto-pre/table-captions.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resources/filters/quarto-pre/parsefiguredivs.lua b/src/resources/filters/quarto-pre/parsefiguredivs.lua index da12f28bb1..e0e3318c42 100644 --- a/src/resources/filters/quarto-pre/parsefiguredivs.lua +++ b/src/resources/filters/quarto-pre/parsefiguredivs.lua @@ -494,7 +494,7 @@ function parse_floatreftargets() end -- we've parsed the caption, so we can remove it from the table - el.caption.long = pandoc.List({}) + el.caption.long = pandoc.Blocks({}) if label == "" then return nil diff --git a/src/resources/filters/quarto-pre/table-captions.lua b/src/resources/filters/quarto-pre/table-captions.lua index e2fb7525b5..67a3917f75 100644 --- a/src/resources/filters/quarto-pre/table-captions.lua +++ b/src/resources/filters/quarto-pre/table-captions.lua @@ -140,7 +140,7 @@ function applyTableCaptions(el, tblCaptions, tblLabels) cap:insert(pandoc.Str("{#" .. tblLabels[idx] .. "}")) end idx = idx + 1 - el.caption.long = pandoc.Plain(cap) + el.caption.long = pandoc.Blocks{pandoc.Plain(cap)} return el end end, From a8f626b4172d52cc4a1fb37c3a23ac322573ad02 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 25 Nov 2024 10:07:47 +0100 Subject: [PATCH 12/17] Ensure proper Callout rendering if title is set but empty --- src/resources/filters/customnodes/callout.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/resources/filters/customnodes/callout.lua b/src/resources/filters/customnodes/callout.lua index 8a9f4c17de..929c9c5cb8 100644 --- a/src/resources/filters/customnodes/callout.lua +++ b/src/resources/filters/customnodes/callout.lua @@ -264,7 +264,8 @@ function _callout_main() return _quarto.format.typst.function_call("callout", { { "body", _quarto.format.typst.as_typst_content(callout.content) }, { "title", _quarto.format.typst.as_typst_content( - callout.title or pandoc.Plain(_quarto.modules.callouts.displayName(callout.type)) + (not quarto.utils.is_empty_node(callout.title) and callout.title) or + pandoc.Plain(_quarto.modules.callouts.displayName(callout.type)) )}, { "background_color", pandoc.RawInline("typst", background_color) }, { "icon_color", pandoc.RawInline("typst", icon_color) }, @@ -406,4 +407,4 @@ function crossref_callouts() return callout end } -end \ No newline at end of file +end From 39f4606d6e9d2f17d48f8c3e25aa1dbbaa9ebb6c Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Thu, 24 Oct 2024 18:52:44 +0200 Subject: [PATCH 13/17] Use the correct type (Blocks/Inlines) for lists of elements --- src/resources/filters/crossref/equations.lua | 2 +- src/resources/filters/crossref/preprocess.lua | 2 +- src/resources/filters/customnodes/floatreftarget.lua | 4 ++-- src/resources/filters/customnodes/shortcodes.lua | 8 ++++---- src/resources/filters/layout/html.lua | 2 +- src/resources/filters/quarto-post/foldcode.lua | 2 +- src/resources/filters/quarto-pre/code-annotation.lua | 2 +- src/resources/filters/quarto-pre/output-location.lua | 2 +- src/resources/filters/quarto-pre/parsefiguredivs.lua | 6 +++--- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/resources/filters/crossref/equations.lua b/src/resources/filters/crossref/equations.lua index f8a12e64f2..0ecb0e430b 100644 --- a/src/resources/filters/crossref/equations.lua +++ b/src/resources/filters/crossref/equations.lua @@ -20,7 +20,7 @@ function process_equations(blockEl) end local mathInlines = nil - local targetInlines = pandoc.List() + local targetInlines = pandoc.Inlines{} for i, el in ipairs(inlines) do diff --git a/src/resources/filters/crossref/preprocess.lua b/src/resources/filters/crossref/preprocess.lua index 1b995b78a6..6a7c113fe2 100644 --- a/src/resources/filters/crossref/preprocess.lua +++ b/src/resources/filters/crossref/preprocess.lua @@ -7,7 +7,7 @@ function crossref_mark_subfloats() return { traverse = "topdown", FloatRefTarget = function(float) - float.content = _quarto.ast.walk(float.content, { + float.content = _quarto.ast.walk(float.content or pandoc.Blocks{}, { FloatRefTarget = function(subfloat) float.has_subfloats = true crossref.subfloats[subfloat.identifier] = { diff --git a/src/resources/filters/customnodes/floatreftarget.lua b/src/resources/filters/customnodes/floatreftarget.lua index 03c7d35cc0..9f75512fc0 100644 --- a/src/resources/filters/customnodes/floatreftarget.lua +++ b/src/resources/filters/customnodes/floatreftarget.lua @@ -767,7 +767,7 @@ function float_reftarget_render_html_figure(float) local float_content = pandoc.Div(_quarto.ast.walk(float.content, { -- strip image captions Image = function(image) - image.caption = {} + image.caption = pandoc.Inlines{} return image end }) or pandoc.Div({})) -- this should never happen but the lua analyzer doesn't know it @@ -1098,4 +1098,4 @@ end, function(float) return pandoc.Para({im}) end) -global_table_guid_id = 0 \ No newline at end of file +global_table_guid_id = 0 diff --git a/src/resources/filters/customnodes/shortcodes.lua b/src/resources/filters/customnodes/shortcodes.lua index ffb5cc1c7a..32ad1128e6 100644 --- a/src/resources/filters/customnodes/shortcodes.lua +++ b/src/resources/filters/customnodes/shortcodes.lua @@ -11,7 +11,7 @@ _quarto.ast.add_handler({ kind = "Inline", parse = function(span) - local inner_content = pandoc.List({}) + local inner_content = pandoc.Inlines({}) span.content = span.content:filter(function(el) return el.t == "Span" @@ -78,9 +78,9 @@ _quarto.ast.add_handler({ end local node = _quarto.ast.create_custom_node_scaffold("Shortcode", "Inline") - node.content = inner_content:map(function(el) - return pandoc.Span({el}) - end) + node.content = pandoc.Inlines(inner_content:map(function(el) + return pandoc.Span({el}) + end)) local tbl = { __quarto_custom_node = node, name = name, diff --git a/src/resources/filters/layout/html.lua b/src/resources/filters/layout/html.lua index dc38711021..317cd85565 100644 --- a/src/resources/filters/layout/html.lua +++ b/src/resources/filters/layout/html.lua @@ -190,7 +190,7 @@ function renderHtmlFigure(el, render) end) -- remove identifier (it is now on the div) - el.identifier = "" + el.attr.identifier = "" if not figureDiv.classes:find_if(function(str) return str:match("quarto%-figure%-.+") end) then -- apply standalone figure css if not already set diff --git a/src/resources/filters/quarto-post/foldcode.lua b/src/resources/filters/quarto-post/foldcode.lua index c5884a3da5..ab68552c29 100644 --- a/src/resources/filters/quarto-post/foldcode.lua +++ b/src/resources/filters/quarto-post/foldcode.lua @@ -65,7 +65,7 @@ function fold_code_and_lift_codeblocks() local prev_annotated_code_block_scaffold = nil local prev_annotated_code_block = nil -- ok to lift codeblocks - float.content = _quarto.ast.walk(float.content, { + float.content = _quarto.ast.walk(float.content or pandoc.Blocks{}, { traverse = "topdown", DecoratedCodeBlock = function(block) -- defer the folding of code blocks to the DecoratedCodeBlock renderer diff --git a/src/resources/filters/quarto-pre/code-annotation.lua b/src/resources/filters/quarto-pre/code-annotation.lua index 4fa26cf24a..077a10077e 100644 --- a/src/resources/filters/quarto-pre/code-annotation.lua +++ b/src/resources/filters/quarto-pre/code-annotation.lua @@ -310,7 +310,7 @@ function code_annotations() -- if code annotations is false, then shut it down if codeAnnotations ~= false then - local outputs = pandoc.List() + local outputs = pandoc.Blocks{} -- annotations[annotation-number] = {list of line numbers} local pendingAnnotations = nil diff --git a/src/resources/filters/quarto-pre/output-location.lua b/src/resources/filters/quarto-pre/output-location.lua index eebe8bc212..c50d388248 100644 --- a/src/resources/filters/quarto-pre/output-location.lua +++ b/src/resources/filters/quarto-pre/output-location.lua @@ -71,7 +71,7 @@ function output_location() if _quarto.format.isRevealJsOutput() then return { Blocks = function(blocks) - local newBlocks = pandoc.List() + local newBlocks = pandoc.Blocks{} for _,block in pairs(blocks) do local outputLoc = collectCellOutputLocation(block) if outputLoc then diff --git a/src/resources/filters/quarto-pre/parsefiguredivs.lua b/src/resources/filters/quarto-pre/parsefiguredivs.lua index e0e3318c42..868643cd30 100644 --- a/src/resources/filters/quarto-pre/parsefiguredivs.lua +++ b/src/resources/filters/quarto-pre/parsefiguredivs.lua @@ -458,7 +458,7 @@ function parse_floatreftargets() fig_attr.classes:insert(v) end end - image.caption = {} + image.caption = pandoc.Inlines{} return image end }) or fig.content[1] -- this shouldn't be needed but the lua analyzer doesn't know it @@ -602,7 +602,7 @@ function parse_floatreftargets() if img.identifier == "" then local caption = img.caption if #caption > 0 then - img.caption = nil + img.caption = pandoc.Inlines{} return pandoc.Figure(link, { long = { caption } }) else return nil @@ -819,4 +819,4 @@ function forward_cell_subcaps() return div end } -end \ No newline at end of file +end From 02980f3146f6fd59f0aa5fc417bc8be346ca2b4c Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 25 Nov 2024 10:11:38 +0100 Subject: [PATCH 14/17] Ensure proper types when setting custom node slots --- src/resources/filters/ast/customnodes.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/resources/filters/ast/customnodes.lua b/src/resources/filters/ast/customnodes.lua index 0b1c5d8550..ecda0ccb24 100644 --- a/src/resources/filters/ast/customnodes.lua +++ b/src/resources/filters/ast/customnodes.lua @@ -336,16 +336,21 @@ _quarto.ast = { return end local node = node_accessor(table) - local t = pandoc.utils.type(value) - quarto_assert(t ~= 'Div' and t ~= 'Span', "") + local valtype = pandoc.utils.type(value) + quarto_assert(valtype ~= 'Div' and valtype ~= 'Span', "") if index > #node.content then _quarto.ast.grow_scaffold(node, index) end - local pt = pandoc.utils.type(value) - if pt == "Block" or pt == "Inline" then - node.content[index].content = {value} + local inner_node = node.content[index] + local innertype = pandoc.utils.type(inner_node) + if innertype == 'Block' then + inner_node.content = quarto.utils.as_blocks(value) + elseif innertype == 'Inline' then + inner_node.content = quarto.utils.as_inlines(value) else - node.content[index].content = value + warn(debug.traceback( + 'Cannot find the right content type for value ' .. valtype)) + inner_node.content = value end end } From 90fb5e6ee5b9fd8725f244d435a622e87ab45438 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 26 Nov 2024 11:10:01 +0100 Subject: [PATCH 15/17] Use global function to check if caption if empty --- src/resources/filters/layout/typst.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/filters/layout/typst.lua b/src/resources/filters/layout/typst.lua index 4c875f9b4f..83fdcc3e2b 100644 --- a/src/resources/filters/layout/typst.lua +++ b/src/resources/filters/layout/typst.lua @@ -11,7 +11,7 @@ function make_typst_figure(tbl) local identifier = tbl.identifier local separator = tbl.separator - if (not caption or #caption.content == 0) and tbl.separator == nil then + if quarto.utils.is_empty_node(caption) and tbl.separator == nil then separator = "" end From 557b5f37d8b6f0aaedacf3d3bf2b3dd6accc0bf3 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 26 Nov 2024 14:56:27 +0100 Subject: [PATCH 16/17] Avoid type confusion with captions during crossref handling --- src/resources/filters/crossref/index.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resources/filters/crossref/index.lua b/src/resources/filters/crossref/index.lua index 16ad656d1c..68daa1ede3 100644 --- a/src/resources/filters/crossref/index.lua +++ b/src/resources/filters/crossref/index.lua @@ -65,9 +65,9 @@ end -- add an entry to the index function indexAddEntry(label, parent, order, caption, appendix) if caption ~= nil then - caption = pandoc.List(caption) + caption = quarto.utils.as_blocks(caption) else - caption = pandoc.List({}) + caption = pandoc.Blocks({}) end crossref.index.entries[label] = { parent = parent, From 3a0dc9ea6ef904277364aae7844a75384bd380c1 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 26 Nov 2024 21:03:34 +0100 Subject: [PATCH 17/17] Ensure Blocks in documents when normalizing draft posts The `blocks` property of a Pandoc object should always contain an object of type `Blocks`. --- src/resources/filters/normalize/draft.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/resources/filters/normalize/draft.lua b/src/resources/filters/normalize/draft.lua index 7b9c718a18..d3f043e643 100644 --- a/src/resources/filters/normalize/draft.lua +++ b/src/resources/filters/normalize/draft.lua @@ -23,17 +23,17 @@ function normalize_draft() end is_draft = meta[kDraft] == true or tcontains(drafts, quarto.doc.input_file); end, - Pandoc = function(pandoc) + Pandoc = function(doc) if _quarto.format.isHtmlOutput() and not _quarto.format.isHtmlSlideOutput() then if is_draft and draft_mode == kDraftModeGone then - pandoc.blocks = {} + doc.blocks = pandoc.Blocks{} quarto.doc.includeText("in-header", '') - return pandoc + return doc elseif is_draft and draft_mode ~= kDraftModeGone then quarto.doc.includeText("in-header", '') - return pandoc + return doc end end end } -end \ No newline at end of file +end