diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index db80e74d465..8c821133173 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -14,6 +14,7 @@ All changes included in 1.6: - ([#10168](https://github.com/quarto-dev/quarto-cli/issues/10168)): support `csl` bibliography style. - ([#10181](https://github.com/quarto-dev/quarto-cli/issues/10181)): Remove workaround for image dimensions which is no longer necessary and mishandled image paths with spaces. +- ([#10217](https://github.com/quarto-dev/quarto-cli/issues/10217)): Explicitly compute units for image dimensions in `typst` format when they're not given. ## Other Fixes and Improvements diff --git a/src/resources/filters/quarto-post/typst.lua b/src/resources/filters/quarto-post/typst.lua index 98a047592cf..57c79273653 100644 --- a/src/resources/filters/quarto-post/typst.lua +++ b/src/resources/filters/quarto-post/typst.lua @@ -96,6 +96,16 @@ function render_typst_fixups() traverse = "topdown", Image = function(image) image = _quarto.modules.mediabag.resolve_image_from_url(image) or image + -- REMINDME 2024-09-01 + -- work around until https://github.com/jgm/pandoc/issues/9945 is fixed + local height_as_number = tonumber(image.attributes["height"]) + local width_as_number = tonumber(image.attributes["width"]) + if image.attributes["height"] ~= nil and type(height_as_number) == "number" then + image.attributes["height"] = tostring(image.attributes["height"] / PANDOC_WRITER_OPTIONS.dpi) .. "in" + end + if image.attributes["width"] ~= nil and type(width_as_number) == "number" then + image.attributes["width"] = tostring(image.attributes["width"] / PANDOC_WRITER_OPTIONS.dpi) .. "in" + end return image end, Div = function(div) diff --git a/tests/docs/smoke-all/2024/07/03/10217.qmd b/tests/docs/smoke-all/2024/07/03/10217.qmd new file mode 100644 index 00000000000..573ed7a5271 --- /dev/null +++ b/tests/docs/smoke-all/2024/07/03/10217.qmd @@ -0,0 +1,24 @@ +--- +format: typst +--- + + +::: {.cell execution_count=1} +``` {.python .cell-code} +from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap +from plotnine.data import mtcars + +( + ggplot(mtcars, aes("wt", "mpg", color="factor(gear)")) + + geom_point() + + stat_smooth(method="lm") + + facet_wrap("gear") +) +``` + +::: {.cell-output .cell-output-display} +![](10217_files/figure-typst/cell-2-output-1.png){width=640 height=480} +::: +::: + + diff --git a/tests/docs/smoke-all/2024/07/03/10217_files/figure-typst/cell-2-output-1.png b/tests/docs/smoke-all/2024/07/03/10217_files/figure-typst/cell-2-output-1.png new file mode 100644 index 00000000000..7ff2e399d97 Binary files /dev/null and b/tests/docs/smoke-all/2024/07/03/10217_files/figure-typst/cell-2-output-1.png differ