diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-18 16:31:14 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-18 16:31:14 +0200 |
commit | 5403261e8213f68633a09fc3e9bc2e6e2cd777b2 (patch) | |
tree | bb3a6419ef42f7611c2cb24fe7024228f579331b /src/construct/code_fenced.rs | |
parent | 03544cafaa82ba4bd7e0bc3372fc59549a8dc0cc (diff) | |
download | markdown-rs-5403261e8213f68633a09fc3e9bc2e6e2cd777b2.tar.gz markdown-rs-5403261e8213f68633a09fc3e9bc2e6e2cd777b2.tar.bz2 markdown-rs-5403261e8213f68633a09fc3e9bc2e6e2cd777b2.zip |
Add support for turning off constructs
Diffstat (limited to '')
-rw-r--r-- | src/construct/code_fenced.rs | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/construct/code_fenced.rs b/src/construct/code_fenced.rs index d5001e7..49bcae3 100644 --- a/src/construct/code_fenced.rs +++ b/src/construct/code_fenced.rs @@ -189,10 +189,18 @@ struct Info { /// | ~~~ /// ``` pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { - tokenizer.enter(Token::CodeFenced); - tokenizer.enter(Token::CodeFencedFence); - // To do: allow arbitrary when code (indented) is turned off. - tokenizer.go(space_or_tab_min_max(0, TAB_SIZE - 1), before_sequence_open)(tokenizer, code) + let max = if tokenizer.parse_state.constructs.code_indented { + TAB_SIZE - 1 + } else { + usize::MAX + }; + if tokenizer.parse_state.constructs.code_fenced { + tokenizer.enter(Token::CodeFenced); + tokenizer.enter(Token::CodeFencedFence); + tokenizer.go(space_or_tab_min_max(0, max), before_sequence_open)(tokenizer, code) + } else { + (State::Nok, None) + } } /// Inside the opening fence, after an optional prefix, before a sequence. @@ -445,10 +453,20 @@ fn close_begin(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResu /// ^ /// ``` fn close_start(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResult { - tokenizer.enter(Token::CodeFencedFence); - tokenizer.go(space_or_tab_min_max(0, TAB_SIZE - 1), |t, c| { - close_before(t, c, info) - })(tokenizer, code) + let max = if tokenizer.parse_state.constructs.code_indented { + TAB_SIZE - 1 + } else { + usize::MAX + }; + + if tokenizer.parse_state.constructs.code_fenced { + tokenizer.enter(Token::CodeFencedFence); + tokenizer.go(space_or_tab_min_max(0, max), |t, c| { + close_before(t, c, info) + })(tokenizer, code) + } else { + (State::Nok, None) + } } /// In a closing fence, after optional whitespace, before sequence. |