diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-08-09 10:45:15 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-08-09 10:45:15 +0200 |
commit | 4ce1ac9e41cafa9051377470e8a246063f7d9b1a (patch) | |
tree | d678d9583764b2706fe7ea4876e91e40609f15b0 /src/compiler.rs | |
parent | 8ffed1822bcbc1b6ce6647b840fb03996b0635ea (diff) | |
download | markdown-rs-4ce1ac9e41cafa9051377470e8a246063f7d9b1a.tar.gz markdown-rs-4ce1ac9e41cafa9051377470e8a246063f7d9b1a.tar.bz2 markdown-rs-4ce1ac9e41cafa9051377470e8a246063f7d9b1a.zip |
Rewrite algorithm to not pass around boxed functions
* Pass state names from an enum around instead of boxed functions
* Refactor to simplify attempts a lot
* Use a subtokenizer for the the `document` content type
Diffstat (limited to '')
-rw-r--r-- | src/compiler.rs | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index b86fd82..57ab40a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -482,28 +482,45 @@ fn on_enter_list(context: &mut CompileContext) { // 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 at_marker = balance == 2 - && events[skip::opt_back( - events, - index - 2, - &[Token::BlankLineEnding, Token::SpaceOrTab], - )] - .token_type - == Token::ListItemPrefix; - let at_list_item = balance == 1 && events[index - 2].token_type == Token::ListItem; - let at_empty_list_item = if at_list_item { - let before_item = skip::opt_back(events, index - 2, &[Token::ListItem]); - let before_prefix = skip::opt_back( - events, - index - 3, - &[Token::ListItemPrefix, Token::SpaceOrTab], - ); - before_item + 1 == before_prefix - } else { - false - }; + let mut at_marker = false; + + if balance == 2 { + let mut before = index - 2; + + if events[before].token_type == Token::SpaceOrTab { + before -= 2; + } + + if events[before].token_type == Token::ListItemPrefix { + at_marker = true; + } + } + + let mut at_empty_list_item = false; + let mut at_empty_block_quote = false; + + if balance == 1 { + 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 !at_marker && !at_list_item && !at_empty_list_item { + if !at_marker && !at_empty_list_item && !at_empty_block_quote { loose = true; break; } |