diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-09-09 13:17:59 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-09-09 13:17:59 +0200 |
commit | 118cc91fd56a9b4c93bec5b1cb4c5f25924d353e (patch) | |
tree | 3a33911c5b3f7da33919dfb48f1a0b8f8b46bb1b /src/construct/mdx_expression_flow.rs | |
parent | ffef323d3c927f84e94cae21afeb541be7320f1c (diff) | |
download | markdown-rs-118cc91fd56a9b4c93bec5b1cb4c5f25924d353e.tar.gz markdown-rs-118cc91fd56a9b4c93bec5b1cb4c5f25924d353e.tar.bz2 markdown-rs-118cc91fd56a9b4c93bec5b1cb4c5f25924d353e.zip |
Add mdx expression (flow, text)
Diffstat (limited to 'src/construct/mdx_expression_flow.rs')
-rw-r--r-- | src/construct/mdx_expression_flow.rs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/construct/mdx_expression_flow.rs b/src/construct/mdx_expression_flow.rs new file mode 100644 index 0000000..0faea31 --- /dev/null +++ b/src/construct/mdx_expression_flow.rs @@ -0,0 +1,84 @@ +//! To do. + +use crate::construct::partial_space_or_tab::{space_or_tab, space_or_tab_min_max}; +use crate::event::Name; +use crate::state::{Name as StateName, State}; +use crate::tokenizer::Tokenizer; +use crate::util::constant::TAB_SIZE; + +/// Start of MDX: expression (flow). +/// +/// ```markdown +/// > | {Math.PI} +/// ^ +/// ``` +pub fn start(tokenizer: &mut Tokenizer) -> State { + if tokenizer.parse_state.options.constructs.mdx_expression_flow { + tokenizer.tokenize_state.token_1 = Name::MdxFlowExpression; + tokenizer.concrete = true; + if matches!(tokenizer.current, Some(b'\t' | b' ')) { + tokenizer.attempt(State::Next(StateName::MdxExpressionFlowBefore), State::Nok); + State::Retry(space_or_tab_min_max( + tokenizer, + 0, + if tokenizer.parse_state.options.constructs.code_indented { + TAB_SIZE - 1 + } else { + usize::MAX + }, + )) + } else { + State::Retry(StateName::MdxExpressionFlowBefore) + } + } else { + State::Nok + } +} + +/// After optional whitespace, before of MDX expression (flow). +/// +/// ```markdown +/// > | {Math.PI} +/// ^ +/// ``` +pub fn before(tokenizer: &mut Tokenizer) -> State { + if Some(b'{') == tokenizer.current { + tokenizer.attempt(State::Next(StateName::MdxExpressionFlowAfter), State::Nok); + State::Retry(StateName::MdxExpressionStart) + } else { + State::Nok + } +} + +/// After an MDX expression (flow). +/// +/// ```markdown +/// > | {Math.PI} +/// ^ +/// ``` +pub fn after(tokenizer: &mut Tokenizer) -> State { + match tokenizer.current { + Some(b'\t' | b' ') => { + tokenizer.attempt(State::Next(StateName::MdxExpressionFlowEnd), State::Nok); + State::Retry(space_or_tab(tokenizer)) + } + _ => State::Retry(StateName::MdxExpressionFlowEnd), + } +} + +/// After an MDX expression (flow), after optional whitespace. +/// +/// ```markdown +/// > | {Math.PI}␠␊ +/// ^ +/// ``` +pub fn end(tokenizer: &mut Tokenizer) -> State { + tokenizer.concrete = false; + tokenizer.tokenize_state.token_1 = Name::Data; + + if matches!(tokenizer.current, None | Some(b'\n')) { + State::Ok + } else { + State::Nok + } +} |