mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Add support for more characters in links (#379)
This commit is contained in:
parent
5aa2ba1490
commit
ed36ef3312
@ -264,16 +264,35 @@ impl Lexer<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn link(&mut self) -> SyntaxKind {
|
fn link(&mut self) -> SyntaxKind {
|
||||||
|
let mut bracket_stack = Vec::new();
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
self.s.eat_while(|c: char| matches!(c,
|
self.s.eat_while(|c: char| {
|
||||||
| '0' ..= '9'
|
match c {
|
||||||
| 'a' ..= 'z'
|
| '0' ..= '9'
|
||||||
| 'A' ..= 'Z'
|
| 'a' ..= 'z'
|
||||||
| '~' | '/' | '%' | '?' | '#' | '&' | '+' | '='
|
| 'A' ..= 'Z'
|
||||||
| '\'' | '.' | ',' | ';'
|
| '!' | '#' | '$' | '%' | '&' | '*' | '+'
|
||||||
));
|
| ',' | '-' | '.' | '/' | ':' | ';' | '='
|
||||||
|
| '?' | '@' | '_' | '~' | '\'' => true,
|
||||||
|
'[' => {
|
||||||
|
bracket_stack.push(SyntaxKind::LeftBracket);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
'(' => {
|
||||||
|
bracket_stack.push(SyntaxKind::LeftParen);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
']' => bracket_stack.pop() == Some(SyntaxKind::LeftBracket),
|
||||||
|
')' => bracket_stack.pop() == Some(SyntaxKind::LeftParen),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if !bracket_stack.is_empty() {
|
||||||
|
return self.error_at_end("expected closing bracket in link");
|
||||||
|
}
|
||||||
|
|
||||||
if self.s.scout(-1) == Some('.') {
|
// Don't include the trailing characters likely to be part of another expression.
|
||||||
|
if matches!(self.s.scout(-1), Some('!' | ',' | '.' | ':' | ';' | '?' | '\'')) {
|
||||||
self.s.uneat();
|
self.s.uneat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 90 KiB |
@ -22,6 +22,22 @@ Wahttp://link \
|
|||||||
Nohttps:\//link \
|
Nohttps:\//link \
|
||||||
Nohttp\://comment
|
Nohttp\://comment
|
||||||
|
|
||||||
|
---
|
||||||
|
// Verify that brackets are included in links.
|
||||||
|
https://[::1]:8080/ \
|
||||||
|
https://example.com/(paren) \
|
||||||
|
https://example.com/#(((nested))) \
|
||||||
|
|
||||||
|
---
|
||||||
|
// Check that unbalanced brackets are not included in links.
|
||||||
|
#[https://example.com/] \
|
||||||
|
https://example.com/)
|
||||||
|
|
||||||
|
---
|
||||||
|
// Verify that opening brackets without closing brackets throw an error.
|
||||||
|
// Error: 22-22 expected closing bracket in link
|
||||||
|
https://exam(ple.com/
|
||||||
|
|
||||||
---
|
---
|
||||||
// Styled with underline and color.
|
// Styled with underline and color.
|
||||||
#show link: it => underline(text(fill: rgb("283663"), it))
|
#show link: it => underline(text(fill: rgb("283663"), it))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user