Skip to content

Commit 5eba3a1

Browse files
authored
Merge pull request #13112 from quarto-dev/feature/lua-format-id
Lua - new API quarto.format.format_identifier()
2 parents bff4e40 + 79588b7 commit 5eba3a1

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

news/changelog-1.8.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ All changes included in 1.8:
8181
- ([#12727](https://github.com/quarto-dev/quarto-cli/issues/12727)): Do not crash in the presence of malformed tabset contents.
8282
- ([#12806](https://github.com/quarto-dev/quarto-cli/pull/12806)): Use pandoc APIs to handle codepage conversion on Windows.
8383
- ([#12811](https://github.com/quarto-dev/quarto-cli/pull/12811)): Add support for YouTube Shorts in `video` shortcode.
84-
- ([#13128](https://github.com/quarto-dev/quarto-cli/issues/13128)): Meta shortcode could crash on bad input.
84+
- ([#13112](https://github.com/quarto-dev/quarto-cli/pull/13112)): Add `quarto.format.format_identifier()` API entry.
85+
- ([#13128](https://github.com/quarto-dev/quarto-cli/issues/13128)): Avoid meta shortcode crash on bad input.
8586
- ([#13246](https://github.com/quarto-dev/quarto-cli/pull/13246)): Add `quarto.variables.get()` and `quarto.metadata.get()` APIs.
8687

8788
## Commands

src/resources/lua-types/quarto/format.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,13 @@ Returns an object with the format name and variants as would be interpreted by P
239239
]]
240240
---@param raw_format string The format's string
241241
---@return quarto.format.ParseFormatResult
242-
function quarto.format.parse_format(raw_format) end
242+
function quarto.format.parse_format(raw_format) end
243+
244+
--[[
245+
Returns a table with the format identifier information, including:
246+
- `target-format`: The full target format name, e.g. `html+variant`
247+
- `base-format`: The base format name, e.g. `html`
248+
- `display-name`: A human-readable display name for the format, e.g. `HTML`
249+
- `extension`: The name of the extension that exposes the format, if present
250+
]]
251+
function quarto.format.format_identifier() end

src/resources/pandoc/datadir/_format.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ local function _main()
288288
end
289289

290290
return {
291+
format_identifier = function()
292+
return param("format-identifier", {})
293+
end,
291294
isAsciiDocOutput = isAsciiDocOutput,
292295
is_asciidoc_output = isAsciiDocOutput,
293296
isRawHtml = isRawHtml,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function Pandoc(doc)
2+
local identifier = quarto.format.format_identifier()
3+
assert(identifier["target-format"] == "html+test")
4+
assert(identifier["base-format"] == "html")
5+
assert(identifier["display-name"] == "HTML")
6+
return doc
7+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
format: html+test
3+
filters:
4+
- format-identifier.lua
5+
---
6+

0 commit comments

Comments
 (0)