Commit 8eca60e89a
Unregistered key
Layout: unified · split
src/message/html.rs +39
| @@ -516,7 +516,23 @@ impl StyleTreeNode { | ||
| 516 | 516 | }, |
| 517 | 517 | StyleTreeNode::Style(child, patch) => child.print(printer, style.patch(*patch)), |
| 518 | 518 | StyleTreeNode::Sequence(children) => { |
| 519 | let mut after_quote = false; | |
| 520 | ||
| 519 | 521 | for child in children { |
| 522 | match child { | |
| 523 | // Whitespace between elements shouldn't affect spacing. | |
| 524 | StyleTreeNode::Text(text) if text.trim().is_empty() => {}, | |
| 525 | StyleTreeNode::Blockquote(_) => { | |
| 526 | if after_quote { | |
| 527 | // Keep adjacent blockquotes from visually merging. | |
| 528 | printer.commit(); | |
| 529 | printer.push_break(); | |
| 530 | } | |
| 531 | after_quote = true; | |
| 532 | }, | |
| 533 | _ => after_quote = false, | |
| 534 | } | |
| 535 | ||
| 520 | 536 | child.print(printer, style); |
| 521 | 537 | } |
| 522 | 538 | }, |
| @@ -1204,6 +1220,29 @@ pub mod tests { | ||
| 1204 | 1220 | ); |
| 1205 | 1221 | } |
| 1206 | 1222 | |
| 1223 | #[test] | |
| 1224 | fn test_blockquote_adjacent() { | |
| 1225 | let info = mock_room(); | |
| 1226 | let settings = mock_settings(); | |
| 1227 | let s = "<blockquote>\n<p>One</p>\n</blockquote>\n<blockquote>\n<p>Two</p>\n</blockquote>"; | |
| 1228 | let tree = parse_matrix_html(s); | |
| 1229 | let text = tree.to_text(10, Style::default(), &settings, &info); | |
| 1230 | let style = Style::new().fg(Color::Cyan); | |
| 1231 | let quoted = |word: &'static str, pad: &'static str| { | |
| 1232 | Line::from(vec![ | |
| 1233 | Span::raw(" "), | |
| 1234 | Span::styled(line::THICK_VERTICAL, style), | |
| 1235 | Span::raw(" "), | |
| 1236 | Span::raw(word), | |
| 1237 | Span::raw(pad), | |
| 1238 | ]) | |
| 1239 | }; | |
| 1240 | assert_eq!(text.lines.len(), 3); | |
| 1241 | assert_eq!(text.lines[0], quoted("One", " ")); | |
| 1242 | assert_eq!(text.lines[1], Line::from(vec![Span::raw(" ".repeat(10))])); | |
| 1243 | assert_eq!(text.lines[2], quoted("Two", " ")); | |
| 1244 | } | |
| 1245 | ||
| 1207 | 1246 | #[test] |
| 1208 | 1247 | fn test_list_unordered() { |
| 1209 | 1248 | let info = mock_room(); |