1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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),
}
}
|