Skip to content

Commit

Permalink
Issue #370 typst alignment and simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 14, 2024
1 parent 724740f commit 4f2e5a7
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 313 deletions.
1 change: 0 additions & 1 deletion R/style_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ setMethod(

for (s in styles) {
x@table_string <- lines_insert(x@table_string, s, "tinytable cell style after", "after")
# x@table_string <- lines_insert(x@table_string, s, "tinytable cell align after", "after")
}

lin <- sty[grepl("b|t", sty$line),, drop = FALSE]
Expand Down
24 changes: 8 additions & 16 deletions inst/templates/typst.typ
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,19 @@ block[ // start block
#table( // tinytable table start
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
// tinytable lines before
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/group_tt-3level.typ
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,19 @@ block[ // start block
columns: (auto, auto, auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 4, start: 0, end: 5, stroke: 0.05em + black),
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/group_tt-issue258_01_typst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,19 @@ block[ // start block
columns: (auto, auto, auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 1, start: 0, end: 5, stroke: 0.05em + black),
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/group_tt-issue258_02_typst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,19 @@ block[ // start block
columns: (auto, auto, auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 1, start: 0, end: 5, stroke: 0.05em + black),
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/tibble-typst_pillar_num.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,19 @@ block[ // start block
columns: (auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 1, start: 0, end: 3, stroke: 0.05em + black),
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/typst-complicated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,19 @@ block[ // start block
columns: (auto, auto, auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 2, start: 0, end: 5, stroke: 0.05em + black),
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/typst-font_size.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,19 @@ block[ // start block
columns: (auto, auto, auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 1, start: 0, end: 5, stroke: 0.05em + black),
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/typst-formatting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,19 @@ block[ // start block
columns: (auto, auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 1, start: 0, end: 4, stroke: 0.05em + black),
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/typst-grid.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,19 @@ block[ // start block
columns: (auto, auto, auto, auto, auto),
stroke: (paint: black),
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
// tinytable lines before
Expand Down
24 changes: 8 additions & 16 deletions inst/tinytest/_tinysnapshot/typst-group_rows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,19 @@ block[ // start block
columns: (auto, auto, auto, auto, auto, auto, auto, auto),
stroke: none,
align: (x, y) => {
let align-array = (
// tinytable cell align after
)
if align-array.len() == 0 {
left
let sarray = style-array.filter(a => "align" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().align
} else {
left
// for style in style-array {
// let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
// if m != none and ("align" in style) {
// let a = style.align
// }
// }
}
},
fill: (x, y) => {
for style in style-array {
let m = style.pairs.find(k => k.at(0) == x and k.at(1) == y)
if m != none and ("background" in style) {
style.background
}
let sarray = style-array.filter(a => "background" in a)
let sarray = sarray.filter(a => a.pairs.find(p => p.at(0) == x and p.at(1) == y) != none)
if sarray.len() > 0 {
sarray.last().background
}
},
table.hline(y: 1, start: 0, end: 8, stroke: 0.05em + black),
Expand Down
Loading

0 comments on commit 4f2e5a7

Please sign in to comment.