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/label_start_image.rs | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/construct/label_start_image.rs (limited to 'src/construct/label_start_image.rs') diff --git a/src/construct/label_start_image.rs b/src/construct/label_start_image.rs new file mode 100644 index 0000000..2e96977 --- /dev/null +++ b/src/construct/label_start_image.rs @@ -0,0 +1,47 @@ +//! To do + +use super::label_end::resolve_media; +use crate::tokenizer::{Code, LabelStart, State, StateFnResult, TokenType, Tokenizer}; + +/// Start of label (image) start. +/// +/// ```markdown +/// a |![ b +/// ``` +pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { + match code { + Code::Char('!') => { + tokenizer.enter(TokenType::LabelImage); + tokenizer.enter(TokenType::LabelImageMarker); + tokenizer.consume(code); + tokenizer.exit(TokenType::LabelImageMarker); + (State::Fn(Box::new(open)), None) + } + _ => (State::Nok, None), + } +} + +/// After `!`, before a `[`. +/// +/// ```markdown +/// a !|[ b +/// ``` +pub fn open(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { + match code { + Code::Char('[') => { + tokenizer.enter(TokenType::LabelMarker); + tokenizer.consume(code); + tokenizer.exit(TokenType::LabelMarker); + tokenizer.exit(TokenType::LabelImage); + let end = tokenizer.events.len() - 1; + tokenizer.label_start_stack.push(LabelStart { + start: (end - 5, end), + balanced: false, + inactive: false, + }); + tokenizer.register_resolver("media".to_string(), Box::new(resolve_media)); + (State::Ok, None) + } + _ => (State::Nok, None), + } +} -- cgit