From 1e4c95079cb97b2b02440b21945c6d12741a7d19 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 25 Aug 2022 13:16:45 +0200 Subject: Add support for GFM footnotes --- src/tokenizer.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'src/tokenizer.rs') diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 83514cb..c6a209b 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -28,6 +28,8 @@ pub enum Container { BlockQuote, /// [List item][crate::construct::list_item]. ListItem, + /// [GFM: Footnote definition][crate::construct::gfm_footnote_definition]. + GfmFootnoteDefinition, } /// Info used to tokenize a container. @@ -56,9 +58,53 @@ enum ByteAction { Insert(u8), } +/// Label start kind. +#[derive(Debug, PartialEq, Eq)] +pub enum LabelKind { + /// Label (image) start. + /// + /// ```markdown + /// > | a ![b] c + /// ^^ + /// ``` + /// + /// Construct: [Label start (image)][crate::construct::label_start_image]. + Image, + /// Label (image) link. + /// + /// ```markdown + /// > | a [b] c + /// ^ + /// ``` + /// + /// Construct: [Label start (link)][crate::construct::label_start_link]. + Link, + /// GFM: Label (footnote) link. + /// + /// ```markdown + /// > | a [^b] c + /// ^^ + /// ``` + /// + /// Construct: [GFM: Label start (footnote)][crate::construct::gfm_label_start_footnote]. + GfmFootnote, + /// GFM: Label (footnote) link, not matching a footnote definition, so + /// handled as a label (link) start. + /// + /// ```markdown + /// > | a [^b](c) d + /// ^^ + /// ``` + /// + /// Construct: [Label end][crate::construct::label_end]. + GfmUndefinedFootnote, +} + /// Label start, looking for an end. #[derive(Debug)] pub struct LabelStart { + /// Kind of start. + pub kind: LabelKind, /// Indices of where the label starts and ends in `events`. pub start: (usize, usize), /// A boolean used internally to figure out if a (link) label start can’t @@ -71,6 +117,7 @@ pub struct LabelStart { /// Valid label. #[derive(Debug)] pub struct Label { + pub kind: LabelKind, /// Indices of label start. pub start: (usize, usize), /// Indices of label end. @@ -174,8 +221,10 @@ pub struct TokenizeState<'a> { /// Used when tokenizing [text content][crate::construct::text]. pub labels: Vec