Skip to content

Commit

Permalink
Merge pull request #197 from jugglerchris/bugfix_196_extra_lines
Browse files Browse the repository at this point in the history
Remove redundant extra line before lists.
  • Loading branch information
jugglerchris authored Jan 26, 2025
2 parents 2a5a693 + 7ea265e commit 658d5d6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ unicode-width = "0.2"
backtrace = { version = "0.3", optional=true }
thiserror = "2.0.0"
log = { version = "0.4.20", optional = true }
nom = "7.1.3"
nom = { version = "7.1.3", optional = true }

[features]
html_trace = ["dep:log"]
html_trace_bt = ["html_trace", "dep:backtrace"]
default = []
css = []
css = [ "dep:nom" ]
css_ext = ["css"]

[[example]]
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1981,8 +1981,6 @@ fn do_render_node<T: Write, D: TextDecorator>(
})
}
Ul(items) => {
renderer.start_block()?;

let prefix = renderer.unordered_item_prefix();
let prefix_len = prefix.len();

Expand Down Expand Up @@ -2013,8 +2011,6 @@ fn do_render_node<T: Write, D: TextDecorator>(
}
}
Ol(start, items) => {
renderer.start_block()?;

let num_items = items.len();

// The prefix width could be at either end if the start is negative.
Expand Down
27 changes: 27 additions & 0 deletions src/render/text_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,33 @@ impl<D: TextDecorator> std::fmt::Debug for SubRenderer<D> {
}
}

impl<D: TextDecorator> std::fmt::Display for SubRenderer<D> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "SubRenderer(width={})", self.width)?;
writeln!(f, " Lines: {}", self.lines.len())?;
for line in &self.lines {
match line {
RenderLine::Text(tagged_line) => {
writeln!(f, " {}", tagged_line.to_string())?;
}
RenderLine::Line(_) => {
writeln!(f, " <<<border>>>")?;
}
}
}
if let Some(wrapping) = &self.wrapping {
writeln!(f, " WrappedBlock text:")?;
for line in &wrapping.text {
writeln!(f, " {}", line.to_string())?;
}
writeln!(f, " WrappedBlock cur line:")?;
writeln!(f, " {}", wrapping.line.to_string())?;
writeln!(f, " WrappedBlock Word: [[{}]]", wrapping.word.to_string())?;
}
writeln!(f)
}
}

/// Rendering options.
#[derive(Clone)]
#[non_exhaustive]
Expand Down
58 changes: 52 additions & 6 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ bit of
text to
wrap
* This is a
bit of
text to
Expand All @@ -803,16 +802,13 @@ fn test_wrap_max2() {
</li></ul>"#,
r#"plain para at the
full screen width
* bullet point uses
same width so its
margin is 2 chars
further right
* nested bullets in
turn move 2 chars
right each time
* result: you never
get text squashed
too narrow
Expand All @@ -822,6 +818,58 @@ full screen width
);
}

#[test]
fn test_nested_ul() {
test_html(
br"
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>SubItem 2.1</li>
<li>SubItem 2.2
<ul>
<li>Sub Item 2.2.1</li>
</ul>
</li>
</ul>
</ul>",
r#"* Item 1
* Item 2
* SubItem 2.1
* SubItem 2.2
* Sub Item 2.2.1
"#,
80,
);
}

#[test]
fn test_nested_ol() {
test_html(
br"
<ol>
<li>Item 1</li>
<li>Item 2
<ol>
<li>SubItem 2.1</li>
<li>SubItem 2.2
<ol>
<li>Sub Item 2.2.1</li>
</ol>
</li>
</ol>
</ol>",
r#"1. Item 1
2. Item 2
1. SubItem 2.1
2. SubItem 2.2
1. Sub Item 2.2.1
"#,
80,
);
}

#[test]
fn test_wrap_word_boundaries() {
test_html(br#"Hello there boo"#, "Hello there boo\n", 20);
Expand Down Expand Up @@ -917,7 +965,6 @@ fn test_subblock() {
</ul></div>
</div>"#,
r"Here's a [link][1].
* Bullet
* Bullet
* Bullet
Expand Down Expand Up @@ -1295,7 +1342,6 @@ fn test_trivial_decorator() {
</ul></div>
</div>"#,
r"Here's a link.
Bullet
Bullet
Bullet
Expand Down

0 comments on commit 658d5d6

Please sign in to comment.