mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Capability to escape the tilde symbol 💨
This commit is contained in:
parent
d0e252d116
commit
08433ab79f
@ -109,7 +109,16 @@ impl Parser<'_> {
|
|||||||
let mut iter = text.chars();
|
let mut iter = text.chars();
|
||||||
while let Some(c) = iter.next() {
|
while let Some(c) = iter.next() {
|
||||||
match c {
|
match c {
|
||||||
'~' => text_s.push('\u{00A0}'),
|
'~' => {
|
||||||
|
// The escape sequence will separate
|
||||||
|
// the ~ into its own text node, therefore
|
||||||
|
// check the length here.
|
||||||
|
if text.len() == 1 {
|
||||||
|
text_s.push('~');
|
||||||
|
} else {
|
||||||
|
text_s.push('\u{00A0}');
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => text_s.push(c),
|
_ => text_s.push(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1017,6 +1026,7 @@ mod tests {
|
|||||||
t!("hi_" => T("hi"), I);
|
t!("hi_" => T("hi"), I);
|
||||||
t!("hi you" => T("hi"), S, T("you"));
|
t!("hi you" => T("hi"), S, T("you"));
|
||||||
t!("special~name" => T("special\u{00A0}name"));
|
t!("special~name" => T("special\u{00A0}name"));
|
||||||
|
t!("special\\~name" => T("special"), T("~"), T("name"));
|
||||||
t!("\\u{1f303}" => T("🌃"));
|
t!("\\u{1f303}" => T("🌃"));
|
||||||
t!("\n\n\nhello" => P, T("hello"));
|
t!("\n\n\nhello" => P, T("hello"));
|
||||||
t!(r"a\ b" => T("a"), L, S, T("b"));
|
t!(r"a\ b" => T("a"), L, S, T("b"));
|
||||||
|
@ -439,7 +439,7 @@ impl<'s> Tokens<'s> {
|
|||||||
fn read_escaped(&mut self) -> Token<'s> {
|
fn read_escaped(&mut self) -> Token<'s> {
|
||||||
fn is_escapable(c: char) -> bool {
|
fn is_escapable(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
'[' | ']' | '\\' | '/' | '*' | '_' | '`' | '"' => true,
|
'[' | ']' | '\\' | '/' | '*' | '_' | '`' | '"' | '~' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user