summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-06-18 05:50:15 +0200
committerCyborus <cyborus@cyborus.xyz>2024-06-18 05:50:15 +0200
commitd060a73cde1aa27e59f59554d9e94b5209acafd2 (patch)
treeaaa403d9e21ad72c3f7bf9619917c2e0af7089ce
parentMerge pull request 'add more success messages' (#78) from success-msg into main (diff)
downloadforgejo-cli-d060a73cde1aa27e59f59554d9e94b5209acafd2.tar.xz
forgejo-cli-d060a73cde1aa27e59f59554d9e94b5209acafd2.zip
fix(markdown): trailing paragraph newlines
-rw-r--r--src/main.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index ff20789..f33d71b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -357,14 +357,17 @@ fn markdown(text: &str) -> String {
ansi_printer.pause_style();
ansi_printer.prefix();
ansi_printer.resume_style();
- for (item, side) in render_queue {
+ let mut iter = render_queue.into_iter().peekable();
+ while let Some((item, side)) = iter.next() {
use comrak::nodes::NodeValue;
use Side::*;
match (&item.data.borrow().value, side) {
(NodeValue::Paragraph, Start) => (),
(NodeValue::Paragraph, End) => {
- ansi_printer.newline();
- ansi_printer.newline();
+ if iter.peek().is_some_and(|(_, side)| *side == Start) {
+ ansi_printer.newline();
+ ansi_printer.newline();
+ }
}
(NodeValue::Text(s), Start) => ansi_printer.text(s),
(NodeValue::Link(_), Start) => {
@@ -439,6 +442,7 @@ fn markdown(text: &str) -> String {
(NodeValue::Heading(_), End) => {
ansi_printer.reset();
ansi_printer.newline();
+ ansi_printer.newline();
}
(NodeValue::List(list), Start) => {
@@ -450,6 +454,7 @@ fn markdown(text: &str) -> String {
if list.list_type == comrak::nodes::ListType::Ordered {
list_numbers.pop();
}
+ ansi_printer.newline();
}
(NodeValue::Item(list), Start) => {
if list.list_type == comrak::nodes::ListType::Ordered {
@@ -467,6 +472,9 @@ fn markdown(text: &str) -> String {
ansi_printer.cur_line_len += 2;
}
}
+ (NodeValue::Item(_), End) => {
+ ansi_printer.newline();
+ }
(NodeValue::LineBreak, Start) => ansi_printer.newline(),
(NodeValue::SoftBreak, Start) => ansi_printer.newline(),