impl html::Receiver for HTMLFormatter {
fn start_tag(&mut self, tag: &str, attrs: &HashMap<String, String>) {
- if tag == "a" {
- let mut colour = ' ';
- if attrs.get("href").is_some() {
- colour = 'u';
- }
- if let Some(classes) = attrs.get("class") {
- if classes.split(' ').any(|x| x == "hashtag") {
- colour = '#';
- } else if classes.split(' ').any(|x| x == "mention") {
- colour = '@';
+ match tag {
+ "a" => {
+ let mut colour = ' ';
+ if attrs.get("href").is_some() {
+ colour = 'u';
}
- }
- self.colourstack.push(colour);
- } else if tag == "p" {
- if !self.last_para().is_empty() {
- self.paras.push(Paragraph::new());
- }
- self.paras.push(self.new_para());
- } else if tag == "pre" {
- if !self.last_para().is_empty() {
- self.paras.push(Paragraph::new());
- }
- self.paras.push(self.new_para());
- self.pre_tag += 1;
- self.colourstack.push('c');
- } else if tag == "br" {
- self.paras.push(self.new_para());
- } else if tag == "blockquote" {
- self.indent += 2;
- self.paras.push(self.new_para());
- } else if tag == "code" {
- self.colourstack.push('c');
- } else if tag == "strong" {
- self.colourstack.push('s');
- } else if tag == "em" || tag == "i" {
- self.colourstack.push('_');
- } else if tag == "span" || tag == "html" || tag == "head" ||
- tag == "body" {
- // do nothing, except don't report this as an unknown tag
- } else {
- self.bad_tags.insert(tag.to_owned());
+ if let Some(classes) = attrs.get("class") {
+ if classes.split(' ').any(|x| x == "hashtag") {
+ colour = '#';
+ } else if classes.split(' ').any(|x| x == "mention") {
+ colour = '@';
+ }
+ }
+ self.colourstack.push(colour);
+ },
+ "p" => {
+ if !self.last_para().is_empty() {
+ self.paras.push(Paragraph::new());
+ }
+ self.paras.push(self.new_para());
+ },
+ "pre" => {
+ if !self.last_para().is_empty() {
+ self.paras.push(Paragraph::new());
+ }
+ self.paras.push(self.new_para());
+ self.pre_tag += 1;
+ self.colourstack.push('c');
+ },
+ "br" => self.paras.push(self.new_para()),
+ "blockquote" => {
+ self.indent += 2;
+ self.paras.push(self.new_para());
+ },
+ "code" => self.colourstack.push('c'),
+ "strong" => self.colourstack.push('s'),
+ "em" | "i" => self.colourstack.push('_'),
+
+ // do nothing, except don't report these as unknown tags
+ "span" | "html" | "head" | "body" => (),
+
+ _ => {
+ self.bad_tags.insert(tag.to_owned());
+ },
}
}
fn end_tag(&mut self, tag: &str, _attrs: &HashMap<String, String>) {
- if tag == "a" || tag == "code" || tag == "strong" || tag == "em" ||
- tag == "i" {
- self.colourstack.pop();
- } else if tag == "p" {
- if !self.last_para().is_empty() {
- self.paras.push(Paragraph::new());
- }
- } else if tag == "pre" {
- self.pre_tag -= 1;
- self.colourstack.pop();
- if !self.last_para().is_empty() {
- self.paras.push(Paragraph::new());
- }
- } else if tag == "blockquote" {
- if !self.last_para().is_empty() {
- self.paras.push(Paragraph::new());
- }
- self.indent -= 2;
- self.paras.push(self.new_para());
+ match tag {
+ "p" => {
+ if !self.last_para().is_empty() {
+ self.paras.push(Paragraph::new());
+ }
+ },
+ "pre" => {
+ self.pre_tag -= 1;
+ self.colourstack.pop();
+ if !self.last_para().is_empty() {
+ self.paras.push(Paragraph::new());
+ }
+ },
+ "blockquote" => {
+ if !self.last_para().is_empty() {
+ self.paras.push(Paragraph::new());
+ }
+ self.indent -= 2;
+ self.paras.push(self.new_para());
+ },
+ "a" | "code" | "strong" | "em" | "i" => {
+ self.colourstack.pop();
+ },
+ _ => (),
}
}
fn text(&mut self, text: &str) {