aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-11 11:01:49 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-11 11:01:49 +0200
commit053a2603e4bd5ec9caf40617b52136e5ef3fcf0a (patch)
tree14719bc0759a3a9039e88368d3c10ace5075e906 /src/compiler.rs
parent30e5f806277d14d5dcab708ccd0ce07a4894c1f9 (diff)
downloadmarkdown-rs-053a2603e4bd5ec9caf40617b52136e5ef3fcf0a.tar.gz
markdown-rs-053a2603e4bd5ec9caf40617b52136e5ef3fcf0a.tar.bz2
markdown-rs-053a2603e4bd5ec9caf40617b52136e5ef3fcf0a.zip
Add improved container exit injection
Diffstat (limited to '')
-rw-r--r--src/compiler.rs69
1 files changed, 42 insertions, 27 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index 57ab40a..4a9ec36 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -479,48 +479,63 @@ fn on_enter_list(context: &mut CompileContext) {
} else {
balance -= 1;
- // Blank line directly in list or directly in list item,
- // but not a blank line after an empty list item.
if balance < 3 && event.token_type == Token::BlankLineEnding {
- let mut at_marker = false;
+ // Blank line directly after a prefix:
+ //
+ // ```markdown
+ // > | -␊
+ // ^
+ // | a
+ // ```
+ let mut at_prefix = false;
+ // Blank line directly after item, which is just a prefix.
+ //
+ // ```markdown
+ // > | -␊
+ // ^
+ // | - a
+ // ```
+ let mut at_empty_list_item = false;
+ // Blank line at block quote prefix:
+ //
+ // ```markdown
+ // > | * >␊
+ // ^
+ // | * a
+ // ```
+ let mut at_empty_block_quote = false;
- if balance == 2 {
+ if balance == 1 {
let mut before = index - 2;
- if events[before].token_type == Token::SpaceOrTab {
- before -= 2;
- }
-
- if events[before].token_type == Token::ListItemPrefix {
- at_marker = true;
- }
- }
+ if events[before].token_type == Token::ListItem {
+ before -= 1;
- let mut at_empty_list_item = false;
- let mut at_empty_block_quote = false;
+ if events[before].token_type == Token::SpaceOrTab {
+ before -= 2;
+ }
- if balance == 1 {
+ if events[before].token_type == Token::BlockQuote
+ && events[before - 1].token_type == Token::BlockQuotePrefix
+ {
+ at_empty_block_quote = true;
+ } else if events[before].token_type == Token::ListItemPrefix {
+ at_empty_list_item = true;
+ }
+ }
+ } else {
let mut before = index - 2;
if events[before].token_type == Token::SpaceOrTab {
before -= 2;
}
- if events[before].token_type == Token::ListItem
- && events[before - 1].token_type == Token::ListItemPrefix
- {
- at_empty_list_item = true;
- }
-
- if events[before].token_type == Token::ListItem
- && events[before - 1].token_type == Token::BlockQuote
- && events[before - 2].token_type == Token::BlockQuotePrefix
- {
- at_empty_block_quote = true;
+ if events[before].token_type == Token::ListItemPrefix {
+ at_prefix = true;
}
}
- if !at_marker && !at_empty_list_item && !at_empty_block_quote {
+ if !at_prefix && !at_empty_list_item && !at_empty_block_quote {
loose = true;
break;
}