Open LamprosPitsillos opened 6 months ago
tracking in #17
The initial idea is to match patterns like grid/table(columns: $n, $cells)
.
We may put n cells in a line if they can fit in a line. Otherwise we spread them into multiple lines.(This still doesn't sounds good. Do you have better ideas?
Maybe indent the leftover ones a bit?
line fits 3 cells*
table(columns : $n+3 , $cells...)
~~~~
foo bar baz
faz loo soo saz
xoo xaz raz
laz baz laz
Also maybe try to include *span
since it will break a lot of the logic otherwise
colspan, rowspan and cell will very likely to be not supported in the initial MVP. But i think it can be supported once we have a good framework to deal with normal tables
If there is any span element (e.g. rowspan
) or spreading arguments (e.g. ...row
), we may expand it (default formatting for function calls).
I paste three table formatting here that looks beautiful imo:
compacted:
#table(rows=3,
[1], [2], [3],
[1], [2], [3],
[1], [2], [3],
)
2 multiple line with parbreak separated:
#table(rows=3,
[1],
[2],
[3],
[1],
[2],
[3],
[1],
[2],
[3],
)
3 simulate the header's shape:
#table(rows=3,
[time], [event],
[notes],
[ 9:00], [washing], // just align with the header
[and other things],
[12:00], [moyu],
[and other things],
)
Currently i have implement table format if a table:
columns
is int or arrayi'm going to support header/footer/vline/hline in the next step
Currently i have implement table format if a table:
- no comments
- no spread args
- no named args, or named args appears before all pos args
- no function call
columns
is int or array
I think the limitation can be somehow loosed to follows:
columns
is int or arrayThis allows header/footer usage, which will possibly help #78(Although the author doesn't provide their code yet). To format them, we can put header/footer in a single line.
Another way is that for table, we only format each args and don't change newlines, so user can freely arrange their cells. This can be a fallback code path.
Inspired by https://typst.app/universe/package/pillar's string command, we may have some general macro to hint formatting to call, which could also be the intermediate structure between smart formatters and the base formatter.
the macro is:
// @typstyle:call-group=4|4+,{1,_,2},4
// `|`: a line caused by the mid line in `call-group` macro
// `4+`: multiple arguments are group by 4.
#table([],[],[],[], [],[],[],[], [],[],[], [],[],[],[])
is formatted as:
// @typstyle:call-group=4|4+,{1,_,2},4
#table(
[],[],[],[],
[],[],[],[],
[], [],[],
[],[],[],[],
)
struct SmartFormatter;
impl SmartFormatter {
fn identify_dsl_calls(input: Input) -> ResultMap {
let res = ResultMap::default();
res.insert(LineCol(2, 0), "4|4+,{1,_,2},4");
res
}
}
An easy but powerful format is required by this approach tho.
Another way is that for table, we only format each args and don't change newlines, so user can freely arrange their cells. This can be a fallback code path.
implemented in #90
https://github.com/astrale-sharp/typstfmt/discussions/170#discussion-6548338
Would it be possible to format tables in a way that makes since while reading them ?
example