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
};
// 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]

View file

@ -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();