feat: ignore and add back trailing backslash

This commit is contained in:
electria 2026-09-29 16:03:32 -07:00
commit 06b6c38f30
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 7 additions and 5 deletions

View file

@ -34,14 +34,15 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String {
false false
}; };
// no need to remove the character here, // no need to remove the characters here,
// as we ignore the ampersand in all other logic already // as we ignore the them in all other logic already
let should_add_back_alignment = input.contains('&'); let should_add_back_alignment = input.contains('&');
let should_add_back_backslash = input.contains('\\');
let result = parse_and_calc(&input); let result = parse_and_calc(&input);
format!( format!(
"{0}{result:.1$}", "{0}{result:.1$}{2}",
if should_add_back_equals && should_add_back_alignment { if should_add_back_equals && should_add_back_alignment {
"& = " "& = "
} else if should_add_back_equals { } else if should_add_back_equals {
@ -52,6 +53,7 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String {
"" ""
}, },
get_significant_digits(&result), get_significant_digits(&result),
if should_add_back_backslash { " \\" } else { "" }
) )
} }
#[test] #[test]

View file

@ -81,12 +81,12 @@ impl FromStr for Nodes {
/// ///
/// We ignore whitespace since it has no semantic significance in typst /// We ignore whitespace since it has no semantic significance in typst
/// (aside from variables, which are not implemented) /// (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; /// Newlines are also ignored because they're likely accidental;
/// like in the case of `echo 1+1 | tylc`. /// like in the case of `echo 1+1 | tylc`.
fn is_not_ignored_char(c: &char) -> bool { fn is_not_ignored_char(c: &char) -> bool {
!matches!(c, ' ' | '&' | '\n') !matches!(c, ' ' | '&' | '\n' | '\\')
} }
let mut nodes = Vec::new(); let mut nodes = Vec::new();