From c2e43c7a94e54e88dd23d936de0f02fd4bef3dbf Mon Sep 17 00:00:00 2001 From: c <c@farsight.net> Date: Thu, 12 Sep 2024 14:12:00 +0200 Subject: [PATCH 1/3] test empty table inside list --- src/tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index 44e2c6c..e00deba 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -2011,6 +2011,20 @@ fn test_table_too_narrow() { from_read(tbl, 80); } +#[test] +fn test_empty_table_in_list() { + test_html( + b" +<ul> + <table> + <tr></tr> + </table> +</ul>", + "", + 80, + ); +} + #[cfg(feature = "css")] mod css_tests { use super::{test_html_coloured, test_html_css, test_html_style}; From 3c6b04c07cf2fba88be3448a81c57a9596db1a52 Mon Sep 17 00:00:00 2001 From: c <c@farsight.net> Date: Thu, 12 Sep 2024 14:12:21 +0200 Subject: [PATCH 2/3] fix panic for empty table in list --- src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 76b674e..49793d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1801,13 +1801,9 @@ fn render_table_tree<T: Write, D: TextDecorator>( .saturating_sub(1) }; - if table_width == 0 { - return Ok(TreeMapResult::Nothing); - } - renderer.start_block()?; - if renderer.options.draw_borders { + if table_width != 0 && renderer.options.draw_borders { renderer.add_horizontal_border_width(table_width)?; } From 6f4ac52e4645fba53d10251e081371b90322ed59 Mon Sep 17 00:00:00 2001 From: c <c@farsight.net> Date: Thu, 12 Sep 2024 14:18:40 +0200 Subject: [PATCH 3/3] fix warnings and clippy --- examples/html2term.rs | 5 ----- src/css/parser.rs | 2 +- src/markup5ever_rcdom.rs | 1 - src/render/text_renderer.rs | 2 +- src/tests.rs | 4 ++-- 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/examples/html2term.rs b/examples/html2term.rs index 92e8a91..8df19bd 100644 --- a/examples/html2term.rs +++ b/examples/html2term.rs @@ -1,14 +1,9 @@ #[cfg(unix)] extern crate argparse; #[cfg(unix)] -extern crate termion; -#[cfg(unix)] extern crate unicode_width; #[cfg(unix)] mod top { - use ::html2text; - use ::std; - use ::termion; use argparse::{ArgumentParser, Store}; use html2text::render::{RichAnnotation, TaggedLine, TaggedLineElement}; use std::collections::HashMap; diff --git a/src/css/parser.rs b/src/css/parser.rs index ba3ca06..edf39e7 100644 --- a/src/css/parser.rs +++ b/src/css/parser.rs @@ -225,7 +225,7 @@ fn ident_escape(s: &str) -> IResult<&str, char> { match chars.next() { None => { // EOF: return replacement char - Ok((&rest, '\u{fffd}')) + Ok((rest, '\u{fffd}')) } Some((i, c)) if c.is_hex_digit() => { // Option 1: up to 6 hex digits. diff --git a/src/markup5ever_rcdom.rs b/src/markup5ever_rcdom.rs index 19d726a..ff8b371 100644 --- a/src/markup5ever_rcdom.rs +++ b/src/markup5ever_rcdom.rs @@ -42,7 +42,6 @@ extern crate tendril; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{HashSet, VecDeque}; -use std::default::Default; use std::fmt; use std::io; use std::mem; diff --git a/src/render/text_renderer.rs b/src/render/text_renderer.rs index 7fa060b..74134a3 100644 --- a/src/render/text_renderer.rs +++ b/src/render/text_renderer.rs @@ -1032,7 +1032,7 @@ impl<D: TextDecorator> SubRenderer<D> { let mut result = String::new(); for line in &self.lines { result += &line.to_string(); - result.push_str("\n"); + result.push('\n'); } result } diff --git a/src/tests.rs b/src/tests.rs index e00deba..ea9f481 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1128,14 +1128,14 @@ hi .take(rpt - 3) .collect::<Vec<_>>() .concat() - + &r#"──┬──── + + r#"──┬──── hi│hi │//// │── │hi │── ──┴──── -"# + &repeat("──────────\n").take(rpt - 3).collect::<String>(); +"# + &"──────────\n".repeat(rpt - 3); test_html(html.as_bytes(), &result, 10); }