From 6b020b71b98e360e73cce34940ca79ad92148f64 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Fri, 31 May 2024 07:22:39 +0100 Subject: [PATCH 1/3] Fix issue #155: styled table rows disappear. --- src/lib.rs | 14 ++++++++++++++ src/tests.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c42156b..7786b58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -892,6 +892,20 @@ impl<'a, C: 'a, N> TreeMapResult<'a, C, N, RenderNode> { cellinfo.content = vec![wrapped]; RenderNode::new(RenderNodeInfo::TableCell(cellinfo)) } + RenderNodeInfo::TableRow(mut row, vert) => { + let cells = row.cells; + let cells = cells + .into_iter() + .map(|mut child| { + let children = child.content; + let wrapped = RenderNode::new(f(children)); + child.content = vec![wrapped]; + child + }) + .collect(); + row.cells = cells; + RenderNode::new(RenderNodeInfo::TableRow(row, vert)) + } ni => RenderNode::new(f(vec![RenderNode::new(ni)])), } })) diff --git a/src/tests.rs b/src/tests.rs index 46a7e4d..44e2c6c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -2388,6 +2388,38 @@ Baz r#"XCDY CD +"#, + 20, + ); + } + + #[test] + fn test_colour_row() { + test_html_coloured( + br#" + + + + + + + + + + +
RowOne
RowTwo
RowThree
+ "#, + r#"───┬───── +Row│One +───┼───── +RowTwo +───┼───── +Row│Three +───┴───── "#, 20, ); From 10b84cd57010735e8f1d200d70a17d950906facd Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Fri, 31 May 2024 07:25:46 +0100 Subject: [PATCH 2/3] Remove unused functions. --- src/render/mod.rs | 6 ------ src/render/text_renderer.rs | 34 ---------------------------------- 2 files changed, 40 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 3637c18..e0955cc 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -58,9 +58,6 @@ pub(crate) trait Renderer { /// Return the current width in character cells fn width(&self) -> usize; - /// Add a line to the current block without starting a new one. - fn add_block_line(&mut self, line: &str); - /// Add a new block from a sub renderer, and prefix every line by the /// corresponding text from each iteration of prefixes. fn append_subrender<'a, I>(&mut self, other: Self, prefixes: I) -> Result<(), Error> @@ -86,9 +83,6 @@ pub(crate) trait Renderer { /// Returns true if this renderer has no content. fn empty(&self) -> bool; - /// Return the length of the contained text. - fn text_len(&self) -> usize; - /// Start a hyperlink /// TODO: return sub-builder or similar to make misuse /// of start/link harder? diff --git a/src/render/text_renderer.rs b/src/render/text_renderer.rs index 4c1cee9..43a94c8 100644 --- a/src/render/text_renderer.rs +++ b/src/render/text_renderer.rs @@ -993,22 +993,6 @@ impl SubRenderer { } } - /// Add a prerendered (multiline) string with the current annotations. - fn add_subblock(&mut self, s: &str) { - use self::TaggedLineElement::Str; - - html_trace!("add_subblock({}, {})", self.width, s); - let tag = self.ann_stack.clone(); - self.lines.extend(s.lines().map(|l| { - let mut line = TaggedLine::new(); - line.push(Str(TaggedString { - s: l.into(), - tag: tag.clone(), - })); - RenderLine::Text(line) - })); - } - /// Flushes the current wrapped block into the lines. fn flush_wrapping(&mut self) -> Result<(), Error> { if let Some(w) = self.wrapping.take() { @@ -1249,10 +1233,6 @@ impl Renderer for SubRenderer { self.width } - fn add_block_line(&mut self, line: &str) { - self.add_subblock(line); - } - fn append_subrender<'a, I>(&mut self, other: Self, prefixes: I) -> Result<(), Error> where I: Iterator, @@ -1478,20 +1458,6 @@ impl Renderer for SubRenderer { } } - fn text_len(&self) -> usize { - let mut result = 0; - for line in &self.lines { - result += match *line { - RenderLine::Text(ref tline) => tline.width(), - RenderLine::Line(_) => 0, // FIXME: should borders count? - }; - } - if let Some(ref w) = self.wrapping { - result += w.text_len(); - } - result - } - fn start_link(&mut self, target: &str) -> crate::Result<()> { let (s, annotation) = self.decorator.decorate_link_start(target); self.ann_stack.push(annotation); From 9fb380e0a69f1b9909f2dc3c8b7608a16fb714a5 Mon Sep 17 00:00:00 2001 From: Chris Emerson Date: Fri, 31 May 2024 07:30:51 +0100 Subject: [PATCH 3/3] Updates for 0.13.0-alpha.1 --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15303a9..49829eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Possible log types: - `[fixed]` for any bug fixes. - `[security]` to invite users to upgrade in case of vulnerabilities. +### 0.13.0-alpha.1 + +- [fixed] Table rows with colours would disappear. (thanks tkapias) + ### 0.13.0-alpha.0 - [changed] Replaced LightningCSS with a smaller CSS parser. There is a chance diff --git a/Cargo.toml b/Cargo.toml index 540282c..90bab61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "html2text" -version = "0.13.0-alpha.0" +version = "0.13.0-alpha.1" authors = ["Chris Emerson "] description = "Render HTML as plain text." repository = "https://github.com/jugglerchris/rust-html2text/"