Skip to content

Commit

Permalink
Fix container close after unclosed fenced code, w/ eol
Browse files Browse the repository at this point in the history
Closes GH-16

Co-authored-by: Christian Murphy <christian.murphy.42@gmail.com>
  • Loading branch information
wooorm and ChristianMurphy committed Oct 26, 2022
1 parent bfe2f86 commit ccf6775
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/construct/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,33 @@ fn resolve(tokenizer: &mut Tokenizer) {
let mut line = 0;

while child_index < child.events.len() {
let event = &child.events[child_index];

if event.kind == Kind::Enter
&& (event.name == Name::LineEnding || event.name == Name::BlankLineEnding)
if child.events[child_index].kind == Kind::Exit
&& matches!(
child.events[child_index].name,
Name::LineEnding | Name::BlankLineEnding
)
{
// Inject before `Enter:LineEnding`.
let mut inject_index = child_index - 1;
let mut point = &child.events[inject_index].point;

while child_index + 1 < child.events.len()
&& child.events[child_index + 1].kind == Kind::Exit
{
child_index += 1;
point = &child.events[child_index].point;
// Inject after `Exit:*`.
inject_index = child_index + 1;
}

if let Some(mut exits) = tokenizer.tokenize_state.document_exits[line].take() {
let mut exit_index = 0;
while exit_index < exits.len() {
exits[exit_index].point = event.point.clone();
exits[exit_index].point = point.clone();
exit_index += 1;
}

child.map.add(child_index, 0, exits);
child.map.add(inject_index, 0, exits);
}

line += 1;
Expand Down
12 changes: 12 additions & 0 deletions tests/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,17 @@ fn fuzz() -> Result<(), String> {
"5: lists should support high start numbers (GH-17)"
);

assert_eq!(
to_html("> ```\n"),
"<blockquote>\n<pre><code>\n</code></pre>\n</blockquote>",
"6-a: container close after unclosed fenced code, with eol (block quote, GH-16)"
);

assert_eq!(
to_html("- ```\n"),
"<ul>\n<li>\n<pre><code>\n</code></pre>\n</li>\n</ul>",
"6-b: container close after unclosed fenced code, with eol (list, GH-16)"
);

Ok(())
}

0 comments on commit ccf6775

Please sign in to comment.