diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-07 17:21:38 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-07 17:36:35 +0200 |
commit | 4806864e5377a5fef937b3fa02542e620c547969 (patch) | |
tree | c91ae2bbd1dc2037f425efd24d62d05e706e3e60 /src/construct/heading_setext.rs | |
parent | c2b4402223e53498078fc33dd55aabc0a48cdb56 (diff) | |
download | markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.tar.gz markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.tar.bz2 markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.zip |
Add basic support for block quotes
Diffstat (limited to '')
-rw-r--r-- | src/construct/heading_setext.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/construct/heading_setext.rs b/src/construct/heading_setext.rs index 211434f..440baa8 100644 --- a/src/construct/heading_setext.rs +++ b/src/construct/heading_setext.rs @@ -60,7 +60,7 @@ use crate::constant::TAB_SIZE; use crate::construct::partial_space_or_tab::{space_or_tab, space_or_tab_min_max}; use crate::tokenizer::{Code, Event, EventType, State, StateFnResult, TokenType, Tokenizer}; -use crate::util::edit_map::EditMap; +use crate::util::{edit_map::EditMap, skip::opt_back as skip_opt_back}; /// Kind of underline. #[derive(Debug, Clone, PartialEq)] @@ -116,11 +116,26 @@ impl Kind { /// ``` pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { let index = tokenizer.events.len(); - let paragraph_before = index > 3 - && tokenizer.events[index - 1].token_type == TokenType::LineEnding - && tokenizer.events[index - 3].token_type == TokenType::Paragraph; - - if paragraph_before { + let previous = if index > 1 { + skip_opt_back( + &tokenizer.events, + index - 1, + &[TokenType::SpaceOrTab, TokenType::BlockQuotePrefix], + ) + } else { + 0 + }; + let previous = skip_opt_back(&tokenizer.events, previous, &[TokenType::LineEnding]); + let paragraph_before = + previous > 1 && tokenizer.events[previous].token_type == TokenType::Paragraph; + + println!( + "setext-start: {:?} {:?} {:?}", + tokenizer.interrupt, tokenizer.lazy, paragraph_before + ); + + // Require a paragraph before and do not allow on a lazy line. + if paragraph_before && !tokenizer.lazy { // To do: allow arbitrary when code (indented) is turned off. tokenizer.go(space_or_tab_min_max(0, TAB_SIZE - 1), before)(tokenizer, code) } else { |