markdown/
resolve.rs

1//! Resolve events.
2
3use crate::construct;
4use crate::message;
5use crate::subtokenize::Subresult;
6use crate::tokenizer::Tokenizer;
7
8/// Names of resolvers.
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
10pub enum Name {
11    /// Resolve labels.
12    ///
13    /// Labels are parsed as starts and ends, and when they match, merged
14    /// together to form media (links and images), and otherwise turned into
15    /// data.
16    Label,
17    /// Resolve attention.
18    ///
19    /// Attention sequences are parsed and finally matched together to form
20    /// attention (emphasis and strong) based on which characters they contain,
21    /// and what occurs before and after each sequence.
22    /// Otherwise they are turned into data.
23    Attention,
24    /// Resolve GFM tables.
25    ///
26    /// The table head, and later each row, are all parsed separately.
27    /// Resolving groups everything together, and groups cells.
28    GfmTable,
29    /// Resolve heading (atx).
30    ///
31    /// Heading (atx) contains further sequences and data.
32    /// At the end, a final sequence is kept that way, while the rest is merged
33    /// with the data.
34    HeadingAtx,
35    /// Resolve heading (setext).
36    ///
37    /// Heading (setext) is parsed as an underline that is preceded by content,
38    /// both will form the whole construct.
39    HeadingSetext,
40    /// Resolve list item.
41    ///
42    /// List items are parsed on their own.
43    /// They are wrapped into ordered or unordered lists based on whether items
44    /// with the same marker occur next to each other.
45    ListItem,
46    /// Resolve content.
47    ///
48    /// Content is parsed as single lines, as what remains if other flow
49    /// constructs don’t match.
50    /// But, when they occur next to each other, they need to be merged.
51    Content,
52    /// Resolve data.
53    ///
54    /// Data is parsed as many small bits, due to many punctuation characters
55    /// potentially starting something in particularly text content.
56    /// It helps performance to merge them together if those markers did not
57    /// match anything and hence they occur next to each other.
58    Data,
59    /// Resolve whitespace in `string`.
60    String,
61    /// Resolve whitespace in `text`.
62    Text,
63}
64
65/// Call the corresponding resolver.
66pub fn call(tokenizer: &mut Tokenizer, name: Name) -> Result<Option<Subresult>, message::Message> {
67    let result = match name {
68        Name::Label => construct::label_end::resolve(tokenizer),
69        Name::Attention => construct::attention::resolve(tokenizer),
70        Name::GfmTable => construct::gfm_table::resolve(tokenizer),
71        Name::HeadingAtx => construct::heading_atx::resolve(tokenizer),
72        Name::HeadingSetext => construct::heading_setext::resolve(tokenizer),
73        Name::ListItem => construct::list_item::resolve(tokenizer),
74        Name::Content => construct::content::resolve(tokenizer)?,
75        Name::Data => construct::partial_data::resolve(tokenizer),
76        Name::String => construct::string::resolve(tokenizer),
77        Name::Text => construct::text::resolve(tokenizer),
78    };
79
80    Ok(result)
81}