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
use super::TagHandler;
use super::StructuredPrinter;
use markup5ever_rcdom::{Handle,NodeData};
#[derive(Default)]
pub struct ParagraphHandler {
paragraph_type: String
}
impl TagHandler for ParagraphHandler {
fn handle(&mut self, tag: &Handle, printer: &mut StructuredPrinter) {
self.paragraph_type = match tag.data {
NodeData::Element { ref name, .. } => name.local.to_string(),
_ => String::new()
};
match self.paragraph_type.as_ref() {
"p" => { printer.insert_newline(); printer.insert_newline(); }
_ => {}
}
}
fn after_handle(&mut self, printer: &mut StructuredPrinter) {
match self.paragraph_type.as_ref() {
"p" => { printer.insert_newline(); printer.insert_newline(); }
"hr" => { printer.insert_newline(); printer.append_str("---"); printer.insert_newline(); }
"br" => printer.append_str(" \n"),
_ => {}
}
}
}