From a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 24 Jun 2022 17:57:10 +0200 Subject: Add link, images (resource) This is still some messy code that needs cleaning up, but it adds support for links and images, of the resource kind (`[a](b)`). References (`[a][b]`) are parsed and will soon be supported, but need matching. * Fix bug to pad percent-encoded bytes when normalizing urls * Fix bug with escapes counting as balancing in destination * Add `space_or_tab_one_line_ending`, to parse whitespace including up to one line ending (but not a blank line) * Add `ParserState` to share codes, definitions, etc --- src/construct/partial_title.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/construct/partial_title.rs') diff --git a/src/construct/partial_title.rs b/src/construct/partial_title.rs index 3e61788..78ae311 100644 --- a/src/construct/partial_title.rs +++ b/src/construct/partial_title.rs @@ -32,7 +32,7 @@ //! use crate::construct::partial_space_or_tab::space_or_tab; -use crate::subtokenize::link; +use crate::subtokenize::link_to; use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer}; /// Configuration. @@ -109,7 +109,7 @@ impl Kind { #[derive(Debug)] struct Info { /// Whether we’ve seen our first `ChunkString`. - connect: bool, + connect_index: Option, /// Kind of title. kind: Kind, /// Configuration. @@ -125,9 +125,9 @@ struct Info { /// ``` pub fn start(tokenizer: &mut Tokenizer, code: Code, options: Options) -> StateFnResult { match code { - Code::Char(char) if char == '(' || char == '"' || char == '\'' => { + Code::Char(char) if char == '"' || char == '\'' || char == '(' => { let info = Info { - connect: false, + connect_index: None, kind: Kind::from_char(char), options, }; @@ -184,11 +184,11 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> StateFnRes _ => { tokenizer.enter(TokenType::ChunkString); - if info.connect { + if let Some(connect_index) = info.connect_index { let index = tokenizer.events.len() - 1; - link(&mut tokenizer.events, index); + link_to(&mut tokenizer.events, connect_index, index); } else { - info.connect = true; + info.connect_index = Some(tokenizer.events.len() - 1); } title(tokenizer, code, info) -- cgit