Interpret newlines as line breaks when converting Markdown to HTML (#74)

This commit is contained in:
Ulyssa
2023-04-06 16:10:48 -07:00
parent 953be6a195
commit ad3b40d538
6 changed files with 442 additions and 42 deletions

View File

@@ -156,8 +156,13 @@ impl<'a> TextPrinter<'a> {
pub fn push_str(&mut self, s: &'a str, style: Style) {
let style = self.base_style.patch(style);
for word in UnicodeSegmentation::split_word_bounds(s) {
if self.width == 0 && word.chars().all(char::is_whitespace) {
for mut word in UnicodeSegmentation::split_word_bounds(s) {
if let "\n" | "\r\n" = word {
// Render embedded newlines as spaces.
word = " ";
}
if self.curr_width == 0 && word.chars().all(char::is_whitespace) {
// Drop leading whitespace.
continue;
}