Skip to content

Commit ea41b6d

Browse files
expose _quarto.modules.typst.css.expand_side_shorthand
1 parent 48109de commit ea41b6d

File tree

3 files changed

+72
-27
lines changed

3 files changed

+72
-27
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
format:
3+
html:
4+
quality: -1
5+
pdf:
6+
quality: na
7+
typst:
8+
quality: -1
9+
comment: "invalid"
10+
dashboard:
11+
quality: -1
12+
docx:
13+
quality: na
14+
pptx:
15+
quality: na
16+
keep-typ: true
17+
_quarto:
18+
tests:
19+
typst:
20+
ensureTypstFileRegexMatches:
21+
-
22+
- ' \[A\], \[B\]'
23+
- []
24+
---
25+
26+
```{=html}
27+
<table>
28+
<tr><td style="border-width: 1pt 2pt 3pt 4pt 5pt">A</td><td>B</td></tr>
29+
</table>
30+
```
31+

src/resources/filters/modules/typst_css.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,36 @@ local function consume_color(s, start, warnings)
648648
return paint, fend + 1
649649
end
650650

651+
-- the most css thing ever
652+
local function expand_side_shorthand(items, context, warnings)
653+
local sides = {}
654+
if #items == 0 then
655+
output_warning(warnings, 'no valid ' .. context)
656+
elseif #items == 1 then
657+
sides.top = items[1]
658+
sides.right = items[1]
659+
sides.bottom = items[1]
660+
sides.left = items[1]
661+
elseif #items == 2 then
662+
sides.top = items[1]
663+
sides.right = items[2]
664+
sides.bottom = items[1]
665+
sides.left = items[2]
666+
elseif #items == 3 then
667+
sides.top = items[1]
668+
sides.right = items[2]
669+
sides.bottom = items[3]
670+
sides.left = items[2]
671+
elseif #items == 4 then
672+
sides.top = items[1]
673+
sides.right = items[2]
674+
sides.bottom = items[3]
675+
sides.left = items[4]
676+
else
677+
output_warning(warnings, 'too many ' .. context)
678+
end
679+
return sides
680+
end
651681

652682
return {
653683
parse_color = parse_color,
@@ -658,6 +688,7 @@ return {
658688
output_length = output_length,
659689
translate_length = translate_length,
660690
parse_multiple = parse_multiple,
691+
expand_side_shorthand = expand_side_shorthand,
661692
translate_border = translate_border,
662693
translate_border_width = translate_border_width,
663694
translate_border_style = translate_border_style,

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

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ function render_typst_css_property_processing()
151151
end
152152
elseif tcontains(border_properties, part) then
153153
local items = {}
154-
_quarto.modules.typst.css.parse_multiple(v, 4, function(s, start)
154+
-- one extra only so we can error on it
155+
_quarto.modules.typst.css.parse_multiple(v, 5, function(s, start)
155156
local item, newstart = border_consumers[part](s, start)
156157
table.insert(items, item)
157158
return newstart
@@ -160,32 +161,14 @@ function render_typst_css_property_processing()
160161
borders[side] = borders[side] or {}
161162
end
162163
local xlate = border_translators[part]
163-
if #items == 0 then
164-
_warnings:insert('no valid ' .. part .. 's in ' .. v)
165-
-- the most css thing ever
166-
elseif #items == 1 then
167-
borders.top[xlate.prop] = items[1]
168-
borders.right[xlate.prop] = items[1]
169-
borders.bottom[xlate.prop] = items[1]
170-
borders.left[xlate.prop] = items[1]
171-
elseif #items == 2 then
172-
borders.top[xlate.prop] = items[1]
173-
borders.right[xlate.prop] = items[2]
174-
borders.bottom[xlate.prop] = items[1]
175-
borders.left[xlate.prop] = items[2]
176-
elseif #items == 3 then
177-
borders.top[xlate.prop] = items[1]
178-
borders.right[xlate.prop] = items[2]
179-
borders.bottom[xlate.prop] = items[3]
180-
borders.left[xlate.prop] = items[2]
181-
elseif #items == 4 then
182-
borders.top[xlate.prop] = items[1]
183-
borders.right[xlate.prop] = items[2]
184-
borders.bottom[xlate.prop] = items[3]
185-
borders.left[xlate.prop] = items[4]
186-
else
187-
_warnings:insert('too many values in ' .. k .. ' list: ' .. v)
188-
end
164+
local sides = _quarto.modules.typst.css.expand_side_shorthand(
165+
items,
166+
part .. 's in ' .. k .. ' list: ' .. v,
167+
_warnings)
168+
borders.top[xlate.prop] = sides.top
169+
borders.right[xlate.prop] = sides.right
170+
borders.bottom[xlate.prop] = sides.bottom
171+
borders.left[xlate.prop] = sides.left
189172
else
190173
_warnings:insert('invalid 2-item border key ' .. k)
191174
end

0 commit comments

Comments
 (0)