Fix string quoting

This commit is contained in:
Joscha 2024-05-04 23:05:08 +02:00
parent d918e3f724
commit b14284b6ac

View file

@ -60,8 +60,18 @@ pub struct Timesheet {
///////////////////////
fn fmt_str(s: &str) -> String {
// https://github.com/typst/typst/blob/69dcc89d84176838c293b2d59747cd65e28843ad/crates/typst-syntax/src/ast.rs#L1041-L1082
format!("\"{}\"", s.replace('\\', "\\\\"))
// https://github.com/typst/typst/blob/v0.11.0/crates/typst-syntax/src/lexer.rs#L699-L713
// https://github.com/typst/typst/blob/v0.11.0/crates/typst-syntax/src/ast.rs#L1041-L1082
let quoted = s
.chars()
.map(|c| match c {
'"' => "\\\"".to_string(),
'\\' => "\\\\".to_string(),
c => c.to_string(),
})
.collect::<String>();
format!("\"{}\"", quoted)
}
fn fmt_int(n: u32) -> String {