From b14284b6acbd136b2168a9a9b50af8bfc1fb1f2d Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 4 May 2024 23:05:08 +0200 Subject: [PATCH] Fix string quoting --- src/render.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/render.rs b/src/render.rs index 3e09bda..a73f5ef 100644 --- a/src/render.rs +++ b/src/render.rs @@ -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::(); + + format!("\"{}\"", quoted) } fn fmt_int(n: u32) -> String {