aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-26 11:00:57 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-26 11:00:57 +0200
commitccf6775c848ba798c011654905269e3300e0079a (patch)
treea58f1fb2b060c14364328f981f50b1ab9ed3abf2 /src/construct
parentbfe2f86e99b5528c636cc4002ce10e9af06de0c0 (diff)
downloadmarkdown-rs-ccf6775c848ba798c011654905269e3300e0079a.tar.gz
markdown-rs-ccf6775c848ba798c011654905269e3300e0079a.tar.bz2
markdown-rs-ccf6775c848ba798c011654905269e3300e0079a.zip
Fix container close after unclosed fenced code, w/ eol
Closes GH-16 Co-authored-by: Christian Murphy <christian.murphy.42@gmail.com>
Diffstat (limited to 'src/construct')
-rw-r--r--src/construct/document.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/construct/document.rs b/src/construct/document.rs
index daf7131..a81be8a 100644
--- a/src/construct/document.rs
+++ b/src/construct/document.rs
@@ -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;