Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Linebreaks for blockquotes (#734)
Browse files Browse the repository at this point in the history
* remove trailing newlines when parsing blockquotes
  • Loading branch information
alunturner committed Jun 28, 2023
1 parent 2d9c28c commit 10e5ed8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ impl MarkdownHTMLParser {
}
};

// Format new lines.
// Remove any trailing newline characters from block tags
let html = html
.replace("<ul>\n", "<ul>")
.replace("</ul>\n", "</ul>")
.replace("<ol>\n", "<ol>")
.replace("</ol>\n", "</ol>")
.replace("</li>\n", "</li>")
.replace("<br />\n", "<br />");
.replace("<br />\n", "<br />")
.replace("<blockquote>\n", "<blockquote>")
.replace("</blockquote>\n", "</blockquote>")
.replace("<p>\n", "<p>")
.replace("</p>\n", "</p>");

Ok(S::try_from(html).unwrap())
}
Expand Down
19 changes: 19 additions & 0 deletions crates/wysiwyg/src/tests/test_set_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,22 @@ fn set_contents_with_line_break_in_code_block() {
let model = cm("<pre>\n<code>|Test</code></pre>");
assert_eq!(tx(&model), "<pre><code>|Test</code></pre>");
}

#[test]
fn set_content_from_markdown_blockquote() {
let mut model = cm("|");
model.set_content_from_markdown(&utf16("> quote")).unwrap();
assert_eq!(tx(&model), "<blockquote><p>quote|</p></blockquote>");
}

#[test]
fn set_content_from_markdown_blockquote_multiline() {
let mut model = cm("|");
model
.set_content_from_markdown(&utf16("> quote\n\nfollowing text"))
.unwrap();
assert_eq!(
tx(&model),
"<blockquote><p>quote</p></blockquote><p>following text|</p>"
);
}

0 comments on commit 10e5ed8

Please sign in to comment.