Skip to content

Commit

Permalink
Don't add a newline if the last thing added was a newline
Browse files Browse the repository at this point in the history
  • Loading branch information
darakian committed Sep 15, 2022
1 parent 3558530 commit d144f6c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib.rs
Expand Up @@ -155,7 +155,7 @@ pub fn parse(tokens: &[Token]) -> String {
Token::BlockQuote(_, _) | Token::Newline if quote_level > 0 => {},
Token::CodeBlock(_, _) | Token::Newline | Token::Header(_, _, _) if in_paragraph => {
in_paragraph = false;
html.push_str("</p>")
html.push_str("</p>\n")
},
Token::Plaintext(_) | Token::Italic(_) | Token::Bold(_) | Token::BoldItalic(_) | Token::Strikethrough(_) if !in_paragraph => {
for _i in 0..quote_level {
Expand Down Expand Up @@ -235,7 +235,12 @@ pub fn parse(tokens: &[Token]) -> String {
}
html.push_str(format!("<li>{}</li>", sanitize_display_text(t)).as_str())
},
Token::Newline => {html.push('\n')},
Token::Newline => {
match html.chars().last() {
Some('\n') => {}
_ => html.push('\n'),
}
},
Token::Tab => {html.push('\t')},
Token::DoubleTab => {html.push_str("\t\t")},
Token::Italic(t) => {html.push_str(format!("<em>{}</em>", sanitize_display_text(t)).as_str())},
Expand Down

0 comments on commit d144f6c

Please sign in to comment.