Skip to content

Commit f7b65ec

Browse files
authored
Merge pull request #12752 from quarto-dev/fix/typst-css-font-weight
typst-css - correctly handle unsupported font-weight values
2 parents b13c19b + df09322 commit f7b65ec

File tree

4 files changed

+1150
-985
lines changed

4 files changed

+1150
-985
lines changed

src/resources/filters/quarto-post/typst-css-property-processing.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ function render_typst_css_property_processing()
171171
elseif k == 'font-size' then
172172
cell.attributes['typst:text:size'] = _quarto.format.typst.css.translate_length(v, _warnings)
173173
elseif k == 'font-weight' then
174-
cell.attributes['typst:text:weight'] = _quarto.format.typst.css.quote(_quarto.format.typst.css.translate_font_weight(v, _warnings))
174+
local translated_fw = _quarto.format.typst.css.translate_font_weight(v, _warnings)
175+
-- unsupported font-weight values will be returned as nil
176+
if translated_fw then
177+
cell.attributes['typst:text:weight'] = _quarto.format.typst.css.quote(translated_fw)
178+
end
175179
elseif k == 'font-style' then
176180
cell.attributes['typst:text:style'] = _quarto.format.typst.css.quote(v)
177181
elseif k == 'vertical-align' then
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "Great Tables - Oceania"
3+
format: typst
4+
_quarto:
5+
tests:
6+
typst:
7+
printsMessage:
8+
level: INFO
9+
regex: 'invalid font weight initial'
10+
---
11+
12+
```{=typst}
13+
#set page(numbering: none)
14+
```
15+
16+
```{python}
17+
#| classes: plain
18+
from great_tables import GT
19+
from great_tables.data import countrypops
20+
import polars as pl
21+
import polars.selectors as cs
22+
23+
# Get vectors of 2-letter country codes for each region of Oceania
24+
oceania = {
25+
"Australasia": ["AU", "NZ"],
26+
"Melanesia": ["NC", "PG", "SB", "VU"],
27+
"Micronesia": ["FM", "GU", "KI", "MH", "MP", "NR", "PW"],
28+
"Polynesia": ["PF", "WS", "TO", "TV"],
29+
}
30+
31+
# Create a dictionary mapping country to region (e.g. AU -> Australasia)
32+
country_to_region = {
33+
country: region for region, countries in oceania.items() for country in countries
34+
}
35+
36+
wide_pops = (
37+
pl.from_pandas(countrypops)
38+
.filter(
39+
pl.col("country_code_2").is_in(list(country_to_region))
40+
& pl.col("year").is_in([2000, 2010, 2020])
41+
)
42+
.with_columns(pl.col("country_code_2").replace(country_to_region).alias("region"))
43+
.pivot(index=["country_name", "region"], columns="year", values="population")
44+
.sort("2020", descending=True)
45+
)
46+
47+
(
48+
GT(wide_pops, rowname_col="country_name", groupname_col="region")
49+
.tab_header(title="Populations of Oceania's Countries in 2000, 2010, and 2020")
50+
.tab_spanner(label="Total Population", columns=cs.all())
51+
.fmt_integer()
52+
)
53+
```

tests/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ dependencies = [
1515
"papermill>=2.6.0",
1616
"seaborn>=0.13.2",
1717
"shiny>=1.2.0",
18+
"great-tables>=0.17.0",
19+
"polars>=1.29.0",
20+
"pyarrow>=20.0.0",
1821
]

0 commit comments

Comments
 (0)