aboutsummaryrefslogtreecommitdiffstats
path: root/src/content
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-13 10:40:11 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-13 10:40:11 +0200
commitad8eac98c1468b30c17c339e79b84c37a7b15517 (patch)
treedaffac5b46b474787ebe6e886061510249f37cab /src/content
parent86834a02b301bba48c2bd568beb156e604470167 (diff)
downloadmarkdown-rs-ad8eac98c1468b30c17c339e79b84c37a7b15517.tar.gz
markdown-rs-ad8eac98c1468b30c17c339e79b84c37a7b15517.tar.bz2
markdown-rs-ad8eac98c1468b30c17c339e79b84c37a7b15517.zip
Fix to close containers before several (blank) line endings
Diffstat (limited to 'src/content')
-rw-r--r--src/content/document.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/content/document.rs b/src/content/document.rs
index 27fb73d..7f8a116 100644
--- a/src/content/document.rs
+++ b/src/content/document.rs
@@ -410,6 +410,7 @@ fn flow_end(
let mut index = 0;
let add = info.inject[line_index].0.clone();
+ let mut first_line_ending_in_run: Option<usize> = None;
map.add(0, 0, add);
while index < tokenizer.events.len() {
@@ -419,19 +420,28 @@ fn flow_end(
|| event.token_type == Token::BlankLineEnding
{
if event.event_type == EventType::Enter {
+ first_line_ending_in_run = first_line_ending_in_run.or(Some(index));
let mut add = info.inject[line_index].1.clone();
- let mut deep_index = 0;
- while deep_index < add.len() {
- add[deep_index].point = event.point.clone();
- add[deep_index].index = event.index;
- deep_index += 1;
+ let mut index = 0;
+ while index < add.len() {
+ add[index].point = event.point.clone();
+ add[index].index = event.index;
+ index += 1;
+ }
+ if !add.is_empty() {
+ map.add(first_line_ending_in_run.unwrap(), 0, add);
}
- map.add(index, 0, add);
} else {
line_index += 1;
let add = info.inject[line_index].0.clone();
- map.add(index + 1, 0, add);
+ if !add.is_empty() {
+ map.add(index + 1, 0, add);
+ }
}
+ } else if event.token_type == Token::SpaceOrTab {
+ // Empty to allow whitespace in blank lines.
+ } else {
+ first_line_ending_in_run = None;
}
index += 1;