mirror of
https://github.com/chatmail/core.git
synced 2026-04-02 05:22:14 +03:00
fix: preserve indentation when converting plaintext to HTML
This commit is contained in:
@@ -96,7 +96,12 @@ impl PlainText {
|
||||
line += "<br/>\n";
|
||||
}
|
||||
|
||||
ret += &*line;
|
||||
let len_with_indentation = line.len();
|
||||
let line = line.trim_start_matches(' ');
|
||||
for _ in line.len()..len_with_indentation {
|
||||
ret += " ";
|
||||
}
|
||||
ret += line;
|
||||
}
|
||||
ret += "</body></html>\n";
|
||||
ret
|
||||
@@ -267,7 +272,32 @@ line <br/>
|
||||
still line<br/>
|
||||
<em>>quote </em><br/>
|
||||
<em>>still quote</em><br/>
|
||||
>no quote<br/>
|
||||
>no quote<br/>
|
||||
</body></html>
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plain_to_html_indentation() {
|
||||
let html = PlainText {
|
||||
text: "def foo():\n pass\n\ndef bar(x):\n return x + 5".to_string(),
|
||||
flowed: false,
|
||||
delsp: false,
|
||||
}
|
||||
.to_html();
|
||||
assert_eq!(
|
||||
html,
|
||||
r#"<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
</head><body>
|
||||
def foo():<br/>
|
||||
pass<br/>
|
||||
<br/>
|
||||
def bar(x):<br/>
|
||||
return x + 5<br/>
|
||||
</body></html>
|
||||
"#
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user