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
2 changes: 2 additions & 0 deletions src/resources/filters/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import("./quarto-post/fig-cleanup.lua")
import("./quarto-post/foldcode.lua")
import("./quarto-post/ipynb.lua")
import("./quarto-post/latex.lua")
import("./quarto-post/typst.lua")
import("./quarto-post/latexdiv.lua")
import("./quarto-post/meta.lua")
import("./quarto-post/ojs.lua")
Expand Down Expand Up @@ -328,6 +329,7 @@ local quarto_post_filters = {
{ name = "post-render-asciidoc", filter = render_asciidoc() },
{ name = "post-render-latex", filter = render_latex() },
{ name = "post-render-docx", filter = render_docx() },
{ name = "post-render-typst", filter = render_typst() },

-- extensible rendering
{ name = "post-render_extended_nodes", filter = render_extended_nodes() },
Expand Down
35 changes: 35 additions & 0 deletions src/resources/filters/quarto-post/typst.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- latex.lua
-- Copyright (C) 2023 Posit Software, PBC
--
-- renders AST nodes to Typst


function render_typst()
if not _quarto.format.isTypstOutput() then
return {}
end

return {
Div = function(div)
if div.classes:includes("block") then
div.classes = div.classes:filter(function(c) return c ~= "block" end)

local preamble = pandoc.Blocks({})
local postamble = pandoc.Blocks({})
preamble:insert(pandoc.RawBlock("typst", "#block("))
for k, v in pairs(div.attributes) do
-- FIXME: proper escaping of k and v
preamble:insert(pandoc.RawBlock("typst", k .. ":" .. v .. ",\n"))
end
preamble:insert(pandoc.RawBlock("typst", "[\n"))
postamble:insert(pandoc.RawBlock("typst", "])\n\n"))

local result = pandoc.Blocks({})
result:extend(preamble)
result:extend(div.content)
result:extend(postamble)
return result
end
end
}
end
10 changes: 10 additions & 0 deletions tests/docs/smoke-all/typst/block-divs.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "typst blocks"
format: typst
---

::: {.block fill="rgb(\"ff0000\")"}

This is a block with red background (yuck.)

:::