",
- color_hm
- .get("background")
- .expect("Error getting background color"),
- color_hm
- .get("foreground")
- .expect("Error getting foreground color")
- ));
-
- output_string.push_str("");
-
- for header in &headers {
- output_string.push_str("");
- output_string.push_str(&htmlescape::encode_minimal(&header));
- output_string.push_str(" | ");
- }
- output_string.push_str("
");
- }
-
- for row in input {
- match row.value {
- UntaggedValue::Primitive(Primitive::Binary(b)) => {
- // This might be a bit much, but it's fun :)
- match row.tag.anchor {
- Some(AnchorLocation::Url(f)) | Some(AnchorLocation::File(f)) => {
- let extension = f.split('.').last().map(String::from);
- match extension {
- Some(s)
- if ["png", "jpg", "bmp", "gif", "tiff", "jpeg"]
- .contains(&s.to_lowercase().as_str()) =>
- {
- output_string.push_str("");
- }
- _ => {
- let output = pretty_hex::pretty_hex(&b);
-
- output_string.push_str("");
- output_string.push_str(&output);
- output_string.push_str("
");
- }
- }
- }
- _ => {
- let output = pretty_hex::pretty_hex(&b);
-
- output_string.push_str("");
- output_string.push_str(&output);
- output_string.push_str("
");
- }
- }
+ let inner_value = match input.len() {
+ 0 => String::default(),
+ 1 => match headers {
+ Some(headers) => html_table(input, headers, color_hm),
+ None => {
+ let value = &input[0];
+ html_value(value)
}
- UntaggedValue::Primitive(Primitive::String(ref b)) => {
- // This might be a bit much, but it's fun :)
- match row.tag.anchor {
- Some(AnchorLocation::Url(f)) | Some(AnchorLocation::File(f)) => {
- let extension = f.split('.').last().map(String::from);
- match extension {
- Some(s) if s.to_lowercase() == "svg" => {
- output_string.push_str("");
- continue;
- }
- _ => {}
- }
- }
- _ => {}
- }
- output_string.push_str(
- &(htmlescape::encode_minimal(&format_leaf(&row.value).plain_string(100_000))
- .replace("\n", "
")),
- );
- }
- UntaggedValue::Row(row) => {
- output_string.push_str("");
- for header in &headers {
- let data = row.get_data(header);
- output_string.push_str("");
- output_string.push_str(&format_leaf(data.borrow()).plain_string(100_000));
- output_string.push_str(" | ");
- }
- output_string.push_str("
");
- }
- p => {
- output_string.push_str(
- &(htmlescape::encode_minimal(&format_leaf(&p).plain_string(100_000))
- .replace("\n", "
")),
- );
- }
- }
- }
+ },
+ _ => match headers {
+ Some(headers) => html_table(input, headers, color_hm),
+ None => html_list(input),
+ },
+ };
- if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") {
- output_string.push_str("
");
- }
+ output_string.push_str(&inner_value);
output_string.push_str("");
// Check to see if we want to remove all color or change ansi to html colors
@@ -391,6 +300,130 @@ async fn to_html(
)))
}
+fn html_list(list: Vec