mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 12:09:33 +01:00
Merge pull request 'fix trailing paragraph newlines in markdown rendering' (#79) from trailing-newline-fix into main
Reviewed-on: https://codeberg.org/Cyborus/forgejo-cli/pulls/79
This commit is contained in:
commit
a0bab975d4
1 changed files with 11 additions and 3 deletions
10
src/main.rs
10
src/main.rs
|
@ -357,15 +357,18 @@ fn markdown(text: &str) -> String {
|
||||||
ansi_printer.pause_style();
|
ansi_printer.pause_style();
|
||||||
ansi_printer.prefix();
|
ansi_printer.prefix();
|
||||||
ansi_printer.resume_style();
|
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 comrak::nodes::NodeValue;
|
||||||
use Side::*;
|
use Side::*;
|
||||||
match (&item.data.borrow().value, side) {
|
match (&item.data.borrow().value, side) {
|
||||||
(NodeValue::Paragraph, Start) => (),
|
(NodeValue::Paragraph, Start) => (),
|
||||||
(NodeValue::Paragraph, End) => {
|
(NodeValue::Paragraph, End) => {
|
||||||
|
if iter.peek().is_some_and(|(_, side)| *side == Start) {
|
||||||
ansi_printer.newline();
|
ansi_printer.newline();
|
||||||
ansi_printer.newline();
|
ansi_printer.newline();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
(NodeValue::Text(s), Start) => ansi_printer.text(s),
|
(NodeValue::Text(s), Start) => ansi_printer.text(s),
|
||||||
(NodeValue::Link(_), Start) => {
|
(NodeValue::Link(_), Start) => {
|
||||||
ansi_printer.start_fg(bright_blue);
|
ansi_printer.start_fg(bright_blue);
|
||||||
|
@ -439,6 +442,7 @@ fn markdown(text: &str) -> String {
|
||||||
(NodeValue::Heading(_), End) => {
|
(NodeValue::Heading(_), End) => {
|
||||||
ansi_printer.reset();
|
ansi_printer.reset();
|
||||||
ansi_printer.newline();
|
ansi_printer.newline();
|
||||||
|
ansi_printer.newline();
|
||||||
}
|
}
|
||||||
|
|
||||||
(NodeValue::List(list), Start) => {
|
(NodeValue::List(list), Start) => {
|
||||||
|
@ -450,6 +454,7 @@ fn markdown(text: &str) -> String {
|
||||||
if list.list_type == comrak::nodes::ListType::Ordered {
|
if list.list_type == comrak::nodes::ListType::Ordered {
|
||||||
list_numbers.pop();
|
list_numbers.pop();
|
||||||
}
|
}
|
||||||
|
ansi_printer.newline();
|
||||||
}
|
}
|
||||||
(NodeValue::Item(list), Start) => {
|
(NodeValue::Item(list), Start) => {
|
||||||
if list.list_type == comrak::nodes::ListType::Ordered {
|
if list.list_type == comrak::nodes::ListType::Ordered {
|
||||||
|
@ -467,6 +472,9 @@ fn markdown(text: &str) -> String {
|
||||||
ansi_printer.cur_line_len += 2;
|
ansi_printer.cur_line_len += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(NodeValue::Item(_), End) => {
|
||||||
|
ansi_printer.newline();
|
||||||
|
}
|
||||||
|
|
||||||
(NodeValue::LineBreak, Start) => ansi_printer.newline(),
|
(NodeValue::LineBreak, Start) => ansi_printer.newline(),
|
||||||
(NodeValue::SoftBreak, Start) => ansi_printer.newline(),
|
(NodeValue::SoftBreak, Start) => ansi_printer.newline(),
|
||||||
|
|
Loading…
Reference in a new issue