diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-11 19:49:34 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-11 19:49:34 +0200 |
commit | 2ce19d9fd8f75ee1e3d62762e91f5d18303d4d6b (patch) | |
tree | ad2aa2dc2c96b9de278f6fd5252f1b511c1e07a4 /src/construct/code_fenced.rs | |
parent | b7bd2b734fae09c40d738fcd57d5ee6876f0f504 (diff) | |
download | markdown-rs-2ce19d9fd8f75ee1e3d62762e91f5d18303d4d6b.tar.gz markdown-rs-2ce19d9fd8f75ee1e3d62762e91f5d18303d4d6b.tar.bz2 markdown-rs-2ce19d9fd8f75ee1e3d62762e91f5d18303d4d6b.zip |
Add support for lazy lines
Diffstat (limited to '')
-rw-r--r-- | src/construct/code_fenced.rs | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/construct/code_fenced.rs b/src/construct/code_fenced.rs index c7b2334..18beb92 100644 --- a/src/construct/code_fenced.rs +++ b/src/construct/code_fenced.rs @@ -102,7 +102,10 @@ //! [html-code]: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-code-element use crate::constant::{CODE_FENCED_SEQUENCE_SIZE_MIN, TAB_SIZE}; -use crate::construct::partial_space_or_tab::{space_or_tab, space_or_tab_min_max}; +use crate::construct::{ + partial_non_lazy_continuation::start as partial_non_lazy_continuation, + partial_space_or_tab::{space_or_tab, space_or_tab_min_max}, +}; use crate::token::Token; use crate::tokenizer::{Code, ContentType, State, StateFnResult, Tokenizer}; use crate::util::span::from_exit_event; @@ -376,22 +379,35 @@ fn meta(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResult { fn at_break(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResult { let clone = info.clone(); - match code { - Code::None => after(tokenizer, code, info), - Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => tokenizer.attempt( - |t, c| close_begin(t, c, info), - |ok| { - if ok { - Box::new(|t, c| after(t, c, clone)) - } else { - Box::new(|t, c| content_before(t, c, clone)) - } - }, - )(tokenizer, code), - _ => unreachable!("expected eof/eol"), + if tokenizer.lazy { + after(tokenizer, code, info) + } else { + tokenizer.check(partial_non_lazy_continuation, |ok| { + if ok { + Box::new(move |t, c| at_non_lazy_break(t, c, clone)) + } else { + Box::new(move |t, c| after(t, c, clone)) + } + })(tokenizer, code) } } +/// To do. +fn at_non_lazy_break(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResult { + let clone = info.clone(); + + tokenizer.attempt( + |t, c| close_begin(t, c, info), + |ok| { + if ok { + Box::new(|t, c| after(t, c, clone)) + } else { + Box::new(|t, c| content_before(t, c, clone)) + } + }, + )(tokenizer, code) +} + /// Before a closing fence, at the line ending. /// /// ```markdown |