From 9bab2951cd3e9d492f3aa9f127531643323a1de1 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 9 Aug 2022 17:32:01 +0200 Subject: Add peeking to unindented flow lines --- src/content/flow.rs | 58 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 11 deletions(-) (limited to 'src/content/flow.rs') diff --git a/src/content/flow.rs b/src/content/flow.rs index bfaf5e9..b3fb866 100644 --- a/src/content/flow.rs +++ b/src/content/flow.rs @@ -34,15 +34,56 @@ use crate::tokenizer::{State, StateName, Tokenizer}; /// ``` pub fn start(tokenizer: &mut Tokenizer) -> State { match tokenizer.current { - None => State::Ok, - _ => tokenizer.attempt( - StateName::BlankLineStart, - State::Fn(StateName::FlowBlankLineAfter), - State::Fn(StateName::FlowBefore), + Some(b'`' | b'~') => tokenizer.attempt( + StateName::CodeFencedStart, + State::Fn(StateName::FlowAfter), + State::Fn(StateName::FlowBeforeParagraph), + ), + Some(b'<') => tokenizer.attempt( + StateName::HtmlFlowStart, + State::Fn(StateName::FlowAfter), + State::Fn(StateName::FlowBeforeParagraph), + ), + Some(b'#') => tokenizer.attempt( + StateName::HeadingAtxStart, + State::Fn(StateName::FlowAfter), + State::Fn(StateName::FlowBeforeParagraph), + ), + // Note: `-` is also used in thematic breaks, so it’s not included here. + Some(b'=') => tokenizer.attempt( + StateName::HeadingSetextStart, + State::Fn(StateName::FlowAfter), + State::Fn(StateName::FlowBeforeParagraph), + ), + Some(b'*' | b'_') => tokenizer.attempt( + StateName::ThematicBreakStart, + State::Fn(StateName::FlowAfter), + State::Fn(StateName::FlowBeforeParagraph), + ), + Some(b'[') => tokenizer.attempt( + StateName::DefinitionStart, + State::Fn(StateName::FlowAfter), + State::Fn(StateName::FlowBeforeParagraph), + ), + // Actual parsing: blank line? Indented code? Indented anything? + // Also includes `-` which can be a setext heading underline or a thematic break. + None | Some(b'\t' | b'\n' | b' ' | b'-') => before_blank_line(tokenizer), + Some(_) => tokenizer.attempt( + StateName::ParagraphStart, + State::Fn(StateName::FlowAfter), + State::Nok, ), } } +pub fn before_blank_line(tokenizer: &mut Tokenizer) -> State { + tokenizer.attempt( + StateName::BlankLineStart, + State::Fn(StateName::FlowBlankLineAfter), + State::Fn(StateName::FlowBeforeCodeIndented), + ) +} + /// Before flow (initial). /// /// “Initial” flow means unprefixed flow, so right at the start of a line. @@ -55,17 +96,12 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { /// |~~~js /// |
/// ``` -pub fn before(tokenizer: &mut Tokenizer) -> State { - // match tokenizer.current { - // None => State::Ok, - // _ => { +pub fn before_code_indented(tokenizer: &mut Tokenizer) -> State { tokenizer.attempt( StateName::CodeIndentedStart, State::Fn(StateName::FlowAfter), State::Fn(StateName::FlowBeforeCodeFenced), ) - // } - // } } pub fn before_code_fenced(tokenizer: &mut Tokenizer) -> State { -- cgit