diff --git a/src/message/html.rs b/src/message/html.rs
index d2b40ae3..f6428057 100644
--- a/src/message/html.rs
+++ b/src/message/html.rs
@@ -41,6 +41,7 @@ use crate::{
util::{join_cell_text, space_text},
};
+const CODE_BACKGROUND: Color = Color::Indexed(236);
const QUOTE_COLOR: Color = Color::Indexed(236);
/// Generate bullet points from a [ListStyle].
@@ -97,12 +98,14 @@ impl ListStyle {
pub type StyleTreeChildren = Vec;
/// Type of contents in a table cell.
+#[derive(Debug)]
pub enum CellType {
Data,
Header,
}
/// A collection of cells for a single row in a table.
+#[derive(Debug)]
pub struct TableRow {
cells: Vec<(CellType, StyleTreeNode)>,
}
@@ -120,6 +123,7 @@ impl TableRow {
}
/// A collection of rows in a table.
+#[derive(Debug)]
pub struct TableSection {
rows: Vec,
}
@@ -137,6 +141,7 @@ impl TableSection {
}
/// A table.
+#[derive(Debug)]
pub struct Table {
caption: Option>,
sections: Vec,
@@ -266,6 +271,7 @@ impl Table {
}
/// A processed HTML element that we can render to the terminal.
+#[derive(Debug)]
pub enum StyleTreeNode {
Anchor(Box, char, Url),
Blockquote(Box),
@@ -365,7 +371,10 @@ impl StyleTreeNode {
}
},
StyleTreeNode::Code(child, _) => {
+ let style = style.bg(CODE_BACKGROUND);
+ let old = printer.set_base_style(style);
child.print(printer, style);
+ printer.set_base_style(old);
},
StyleTreeNode::Header(child, level) => {
let style = style.add_modifier(StyleModifier::BOLD);
@@ -1442,6 +1451,7 @@ pub mod tests {
);
let tree = parse_matrix_html(s);
let text = tree.to_text(25, Style::default(), true, &settings);
+ let code_style = Style::new().bg(CODE_BACKGROUND);
assert_eq!(text.lines.len(), 6);
assert_eq!(
text.lines[0],
@@ -1455,19 +1465,19 @@ pub mod tests {
text.lines[1],
Line::from(vec![
Span::raw(line::VERTICAL),
- Span::raw("fn"),
- Span::raw(" "),
- Span::raw("hello"),
- Span::raw("("),
- Span::raw(")"),
- Span::raw(" "),
- Span::raw("-"),
- Span::raw(">"),
- Span::raw(" "),
- Span::raw("usize"),
- Span::raw(" "),
- Span::raw("{"),
- Span::raw(" "),
+ Span::styled("fn", code_style),
+ Span::styled(" ", code_style),
+ Span::styled("hello", code_style),
+ Span::styled("(", code_style),
+ Span::styled(")", code_style),
+ Span::styled(" ", code_style),
+ Span::styled("-", code_style),
+ Span::styled(">", code_style),
+ Span::styled(" ", code_style),
+ Span::styled("usize", code_style),
+ Span::styled(" ", code_style),
+ Span::styled("{", code_style),
+ Span::styled(" ", code_style),
Span::raw(line::VERTICAL)
])
);
@@ -1475,13 +1485,13 @@ pub mod tests {
text.lines[2],
Line::from(vec![
Span::raw(line::VERTICAL),
- Span::raw(" "),
- Span::raw(" "),
- Span::raw("/"),
- Span::raw("/"),
- Span::raw(" "),
- Span::raw("weired"),
- Span::raw(" "),
+ Span::styled(" ", code_style),
+ Span::styled(" ", code_style),
+ Span::styled("/", code_style),
+ Span::styled("/", code_style),
+ Span::styled(" ", code_style),
+ Span::styled("weired", code_style),
+ Span::styled(" ", code_style),
Span::raw(line::VERTICAL)
])
);
@@ -1489,12 +1499,12 @@ pub mod tests {
text.lines[3],
Line::from(vec![
Span::raw(line::VERTICAL),
- Span::raw(" "),
- Span::raw("return"),
- Span::raw(" "),
- Span::raw("5"),
- Span::raw(";"),
- Span::raw(" "),
+ Span::styled(" ", code_style),
+ Span::styled("return", code_style),
+ Span::styled(" ", code_style),
+ Span::styled("5", code_style),
+ Span::styled(";", code_style),
+ Span::styled(" ", code_style),
Span::raw(line::VERTICAL)
])
);
@@ -1502,8 +1512,8 @@ pub mod tests {
text.lines[4],
Line::from(vec![
Span::raw(line::VERTICAL),
- Span::raw("}"),
- Span::raw(" ".repeat(22)),
+ Span::styled("}", code_style),
+ Span::styled(" ".repeat(22), code_style),
Span::raw(line::VERTICAL)
])
);
diff --git a/src/message/printer.rs b/src/message/printer.rs
index 34187521..2c31bbbf 100644
--- a/src/message/printer.rs
+++ b/src/message/printer.rs
@@ -92,6 +92,11 @@ impl<'a> TextPrinter<'a> {
self.width
}
+ /// Sets the base style and returns the old style
+ pub fn set_base_style(&mut self, new: Style) -> Style {
+ std::mem::replace(&mut self.base_style, new)
+ }
+
/// Create a new printer with a smaller width.
pub fn sub(&self, indent: usize) -> Self {
TextPrinter {