use chrono::{DateTime,Utc,Local};
use core::cmp::max;
-use std::collections::{HashMap, HashSet};
+use std::collections::{HashMap, BTreeSet};
use super::html;
use super::coloured_string::{ColouredString, ColouredStringSlice};
struct HTMLFormatter {
paras: Vec<Paragraph>,
colourstack: Vec<char>,
- bad_tags: HashSet<String>,
+ bad_tags: BTreeSet<String>, // so we report more than 1 in consistent order
indent: usize,
pre_tag: usize,
}
HTMLFormatter {
paras: vec! { Paragraph::new() },
colourstack: vec! { ' ' },
- bad_tags: HashSet::new(),
+ bad_tags: BTreeSet::new(),
indent: 0,
pre_tag: 0,
}
fn finish(mut self) -> Vec<Paragraph> {
let first_nonempty = self.paras.iter()
.position(|p| !p.is_empty()).unwrap_or(self.paras.len());
- self.paras.splice(..first_nonempty, vec![]);
+ self.paras.splice(..first_nonempty, vec!{});
while match self.paras.last() {
Some(p) => p.is_empty(),
self.paras.pop();
}
+ if !self.bad_tags.is_empty() {
+ let mut para = Paragraph::new().add(
+ &ColouredString::uniform("Unsupported markup tags:", '!'));
+ for tag in self.bad_tags.iter() {
+ para.push_text(&ColouredString::uniform(
+ &format!(" <{}>", tag), '!'), false);
+ }
+ self.paras.splice(0..0, vec!{
+ para,
+ Paragraph::new(),
+ });
+ }
+
self.paras
}
self.colourstack.push('s');
} else if tag == "em" || tag == "i" {
self.colourstack.push('_');
- } else if tag == "span" {
+ } 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_string());
ColouredString::general("URL to https://www.example.com/stuff/.",
" uuuuuuuuuuuuuuuuuuuuuuuuuuuuuu "),
});
+
+ assert_eq!(render_html("<p>Test of some <nonsense>unsupported</nonsense> <blither>HTML tags</blither></p>", 50),
+ vec! {
+ ColouredString::general("Unsupported markup tags: <blither> <nonsense>",
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"),
+ ColouredString::plain(""),
+ ColouredString::plain("Test of some unsupported HTML tags"),
+ });
}
// TODO: