From 1fab557794737a4c88b0ea2ef32d078955122bc2 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 8 Nov 2023 07:40:34 -0700 Subject: [PATCH 1/3] avoid combineFilters type mismatch by early exiting --- src/resources/filters/common/pandoc.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/resources/filters/common/pandoc.lua b/src/resources/filters/common/pandoc.lua index a9a56ac109f..8193332c586 100644 --- a/src/resources/filters/common/pandoc.lua +++ b/src/resources/filters/common/pandoc.lua @@ -51,6 +51,14 @@ function combineFilters(filters) for _, fn in ipairs(fns) do local result = fn(current) if result ~= nil then + if (pandoc.utils.type(result) ~= pandoc.utils.type(current) or + result.t ~= current.t) then + -- luacov: disable + quarto.log.info("combineFilters: expected " .. (current.t or pandoc.utils.type(current)) .. " got " .. (result.t or pandoc.utils.type(result))) + quarto.log.info("Exiting filter early. (This is a potential bug in Quarto.)") + return result + -- luacov: enable + end -- if there is a result from this function -- update the current value with the result current = result From 8780493ad111a2f388b1d2e398a80fd1968d0a47 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 8 Nov 2023 07:41:19 -0700 Subject: [PATCH 2/3] scaffold in-filter markdown parsing to work well in combineFilters --- src/resources/filters/normalize/extractquartodom.lua | 10 +++++----- src/resources/filters/quarto-finalize/descaffold.lua | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/resources/filters/normalize/extractquartodom.lua b/src/resources/filters/normalize/extractquartodom.lua index 1aab3957cc4..f889719c00d 100644 --- a/src/resources/filters/normalize/extractquartodom.lua +++ b/src/resources/filters/normalize/extractquartodom.lua @@ -14,16 +14,16 @@ function parse_md_in_html_rawblocks() return { Div = function(div) if div.attributes.qmd ~= nil or div.attributes["qmd-base64"] ~= nil then - return process_quarto_markdown_input_element(div) + return make_scaffold(pandoc.Div, process_quarto_markdown_input_element(div)) end end, Span = function(span) if span.attributes.qmd ~= nil or span.attributes["qmd-base64"] ~= nil then - local blocks = process_quarto_markdown_input_element(span) - if #blocks < 1 then - return pandoc.Span({}) + local inlines = quarto.utils.as_inlines(process_quarto_markdown_input_element(span)) + if #inlines < 1 then + return make_scaffold(pandoc.Span, {}) end - return blocks[1].content + return make_scaffold(pandoc.Span, inlines) end end } diff --git a/src/resources/filters/quarto-finalize/descaffold.lua b/src/resources/filters/quarto-finalize/descaffold.lua index 9fab5df4763..50d8afb104e 100644 --- a/src/resources/filters/quarto-finalize/descaffold.lua +++ b/src/resources/filters/quarto-finalize/descaffold.lua @@ -14,4 +14,8 @@ function descaffold() end end } -end \ No newline at end of file +end + +function make_scaffold(ctor, node) + return ctor(node or {}, pandoc.Attr("", {"quarto-scaffold", "hidden"}, {})) +end From 6470f9b43bda2ae0add9a3535476bc282cd46826 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 8 Nov 2023 07:41:53 -0700 Subject: [PATCH 3/3] use Blocks instead of List for better type information --- src/resources/filters/customnodes/callout.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/filters/customnodes/callout.lua b/src/resources/filters/customnodes/callout.lua index d87f338afc9..3317af29334 100644 --- a/src/resources/filters/customnodes/callout.lua +++ b/src/resources/filters/customnodes/callout.lua @@ -119,7 +119,7 @@ function docx_callout_and_table_fixup() Blocks = function(blocks) local lastWasCallout = false local lastWasTableOrFigure = false - local newBlocks = pandoc.List() + local newBlocks = pandoc.Blocks({}) for i,el in ipairs(blocks) do -- determine what this block is local isCallout = is_custom_node(el, "Callout")