From 06b6c38f3086b31873ca4399d4a66f0440f249fe Mon Sep 17 00:00:00 2001 From: electria Date: Tue, 29 Sep 2026 16:03:32 -0700 Subject: [PATCH] feat: ignore and add back trailing backslash --- src/main.rs | 8 +++++--- src/nodes/from_str.rs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3e9206b..fbb3a72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,14 +34,15 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String { false }; - // no need to remove the character here, - // as we ignore the ampersand in all other logic already + // no need to remove the characters here, + // as we ignore the them in all other logic already let should_add_back_alignment = input.contains('&'); + let should_add_back_backslash = input.contains('\\'); let result = parse_and_calc(&input); format!( - "{0}{result:.1$}", + "{0}{result:.1$}{2}", if should_add_back_equals && should_add_back_alignment { "& = " } else if should_add_back_equals { @@ -52,6 +53,7 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String { "" }, get_significant_digits(&result), + if should_add_back_backslash { " \\" } else { "" } ) } #[test] diff --git a/src/nodes/from_str.rs b/src/nodes/from_str.rs index 14e4c9a..189f14c 100644 --- a/src/nodes/from_str.rs +++ b/src/nodes/from_str.rs @@ -81,12 +81,12 @@ impl FromStr for Nodes { /// /// We ignore whitespace since it has no semantic significance in typst /// (aside from variables, which are not implemented) - /// and `&` because it is only used for visual alignment. + /// and `&`, `\` because they are only used for visual alignment. /// /// Newlines are also ignored because they're likely accidental; /// like in the case of `echo 1+1 | tylc`. fn is_not_ignored_char(c: &char) -> bool { - !matches!(c, ' ' | '&' | '\n') + !matches!(c, ' ' | '&' | '\n' | '\\') } let mut nodes = Vec::new();