Skip to content

Commit ccf6775

Browse files
Fix container close after unclosed fenced code, w/ eol
Closes GH-16 Co-authored-by: Christian Murphy <[email protected]>
1 parent bfe2f86 commit ccf6775

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/construct/document.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,19 +546,33 @@ fn resolve(tokenizer: &mut Tokenizer) {
546546
let mut line = 0;
547547

548548
while child_index < child.events.len() {
549-
let event = &child.events[child_index];
550-
551-
if event.kind == Kind::Enter
552-
&& (event.name == Name::LineEnding || event.name == Name::BlankLineEnding)
549+
if child.events[child_index].kind == Kind::Exit
550+
&& matches!(
551+
child.events[child_index].name,
552+
Name::LineEnding | Name::BlankLineEnding
553+
)
553554
{
555+
// Inject before `Enter:LineEnding`.
556+
let mut inject_index = child_index - 1;
557+
let mut point = &child.events[inject_index].point;
558+
559+
while child_index + 1 < child.events.len()
560+
&& child.events[child_index + 1].kind == Kind::Exit
561+
{
562+
child_index += 1;
563+
point = &child.events[child_index].point;
564+
// Inject after `Exit:*`.
565+
inject_index = child_index + 1;
566+
}
567+
554568
if let Some(mut exits) = tokenizer.tokenize_state.document_exits[line].take() {
555569
let mut exit_index = 0;
556570
while exit_index < exits.len() {
557-
exits[exit_index].point = event.point.clone();
571+
exits[exit_index].point = point.clone();
558572
exit_index += 1;
559573
}
560574

561-
child.map.add(child_index, 0, exits);
575+
child.map.add(inject_index, 0, exits);
562576
}
563577

564578
line += 1;

tests/fuzz.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,17 @@ fn fuzz() -> Result<(), String> {
5656
"5: lists should support high start numbers (GH-17)"
5757
);
5858

59+
assert_eq!(
60+
to_html("> ```\n"),
61+
"<blockquote>\n<pre><code>\n</code></pre>\n</blockquote>",
62+
"6-a: container close after unclosed fenced code, with eol (block quote, GH-16)"
63+
);
64+
65+
assert_eq!(
66+
to_html("- ```\n"),
67+
"<ul>\n<li>\n<pre><code>\n</code></pre>\n</li>\n</ul>",
68+
"6-b: container close after unclosed fenced code, with eol (list, GH-16)"
69+
);
70+
5971
Ok(())
6072
}

0 commit comments

Comments
 (0)