diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-28 14:18:17 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-28 14:18:17 +0200 |
commit | dfd11b1bc155ae1fba9975a90c2dc83dc07697b4 (patch) | |
tree | 0dd150365a6ae1df4c4845518efafe02ab61cb77 /src/construct/partial_label.rs | |
parent | a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0 (diff) | |
download | markdown-rs-dfd11b1bc155ae1fba9975a90c2dc83dc07697b4.tar.gz markdown-rs-dfd11b1bc155ae1fba9975a90c2dc83dc07697b4.tar.bz2 markdown-rs-dfd11b1bc155ae1fba9975a90c2dc83dc07697b4.zip |
Fix jumps in `edit_map`
* Use resolve more often (e.g., heading (atx, setext))
* Fix to link whole phrasing (e.g., one big chunk of text in heading (atx,
setext), titles, labels)
* Replace `ChunkText`, `ChunkString`, with
`event.content_type: Option<ContentType>`
* Refactor to externalize `edit_map` from `label`
Diffstat (limited to 'src/construct/partial_label.rs')
-rw-r--r-- | src/construct/partial_label.rs | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/src/construct/partial_label.rs b/src/construct/partial_label.rs index 1cb7d4b..dd8ee84 100644 --- a/src/construct/partial_label.rs +++ b/src/construct/partial_label.rs @@ -55,10 +55,12 @@ // To do: pass token types in. +use super::partial_space_or_tab::{ + space_or_tab_one_line_ending_with_options, OneLineEndingOptions, +}; use crate::constant::LINK_REFERENCE_SIZE_MAX; -use crate::construct::partial_space_or_tab::space_or_tab; use crate::subtokenize::link; -use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer}; +use crate::tokenizer::{Code, ContentType, State, StateFnResult, TokenType, Tokenizer}; /// Configuration. /// @@ -130,8 +132,18 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> StateFnRes tokenizer.exit(info.options.label); (State::Ok, None) } + Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => tokenizer.go( + space_or_tab_one_line_ending_with_options(OneLineEndingOptions { + content_type: Some(ContentType::String), + connect: info.connect, + }), + |t, c| { + info.connect = true; + at_break(t, c, info) + }, + )(tokenizer, code), _ => { - tokenizer.enter(TokenType::ChunkString); + tokenizer.enter_with_content(TokenType::Data, Some(ContentType::String)); if info.connect { let index = tokenizer.events.len() - 1; @@ -145,30 +157,6 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> StateFnRes } } -/// After a line ending. -/// -/// ```markdown -/// [a -/// |b] -/// ``` -fn line_start(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResult { - tokenizer.attempt_opt(space_or_tab(), |t, c| line_begin(t, c, info))(tokenizer, code) -} - -/// After a line ending, after optional whitespace. -/// -/// ```markdown -/// [a -/// |b] -/// ``` -fn line_begin(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResult { - match code { - // Blank line not allowed. - Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => (State::Nok, None), - _ => at_break(tokenizer, code, info), - } -} - /// In a label, in text. /// /// ```markdown @@ -176,20 +164,14 @@ fn line_begin(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResul /// ``` fn label(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> StateFnResult { match code { - Code::None | Code::Char('[' | ']') => { - tokenizer.exit(TokenType::ChunkString); + Code::None | Code::CarriageReturnLineFeed | Code::Char('\r' | '\n' | '[' | ']') => { + tokenizer.exit(TokenType::Data); at_break(tokenizer, code, info) } _ if info.size > LINK_REFERENCE_SIZE_MAX => { - tokenizer.exit(TokenType::ChunkString); + tokenizer.exit(TokenType::Data); at_break(tokenizer, code, info) } - Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => { - tokenizer.consume(code); - info.size += 1; - tokenizer.exit(TokenType::ChunkString); - (State::Fn(Box::new(|t, c| line_start(t, c, info))), None) - } Code::VirtualSpace | Code::Char('\t' | ' ') => { tokenizer.consume(code); info.size += 1; |