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
20 changes: 20 additions & 0 deletions src/resources/filters/normalize/parsehtml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ end

function parse_html_tables()
local function juice(htmltext)
-- return htmltext
return pandoc.system.with_temporary_directory('juice', function(tmpdir)
-- replace any long data uris with uuids
local data_uri_uuid = '273dae7e-3633-4385-9b0c-203d2d7a2d37'
local data_uris = {}
local data_uri_regex = 'data:image/[a-z]+;base64,[a-zA-Z0-9+/]+=*'
htmltext = htmltext:gsub(data_uri_regex, function(data_uri)
-- juice truncates around 15k characters; let's guard any over 2000 characters
if #data_uri > 2000 then
table.insert(data_uris, data_uri)
return data_uri_uuid
else
return data_uri
end
end)
local juice_in = pandoc.path.join({tmpdir, 'juice-in.html'})
local jin = assert(io.open(juice_in, 'w'))
jin:write(htmltext)
Expand All @@ -65,6 +79,12 @@ function parse_html_tables()
quarto.log.error("Running juice failed with exit code: " .. (exitCode or "unknown exit code"))
return htmltext
else
local index = 1
content = content:gsub(data_uri_uuid:gsub('-', '--'), function(_)
local data_uri = data_uris[index]
index = index + 1
return data_uri
end)
return content
end
end)
Expand Down
40 changes: 40 additions & 0 deletions tests/docs/smoke-all/typst/juice/gt-table-images.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
format:
typst:
keep-typ: true
keep-md: true

---

```{=typst}
#show figure: set block(breakable: true)
```

```{r, echo=FALSE, warning=FALSE, message=FALSE}
plot_timeline <- function(T){
tibble(x = seq(1,5), y = x^2) |>
ggplot(aes(
x = x,
y = y
)) +
geom_line()
}
```

```{r, echo=FALSE, warning=FALSE, message=FALSE}
#| label: tbl-example
#| tbl-cap: This is an example table

library(gt)
library(tidyverse)

tibble(Things= seq(1,5)) |>
mutate(trans = Things) |>
gt() |>
text_transform(
locations = cells_body(columns="trans"),
fn = function(col){
local_image(test_image("png"))
}
)
```
15 changes: 15 additions & 0 deletions tests/docs/smoke-all/typst/juice/test.qmd

Large diffs are not rendered by default.

Loading