mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Merge pull request #14 from typst/non-breaking-space
Non-breaking spaces
This commit is contained in:
commit
798c8a10c8
@ -1001,18 +1001,20 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_simple_nodes() {
|
fn test_parse_simple_nodes() {
|
||||||
t!("" => );
|
t!("" => );
|
||||||
t!("hi" => T("hi"));
|
t!("hi" => T("hi"));
|
||||||
t!("*hi" => B, T("hi"));
|
t!("*hi" => B, T("hi"));
|
||||||
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!("\\u{1f303}" => T("🌃"));
|
t!("special~name" => T("special"), T("\u{00A0}"), T("name"));
|
||||||
t!("\n\n\nhello" => P, T("hello"));
|
t!("special\\~name" => T("special"), T("~"), T("name"));
|
||||||
t!(r"a\ b" => T("a"), L, S, T("b"));
|
t!("\\u{1f303}" => T("🌃"));
|
||||||
t!("`py`" => R!["py"]);
|
t!("\n\n\nhello" => P, T("hello"));
|
||||||
t!("`hi\nyou" => R!["hi", "you"]);
|
t!(r"a\ b" => T("a"), L, S, T("b"));
|
||||||
e!("`hi\nyou" => s(1,3, 1,3, "expected backtick"));
|
t!("`py`" => R!["py"]);
|
||||||
t!("`hi\\`du`" => R!["hi`du"]);
|
t!("`hi\nyou" => R!["hi", "you"]);
|
||||||
|
e!("`hi\nyou" => s(1,3, 1,3, "expected backtick"));
|
||||||
|
t!("`hi\\`du`" => R!["hi`du"]);
|
||||||
|
|
||||||
t!("```java System.out.print```" => C![Some("java"), "System.out.print"]);
|
t!("```java System.out.print```" => C![Some("java"), "System.out.print"]);
|
||||||
t!("``` console.log(\n\"alert\"\n)" => C![None, "console.log(", "\"alert\"", ")"]);
|
t!("``` console.log(\n\"alert\"\n)" => C![None, "console.log(", "\"alert\"", ")"]);
|
||||||
|
@ -265,6 +265,9 @@ impl<'s> Iterator for Tokens<'s> {
|
|||||||
'_' if self.mode == Body => Underscore,
|
'_' if self.mode == Body => Underscore,
|
||||||
'`' if self.mode == Body => self.read_raw_or_code(),
|
'`' if self.mode == Body => self.read_raw_or_code(),
|
||||||
|
|
||||||
|
// Non-breaking spaces.
|
||||||
|
'~' if self.mode == Body => Text("\u{00A0}"),
|
||||||
|
|
||||||
// An escaped thing.
|
// An escaped thing.
|
||||||
'\\' if self.mode == Body => self.read_escaped(),
|
'\\' if self.mode == Body => self.read_escaped(),
|
||||||
|
|
||||||
@ -279,7 +282,7 @@ impl<'s> Iterator for Tokens<'s> {
|
|||||||
let val = match n {
|
let val = match n {
|
||||||
c if c.is_whitespace() => true,
|
c if c.is_whitespace() => true,
|
||||||
'[' | ']' | '{' | '}' | '/' | '*' => true,
|
'[' | ']' | '{' | '}' | '/' | '*' => true,
|
||||||
'\\' | '_' | '`' if body => true,
|
'\\' | '_' | '`' | '~' if body => true,
|
||||||
':' | '=' | ',' | '"' | '(' | ')' if !body => true,
|
':' | '=' | ',' | '"' | '(' | ')' if !body => true,
|
||||||
'+' | '-' if !body && !last_was_e => true,
|
'+' | '-' if !body && !last_was_e => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
@ -439,7 +442,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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -646,6 +649,7 @@ mod tests {
|
|||||||
t!(Body, " \n\t \n " => S(2));
|
t!(Body, " \n\t \n " => S(2));
|
||||||
t!(Body, "\n\r" => S(2));
|
t!(Body, "\n\r" => S(2));
|
||||||
t!(Body, " \r\r\n \x0D" => S(3));
|
t!(Body, " \r\r\n \x0D" => S(3));
|
||||||
|
t!(Body, "a~b" => T("a"), T("\u{00A0}"), T("b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user