html2md_bulletty/
paragraphs.rs

1use super::TagHandler;
2use super::StructuredPrinter;
3
4use markup5ever_rcdom::{Handle,NodeData};
5
6#[derive(Default)]
7pub struct ParagraphHandler {
8    paragraph_type: String
9}
10
11impl TagHandler for ParagraphHandler {
12
13    fn handle(&mut self, tag: &Handle, printer: &mut StructuredPrinter) {
14        self.paragraph_type = match tag.data {
15            NodeData::Element { ref name, .. } => name.local.to_string(),
16            _ => String::new()
17        };
18
19        // insert newlines at the start of paragraph
20        match self.paragraph_type.as_ref() {
21            "p" => { printer.insert_newline(); printer.insert_newline(); }
22            _ => {}
23        }
24    }
25
26    fn after_handle(&mut self, printer: &mut StructuredPrinter) {
27        // insert newlines at the end of paragraph
28        match self.paragraph_type.as_ref() {
29            "p" => { printer.insert_newline(); printer.insert_newline(); }
30            "hr" => { printer.insert_newline(); printer.append_str("---"); printer.insert_newline(); }
31            "br" => printer.append_str("  \n"),
32            _ => {}
33        }
34    }
35}