From 053a2603e4bd5ec9caf40617b52136e5ef3fcf0a Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 11 Aug 2022 11:01:49 +0200 Subject: Add improved container exit injection --- src/compiler.rs | 69 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'src/compiler.rs') 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; } -- cgit