Skip to content

Commit 99dbea0

Browse files
guard long data uris so that juice doesn't truncate them
fixes #11829
1 parent a1badd7 commit 99dbea0

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/resources/filters/normalize/parsehtml.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,21 @@ end
4545

4646
function parse_html_tables()
4747
local function juice(htmltext)
48+
-- return htmltext
4849
return pandoc.system.with_temporary_directory('juice', function(tmpdir)
50+
-- replace any long data uris with uuids
51+
local data_uri_uuid = '273dae7e-3633-4385-9b0c-203d2d7a2d37'
52+
local data_uris = {}
53+
local data_uri_regex = 'data:image/[a-z]+;base64,[a-zA-Z0-9+/]+=*'
54+
htmltext = htmltext:gsub(data_uri_regex, function(data_uri)
55+
-- juice truncates around 15k characters; let's guard any over 2000 characters
56+
if #data_uri > 2000 then
57+
table.insert(data_uris, data_uri)
58+
return data_uri_uuid
59+
else
60+
return data_uri
61+
end
62+
end)
4963
local juice_in = pandoc.path.join({tmpdir, 'juice-in.html'})
5064
local jin = assert(io.open(juice_in, 'w'))
5165
jin:write(htmltext)
@@ -65,6 +79,12 @@ function parse_html_tables()
6579
quarto.log.error("Running juice failed with exit code: " .. (exitCode or "unknown exit code"))
6680
return htmltext
6781
else
82+
local index = 1
83+
content = content:gsub(data_uri_uuid:gsub('-', '--'), function(_)
84+
local data_uri = data_uris[index]
85+
index = index + 1
86+
return data_uri
87+
end)
6888
return content
6989
end
7090
end)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
format:
3+
typst:
4+
keep-typ: true
5+
keep-md: true
6+
7+
---
8+
9+
```{=typst}
10+
#show figure: set block(breakable: true)
11+
```
12+
13+
```{r, echo=FALSE, warning=FALSE, message=FALSE}
14+
plot_timeline <- function(T){
15+
tibble(x = seq(1,5), y = x^2) |>
16+
ggplot(aes(
17+
x = x,
18+
y = y
19+
)) +
20+
geom_line()
21+
}
22+
```
23+
24+
```{r, echo=FALSE, warning=FALSE, message=FALSE}
25+
#| label: tbl-example
26+
#| tbl-cap: This is an example table
27+
28+
library(gt)
29+
library(tidyverse)
30+
31+
tibble(Things= seq(1,5)) |>
32+
mutate(trans = Things) |>
33+
gt() |>
34+
text_transform(
35+
locations = cells_body(columns="trans"),
36+
fn = function(col){
37+
local_image(test_image("png"))
38+
}
39+
)
40+
```

tests/docs/smoke-all/typst/juice/test.qmd

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)