Skip to content

Commit

Permalink
fix: correctly parse incomplete inlines inside of a scope
Browse files Browse the repository at this point in the history
  • Loading branch information
nfejzic committed Jul 17, 2022
1 parent 56438e2 commit 9b1d7c9
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions inline/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,27 @@ impl Parser<'_> {
) -> Inline {
// It is closing one, but it was not open last -> Return contents as inline

// remove the opening token from the stack
let token = self.pop(&next_token).unwrap();

// NOTE: when coming from nested, while loop will be continued -> takes
// another token from iterator or cache
self.token_cache = Some(next_token);
while !self.is_token_latest(&next_token) {
match self.pop_last() {
Some(token) => {
// prepend the token to content as plain text
content.prepend(InlineContent::from_token_as_plain(token));
}
None => break,
}
}

// prepend the token to content as plain text
content.prepend(InlineContent::from_token_as_plain(token));
if let Some(last_token) = self.pop(&next_token) {
let start = last_token.span().start();
let end = next_token.span().end();

Inline::Plain(content.into_plain())
Inline::with_span(content, last_token.kind(), Span::from((start, end)))
} else {
// NOTE: when coming from nested, while loop will be continued -> takes
// another token from iterator or cache
self.token_cache = Some(next_token);
Inline::new(content, TokenKind::Plain)
}
}

/// Consumes the [`Token`] as [`Inline::Plain`] and appends it to the current
Expand Down

0 comments on commit 9b1d7c9

Please sign in to comment.