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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::{MarkdownIt, Node, NodeValue, Renderer};
use crate::parser::block::{BlockRule, BlockState};
use crate::parser::inline::InlineRoot;
pub fn add(md: &mut MarkdownIt) {
md.block.add_rule::<ParagraphScanner>()
.after_all();
}
#[derive(Debug)]
pub struct Paragraph;
impl NodeValue for Paragraph {
fn render(&self, node: &Node, fmt: &mut dyn Renderer) {
fmt.cr();
fmt.open("p", &node.attrs);
fmt.contents(&node.children);
fmt.close("p");
fmt.cr();
}
}
#[doc(hidden)]
pub struct ParagraphScanner;
impl BlockRule for ParagraphScanner {
fn run(state: &mut BlockState, silent: bool) -> bool {
if silent { return false; }
let start_line = state.line;
let mut next_line = start_line;
'outer: loop {
next_line += 1;
if next_line >= state.line_max || state.is_empty(next_line) { break; }
if state.line_indent(next_line) >= 4 { continue; }
if state.line_offsets[next_line].indent_nonspace < 0 { continue; }
let old_state_line = state.line;
state.line = next_line;
if state.test_rules_at_line() {
state.line = old_state_line;
break 'outer;
}
state.line = old_state_line;
}
let (content, mapping) = state.get_lines(start_line, next_line, state.blk_indent, false);
state.line = next_line;
let mut node = Node::new(Paragraph);
node.srcmap = state.get_map(start_line, state.line - 1);
node.children.push(Node::new(InlineRoot {
content,
mapping,
}));
state.node.children.push(node);
true
}
}