diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-21 18:06:47 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-21 18:06:47 +0200 |
commit | d1063268e62633a334bb9464f7cba2385da5812d (patch) | |
tree | 76035cdf260046cd2afe1841c0351b311ea66d99 /src/construct/definition.rs | |
parent | 56ff5c73c7ec19b349e7d60d04ce1057c006d6ec (diff) | |
download | markdown-rs-d1063268e62633a334bb9464f7cba2385da5812d.tar.gz markdown-rs-d1063268e62633a334bb9464f7cba2385da5812d.tar.bz2 markdown-rs-d1063268e62633a334bb9464f7cba2385da5812d.zip |
Add support for passing token types to destination, label, title
Diffstat (limited to '')
-rw-r--r-- | src/construct/definition.rs | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/construct/definition.rs b/src/construct/definition.rs index 61c4d34..69d8d9b 100644 --- a/src/construct/definition.rs +++ b/src/construct/definition.rs @@ -57,8 +57,10 @@ //! <!-- To do: describe how references and definitions match --> use crate::construct::{ - partial_destination::start as destination, partial_label::start as label, - partial_space_or_tab::space_or_tab_opt, partial_title::start as title, + partial_destination::{start as destination, Options as DestinationOptions}, + partial_label::{start as label, Options as LabelOptions}, + partial_space_or_tab::space_or_tab_opt, + partial_title::{start as title, Options as TitleOptions}, }; use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer}; @@ -79,7 +81,20 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// ``` pub fn before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { match code { - Code::Char('[') => tokenizer.go(label, label_after)(tokenizer, code), + Code::Char('[') => tokenizer.go( + |t, c| { + label( + t, + c, + LabelOptions { + label: TokenType::DefinitionLabel, + marker: TokenType::DefinitionLabelMarker, + string: TokenType::DefinitionLabelString, + }, + ) + }, + label_after, + )(tokenizer, code), _ => (State::Nok, None), } } @@ -152,7 +167,22 @@ fn destination_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { code, Code::None | Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') ) { - tokenizer.go(destination, destination_after)(tokenizer, code) + tokenizer.go( + |t, c| { + destination( + t, + c, + DestinationOptions { + destination: TokenType::DefinitionDestination, + literal: TokenType::DefinitionDestinationLiteral, + marker: TokenType::DefinitionDestinationLiteralMarker, + raw: TokenType::DefinitionDestinationRaw, + string: TokenType::DefinitionDestinationString, + }, + ) + }, + destination_after, + )(tokenizer, code) } else { (State::Nok, None) } @@ -243,7 +273,20 @@ fn title_before_marker(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { let event = tokenizer.events.last().unwrap(); if event.token_type == TokenType::LineEnding || event.token_type == TokenType::Whitespace { - tokenizer.go(title, title_after)(tokenizer, code) + tokenizer.go( + |t, c| { + title( + t, + c, + TitleOptions { + title: TokenType::DefinitionTitle, + marker: TokenType::DefinitionTitleMarker, + string: TokenType::DefinitionTitleString, + }, + ) + }, + title_after, + )(tokenizer, code) } else { (State::Nok, None) } |