Skip to content
Merged
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
3 changes: 2 additions & 1 deletion news/changelog-1.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ All changes included in 1.8:

- ([#12615](https://github.com/quarto-dev/quarto-cli/pull/12615)): Adds `algorithm` to theorem environments. (author: @jeremy9959)

## Lua Filters
## Lua Filters and API

- ([#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.
- ([#13128](https://github.com/quarto-dev/quarto-cli/issues/13128)): Meta shortcode could crash on bad input.
- ([#13246](https://github.com/quarto-dev/quarto-cli/pull/13246)): Add `quarto.variables.get()` and `quarto.metadata.get()` APIs.

## Commands

Expand Down
13 changes: 13 additions & 0 deletions src/resources/lua-types/quarto/metadata.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---@meta

quarto.metadata = {}

--[[
Return the value of a metadata entry in Quarto metadata as a pandoc.MetaValue.
Return nil if the key (or any of its subcomponents) are missing.

This is the Lua equivalent of the {{< meta key >}} shortcode in Quarto documents.
]]
---@param key string metadata key, possibly with nested keys separated by dots
---@return pandoc.MetaValue | nil
function quarto.metadata.get(key) end
12 changes: 12 additions & 0 deletions src/resources/lua-types/quarto/variables.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---@meta

quarto.variables = {}

--[[
Return the value of a variable in _variables.yml as a string, or nil if name is missing.

This is the Lua equivalent of the {{< var name >}} shortcode in Quarto documents.
]]
---@param name string name of variable
---@return string | nil
function quarto.variables.get(name) end
14 changes: 14 additions & 0 deletions src/resources/pandoc/datadir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,20 @@ quarto = {
end
end,
},
metadata = {
get = function(key)
return option(key, nil)
end
},
variables = {
get = function(name)
local value = var(name, nil)
if value then
value = pandoc.utils.stringify(value)
end
return value
end
}
}

-- alias old names for backwards compatibility
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.quarto/

/.luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
meta_from_metadata: value_from_metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project:
type: website

website:
title: "test-lua-shortcode-apis"
navbar:
left:
- href: index.qmd
text: Home
- about.qmd

format:
html:
theme:
- cosmo
- brand
css: styles.css
toc: true



Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var1: var_value
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "About"
---

About this site
26 changes: 26 additions & 0 deletions tests/docs/smoke-all/2025/08/19/test-lua-shortcode-apis/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: "test-lua-shortcode-apis"
meta1: meta_value
meta2: 2
meta3:
- foo
- bar
meta4:
key1: value1
key2: value2
filters:
- set_span_values.lua
_quarto:
tests:
html:
ensureFileRegexMatches:
-
- meta_value
- var_value
---

This is a Quarto website.

To learn more about Quarto websites visit <https://quarto.org/docs/websites>.

[]{#span1}, []{#span2}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function Span(span)
-- print(quarto.variables.get("var1"))
-- print(quarto.metadata.get("meta1"))
if span.identifier == "span1" then
span.content = quarto.utils.string_to_inlines(
pandoc.utils.stringify(quarto.variables.get("var1")))
return span
elseif span.identifier == "span2" then
span.content = quarto.utils.string_to_inlines(
pandoc.utils.stringify(quarto.metadata.get("meta1")))
return span
end
end

function Pandoc(doc)
local function get_meta(key)
return pandoc.utils.stringify(quarto.metadata.get(key))
end
assert(type(quarto.metadata.get("meta3")) == "table")
assert(get_meta("meta2") == "2")
assert(get_meta("meta4.key1") == "value1")
assert(get_meta("meta4.key2") == "value2")
assert(get_meta("meta_from_metadata") == "value_from_metadata")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* css styles */
Loading