html2md_bulletty/
headers.rs1use super::TagHandler;
2use super::StructuredPrinter;
3
4use markup5ever_rcdom::{Handle,NodeData};
5
6#[derive(Default)]
7pub struct HeaderHandler {
8 header_type: String,
9}
10
11impl TagHandler for HeaderHandler {
12
13 fn handle(&mut self, tag: &Handle, printer: &mut StructuredPrinter) {
14 self.header_type = match tag.data {
15 NodeData::Element { ref name, .. } => name.local.to_string(),
16 _ => String::new()
17 };
18
19 printer.insert_newline();
20 printer.insert_newline();
21 match self.header_type.as_ref() {
22 "h3" => printer.append_str("### "),
23 "h4" => printer.append_str("#### "),
24 "h5" => printer.append_str("##### "),
25 "h6" => printer.append_str("###### "),
26 _ => {}
27 }
28 }
29
30 fn after_handle(&mut self, printer: &mut StructuredPrinter) {
31 match self.header_type.as_ref() {
32 "h1" => printer.append_str("\n==========\n"),
33 "h2" => printer.append_str("\n----------\n"),
34 "h3" => printer.append_str(" ###\n"),
35 "h4" => printer.append_str(" ####\n"),
36 "h5" => printer.append_str(" #####\n"),
37 "h6" => printer.append_str(" ######\n"),
38 _ => {}
39 }
40 printer.insert_newline();
41 }
42}