Skip to content

Commit

Permalink
Fix parsing links with URL encoding (#1291)
Browse files Browse the repository at this point in the history
Adds a HREF token to represent urls (and unit tests for the parser).
  • Loading branch information
nolanking90 authored Dec 14, 2024
1 parent e99406e commit 2f79d32
Show file tree
Hide file tree
Showing 5 changed files with 545 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/parser/src/latex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl<'a> Parser<'a> {
Token::Pipe | Token::Word | Token::Comma => self.text(context),
Token::Eq => self.eat(),
Token::Dollar => self.formula(),
Token::Href => self.eat(),
Token::CommandName(name) => match name {
CommandName::Generic => self.generic_command(),
CommandName::BeginEnvironment if context.allow_environment => self.environment(),
Expand Down Expand Up @@ -1295,6 +1296,7 @@ impl<'a> Parser<'a> {

self.builder.finish_node();
}

}

pub fn parse_latex(text: &str, config: &SyntaxConfig) -> GreenNode {
Expand Down
1 change: 1 addition & 0 deletions crates/parser/src/latex/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl<'a> Lexer<'a> {
Token::Eq => SyntaxKind::EQUALITY_SIGN,
Token::Pipe => SyntaxKind::WORD,
Token::Word => SyntaxKind::WORD,
Token::Href => SyntaxKind::HREF,
Token::Dollar => SyntaxKind::DOLLAR,
Token::CommandName(_) => SyntaxKind::COMMAND_NAME,
};
Expand Down
3 changes: 3 additions & 0 deletions crates/parser/src/latex/lexer/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub enum Token {
#[regex(r"[^\s\\%\{\},\$\[\]\(\)=\|]+")]
Word,

#[regex(r"[a-zA-Z]+:\/\/[^{}]+")]
Href,

#[regex(r"\$\$?")]
Dollar,

Expand Down
Loading

0 comments on commit 2f79d32

Please sign in to comment.