From da14cc03ce19bd08c7679c5e1029287c78c9cd1d Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 25 Jul 2024 10:39:47 -0400 Subject: [PATCH] fix: meta["partial-data"] might be empty --- README.md | 6 +++--- _extensions/partials/quarto-partials.lua | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a4631b1..7cc54dd 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,9 @@ partial-data: > Or used inline: To you I say "{{< partial _hello.md >}}" > ``` > -> Hello, friend! +> Hello, ! > -> Or used inline: To you I say “Hello, friend!” +> Or used inline: To you I say “Hello, !” Alternatively, the second argument of the shortcode can point to a custom key in your YAML frontmatter, e.g. @@ -74,7 +74,7 @@ my-data: > {{< partial _hello.md my-data.friends >}} > ``` > -> Hello, amigo! +> Hello, ! Another, possibly less convenient, option is to provide JSON in the shortcode data. Any key-value pair that starts with `{` or `[` will be diff --git a/_extensions/partials/quarto-partials.lua b/_extensions/partials/quarto-partials.lua index 141bdbe..5786746 100644 --- a/_extensions/partials/quarto-partials.lua +++ b/_extensions/partials/quarto-partials.lua @@ -123,18 +123,20 @@ local function quarto_partial(args, kwargs, meta, raw_args, context) assert(false, msg) end end - else + elseif meta[partial_key] then partial_data = copy(meta[partial_key]) end - local data_str = pandoc_stringify(partial_data) + if #partial_data > 0 then + local data_str = pandoc_stringify(partial_data) - if type(data_str) == "string" then - quarto.log.error("Please choose a metadata key from your YAML frontmatter that contains a table of partial data.") - assert(false, "Expected a table of partial data in YAML frontmatter key " .. partial_key) - end + if type(data_str) == "string" then + quarto.log.error("Please choose a metadata key from your YAML frontmatter that contains a table of partial data.") + assert(false, "Expected a table of partial data in YAML frontmatter key " .. partial_key) + end - data = data_str + data = data_str + end for k, v in pairs(kwargs) do local v_is_json_string = false