From b4e0c10257508b92169c1994faf29a0709dac9cc Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Mon, 21 Jul 2025 19:20:48 -0400 Subject: [PATCH 1/2] Lua - new API quarto.format .format_identifier() --- src/resources/lua-types/quarto/format.lua | 11 ++++++++++- src/resources/pandoc/datadir/_format.lua | 3 +++ tests/docs/smoke-all/lua/format/format-identifier.lua | 7 +++++++ tests/docs/smoke-all/lua/format/format-identifier.qmd | 6 ++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/docs/smoke-all/lua/format/format-identifier.lua create mode 100644 tests/docs/smoke-all/lua/format/format-identifier.qmd diff --git a/src/resources/lua-types/quarto/format.lua b/src/resources/lua-types/quarto/format.lua index 285ad070a84..70bd60ab225 100644 --- a/src/resources/lua-types/quarto/format.lua +++ b/src/resources/lua-types/quarto/format.lua @@ -239,4 +239,13 @@ Returns an object with the format name and variants as would be interpreted by P ]] ---@param raw_format string The format's string ---@return quarto.format.ParseFormatResult -function quarto.format.parse_format(raw_format) end \ No newline at end of file +function quarto.format.parse_format(raw_format) end + +--[[ +Returns a table with the format identifier information, including: +- `target-format`: The full target format name, e.g. `html+variant` +- `base-format`: The base format name, e.g. `html` +- `display-name`: A human-readable display name for the format, e.g. `HTML` +- `extension`: The name of the extension that exposes the format, if present +]] +function quarto.format.format_identifier() end \ No newline at end of file diff --git a/src/resources/pandoc/datadir/_format.lua b/src/resources/pandoc/datadir/_format.lua index 4dbf44ecff8..64fe30c5875 100644 --- a/src/resources/pandoc/datadir/_format.lua +++ b/src/resources/pandoc/datadir/_format.lua @@ -288,6 +288,9 @@ local function _main() end return { + format_identifier = function() + return param("format-identifier", {}) + end, isAsciiDocOutput = isAsciiDocOutput, is_asciidoc_output = isAsciiDocOutput, isRawHtml = isRawHtml, diff --git a/tests/docs/smoke-all/lua/format/format-identifier.lua b/tests/docs/smoke-all/lua/format/format-identifier.lua new file mode 100644 index 00000000000..540769cd98f --- /dev/null +++ b/tests/docs/smoke-all/lua/format/format-identifier.lua @@ -0,0 +1,7 @@ +function Pandoc(doc) + local identifier = quarto.format.format_identifier() + assert(identifier["target-format"] == "html+test") + assert(identifier["base-format"] == "html") + assert(identifier["display-name"] == "HTML") + return doc +end \ No newline at end of file diff --git a/tests/docs/smoke-all/lua/format/format-identifier.qmd b/tests/docs/smoke-all/lua/format/format-identifier.qmd new file mode 100644 index 00000000000..45616c60a19 --- /dev/null +++ b/tests/docs/smoke-all/lua/format/format-identifier.qmd @@ -0,0 +1,6 @@ +--- +format: html+test +filters: + - format-identifier.lua +--- + From fea10eff3ea9d40ebfce2fb5149e9e67d31ad0d0 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Mon, 21 Jul 2025 19:22:57 -0400 Subject: [PATCH 2/2] changelog --- news/changelog-1.8.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.8.md b/news/changelog-1.8.md index 0a81500ecab..5b3660a9828 100644 --- a/news/changelog-1.8.md +++ b/news/changelog-1.8.md @@ -73,6 +73,7 @@ All changes included in 1.8: - ([#12727](https://github.com/quarto-dev/quarto-cli/issues/12727)): Do not crash in the presence of malformed tabset contents. - ([#12806](https://github.com/quarto-dev/quarto-cli/pull/12806)): Use pandoc APIs to handle codepage conversion on Windows. - ([#12811](https://github.com/quarto-dev/quarto-cli/pull/12811)): Add support for YouTube Shorts in `video` shortcode. +- ([#13112](https://github.com/quarto-dev/quarto-cli/pull/13112)): Add `quarto.format.format_identifier()` API entry. ## Commands