From a54eaea7e32ef64bd30e74d39621609c7448c109 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 22 Oct 2024 13:26:06 -0700 Subject: [PATCH] shortcodes - render passthrough shortcodes more accurately --- news/changelog-1.6.md | 4 ++++ .../filters/customnodes/shortcodes.lua | 18 +++++++++++++++++- .../2024/10/22/issue-10292.md.snapshot | 7 +++++++ .../docs/smoke-all/2024/10/22/issue-10292.qmd | 12 ++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/docs/smoke-all/2024/10/22/issue-10292.md.snapshot create mode 100644 tests/docs/smoke-all/2024/10/22/issue-10292.qmd diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index 1a4432acb9..ecea7b65c9 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -4,6 +4,10 @@ All changes included in 1.6: - The syntax for standard library imports in `quarto run` TypeScript files (`*.ts`) changed. Please see https://prerelease.quarto.org/docs/projects/scripts.html#deno-scripts for how to make the necessary changes. +## Shortcodes + +- ([#10292](https://github.com/quarto-dev/quarto-cli/issues/10292)): Improve shortcode passthrough when handlers are not available. + ## `quarto inspect` - ([#10039](https://github.com/quarto-dev/quarto-cli/issues/10039)): `quarto inspect` properly handles `!expr` tag in metadata. diff --git a/src/resources/filters/customnodes/shortcodes.lua b/src/resources/filters/customnodes/shortcodes.lua index 7d54e4cc92..ffb5cc1c7a 100644 --- a/src/resources/filters/customnodes/shortcodes.lua +++ b/src/resources/filters/customnodes/shortcodes.lua @@ -226,7 +226,23 @@ function shortcodes_filter() } local handler = handlerForShortcode(shortcode_struct) if handler == nil then - return open .. space .. name .. " " .. table.concat(raw_args, " ") .. " " .. close + local strs = {} + table.insert(strs, open) + table.insert(strs, space) + table.insert(strs, name) + for _, v in ipairs(lst) do + if type(v) == "string" then + table.insert(strs, v) + else + if v.name then + table.insert(strs, v.name .. "=" .. v.value) + else + table.insert(strs, v.value) + end + end + end + table.insert(strs, close) + return table.concat(strs, "") end local result = callShortcodeHandler(handler, shortcode_struct, "text") return pandoc.utils.stringify(result) diff --git a/tests/docs/smoke-all/2024/10/22/issue-10292.md.snapshot b/tests/docs/smoke-all/2024/10/22/issue-10292.md.snapshot new file mode 100644 index 0000000000..ac9520285c --- /dev/null +++ b/tests/docs/smoke-all/2024/10/22/issue-10292.md.snapshot @@ -0,0 +1,7 @@ +--- +title: Test +format: hugo-md +--- + + +{{< vimeo id="146022717" class="my-vimeo-wrapper-class" title="My vimeo video" >}} diff --git a/tests/docs/smoke-all/2024/10/22/issue-10292.qmd b/tests/docs/smoke-all/2024/10/22/issue-10292.qmd new file mode 100644 index 0000000000..c8ef834e63 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/22/issue-10292.qmd @@ -0,0 +1,12 @@ +--- +title: "Test" +format: hugo-md +_quarto: + tests: + hugo-md: + ensureSnapshotMatches: true +--- + +```{=markdown} +{{< vimeo id="146022717" class="my-vimeo-wrapper-class" title="My vimeo video" >}} +``` \ No newline at end of file