diff options
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/content.rs | 49 | ||||
-rw-r--r-- | src/content/flow.rs | 24 | ||||
-rw-r--r-- | src/content/string.rs | 2 |
3 files changed, 22 insertions, 53 deletions
diff --git a/src/content/content.rs b/src/content/content.rs index 4ca69ee..86bc290 100644 --- a/src/content/content.rs +++ b/src/content/content.rs @@ -16,10 +16,9 @@ use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer}; -/// Before content. +/// Before a paragraph. /// /// ```markdown -/// |[x]: y /// |asd /// ``` pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { @@ -27,48 +26,10 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { unreachable!("expected non-eol/eof"); } - _ => after_definitions(tokenizer, code) - // To do: definition. - // _ => tokenizer.attempt(definition, |ok| { - // Box::new(if ok { - // a - // } else { - // b - // }) - // })(tokenizer, code), - } -} - -/// Before a paragraph. -/// -/// ```markdown -/// |asd -/// ``` -fn after_definitions(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { - match code { - Code::None => (State::Ok, None), - Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { - unreachable!("to do: handle eol after definition"); - } - _ => paragraph_initial(tokenizer, code), - } -} - -/// Before a paragraph. -/// -/// ```markdown -/// |asd -/// ``` -fn paragraph_initial(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { - match code { - Code::None => (State::Ok, None), - Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { - unreachable!("to do: handle eol after definition"); - } _ => { tokenizer.enter(TokenType::Paragraph); tokenizer.enter(TokenType::ChunkText); - data(tokenizer, code, tokenizer.events.len() - 1) + inside(tokenizer, code, tokenizer.events.len() - 1) } } } @@ -79,7 +40,7 @@ fn paragraph_initial(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// |\& /// |qwe /// ``` -fn data(tokenizer: &mut Tokenizer, code: Code, previous_index: usize) -> StateFnResult { +fn inside(tokenizer: &mut Tokenizer, code: Code, previous_index: usize) -> StateFnResult { match code { Code::None => { tokenizer.exit(TokenType::ChunkText); @@ -94,14 +55,14 @@ fn data(tokenizer: &mut Tokenizer, code: Code, previous_index: usize) -> StateFn tokenizer.events[previous_index].next = Some(next_index); tokenizer.events[next_index].previous = Some(previous_index); ( - State::Fn(Box::new(move |t, c| data(t, c, next_index))), + State::Fn(Box::new(move |t, c| inside(t, c, next_index))), None, ) } _ => { tokenizer.consume(code); ( - State::Fn(Box::new(move |t, c| data(t, c, previous_index))), + State::Fn(Box::new(move |t, c| inside(t, c, previous_index))), None, ) } diff --git a/src/content/flow.rs b/src/content/flow.rs index d7509d7..3fab523 100644 --- a/src/content/flow.rs +++ b/src/content/flow.rs @@ -13,6 +13,7 @@ //! * [Blank line][crate::construct::blank_line] //! * [Code (fenced)][crate::construct::code_fenced] //! * [Code (indented)][crate::construct::code_indented] +//! * [Definition][crate::construct::definition] //! * [Heading (atx)][crate::construct::heading_atx] //! * [Heading (setext)][crate::construct::heading_setext] //! * [HTML (flow)][crate::construct::html_flow] @@ -23,9 +24,10 @@ use crate::constant::TAB_SIZE; use crate::construct::{ blank_line::start as blank_line, code_fenced::start as code_fenced, - code_indented::start as code_indented, heading_atx::start as heading_atx, - heading_setext::start as heading_setext, html_flow::start as html_flow, - partial_whitespace::start as whitespace, thematic_break::start as thematic_break, + code_indented::start as code_indented, definition::start as definition, + heading_atx::start as heading_atx, heading_setext::start as heading_setext, + html_flow::start as html_flow, partial_whitespace::start as whitespace, + thematic_break::start as thematic_break, }; use crate::subtokenize::subtokenize; use crate::tokenizer::{Code, Event, Point, State, StateFnResult, TokenType, Tokenizer}; @@ -96,6 +98,7 @@ fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { match code { Code::None => (State::Ok, None), + // To do: should all flow just start before the prefix? _ => tokenizer.attempt_3(code_indented, code_fenced, html_flow, |ok| { Box::new(if ok { after } else { before }) })(tokenizer, code), @@ -145,9 +148,13 @@ pub fn before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// |*** /// ``` pub fn before_after_prefix(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { - tokenizer.attempt_3(heading_atx, thematic_break, heading_setext, |ok| { - Box::new(if ok { after } else { content_before }) - })(tokenizer, code) + tokenizer.attempt_4( + heading_atx, + thematic_break, + definition, + heading_setext, + |ok| Box::new(if ok { after } else { content_before }), + )(tokenizer, code) } /// Before content. @@ -156,9 +163,7 @@ pub fn before_after_prefix(tokenizer: &mut Tokenizer, code: Code) -> StateFnResu /// |qwe /// ``` /// -// To do: -// - Multiline -// - One or more definitions. +// To do: we don’t need content anymore in `micromark-rs` it seems? fn content_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { match code { Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { @@ -247,6 +252,7 @@ fn continuation_construct_after_prefix(tokenizer: &mut Tokenizer, code: Code) -> Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => (State::Nok, None), // To do: If code is disabled, indented lines are part of the content. _ if prefix >= TAB_SIZE => (State::Ok, None), + // To do: definitions, setext headings, etc? _ => tokenizer.attempt_2(heading_atx, thematic_break, |ok| { let result = if ok { (State::Nok, None) diff --git a/src/content/string.rs b/src/content/string.rs index 25d8582..e8134c4 100644 --- a/src/content/string.rs +++ b/src/content/string.rs @@ -15,6 +15,8 @@ use crate::construct::{ }; use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer}; +// To do: line endings? + /// Before string. /// /// ```markdown |