Skip to content

Lua - new API quarto.format.format_identifier() #13112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/resources/lua-types/quarto/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
3 changes: 3 additions & 0 deletions src/resources/pandoc/datadir/_format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions tests/docs/smoke-all/lua/format/format-identifier.lua
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/docs/smoke-all/lua/format/format-identifier.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
format: html+test
filters:
- format-identifier.lua
---

Loading