(
if !href.is_empty() {
dehtml.last_href = Some(href);
- dehtml.strbuilder += "[";
+ *dehtml.get_buf() += "[";
}
}
}
"b" | "strong" => {
if dehtml.get_add_text() != AddText::No {
- dehtml.strbuilder += "*";
+ *dehtml.get_buf() += "*";
}
}
"i" | "em" => {
if dehtml.get_add_text() != AddText::No {
- dehtml.strbuilder += "_";
+ *dehtml.get_buf() += "_";
}
}
"blockquote" => dehtml.blockquotes_since_blockquote += 1,
@@ -319,7 +372,6 @@ pub fn dehtml_manually(buf: &str) -> String {
#[cfg(test)]
mod tests {
use super::*;
- use crate::simplify::{simplify, SimplifiedText};
#[test]
fn test_dehtml() {
@@ -333,18 +385,18 @@ mod tests {
(" bar foo", "* bar _ foo"),
("& bar", "& bar"),
// Despite missing ', this should be shown:
- ("", "No link: "),
+ ("", "No link:"),
(
"No link: ",
- "No link: ",
+ "No link:",
),
("\nfat text", "*fat text*"),
// Invalid html (at least DC should show the text if the html is invalid):
("\nsome text", "some text"),
];
for (input, output) in cases {
- assert_eq!(simplify(dehtml(input).unwrap(), true).text, output);
+ assert_eq!(dehtml(input).unwrap().text, output);
}
let none_cases = vec![" ", ""];
for input in none_cases {
@@ -354,31 +406,54 @@ mod tests {
#[test]
fn test_dehtml_parse_br() {
- let html = "\r\r\nline1
\r\n\r\n\r\rline2
line3\n\r";
- let plain = dehtml(html).unwrap();
+ let html = "line1
line2";
+ let plain = dehtml(html).unwrap().text;
+ assert_eq!(plain, "line1\nline2");
- assert_eq!(plain, "line1\n\r\r\rline2\nline3");
+ let html = "line1
line2";
+ let plain = dehtml(html).unwrap().text;
+ assert_eq!(plain, "line1\nline2");
+
+ let html = "line1
line2";
+ let plain = dehtml(html).unwrap().text;
+ assert_eq!(plain, "line1\n\nline2");
+
+ let html = "\r\r\nline1
\r\n\r\n\r\rline2
line3\n\r";
+ let plain = dehtml(html).unwrap().text;
+ assert_eq!(plain, "line1\nline2\nline3");
+ }
+
+ #[test]
+ fn test_dehtml_parse_span() {
+ assert_eq!(dehtml("Foobar").unwrap().text, "Foobar");
+ assert_eq!(dehtml("Foo bar").unwrap().text, "Foo bar");
+ assert_eq!(dehtml("Foo bar").unwrap().text, "Foo bar");
+ assert_eq!(dehtml("Foo\nbar").unwrap().text, "Foo bar");
+ assert_eq!(dehtml("\nFoo bar").unwrap().text, "Foo bar");
+ assert_eq!(dehtml("Foo\n\nbar").unwrap().text, "Foo bar");
+ assert_eq!(dehtml("Foo\nbar").unwrap().text, "Foo bar");
+ assert_eq!(dehtml("Foo\nbar").unwrap().text, "Foo bar");
}
#[test]
fn test_dehtml_parse_p() {
let html = "Foo
Bar
";
- let plain = dehtml(html).unwrap();
+ let plain = dehtml(html).unwrap().text;
assert_eq!(plain, "Foo\n\nBar");
let html = "Foo
Bar";
- let plain = dehtml(html).unwrap();
+ let plain = dehtml(html).unwrap().text;
assert_eq!(plain, "Foo\n\nBar");
let html = "
Foo
Bar
Baz";
- let plain = dehtml(html).unwrap();
+ let plain = dehtml(html).unwrap().text;
assert_eq!(plain, "Foo\n\nBar\n\nBaz");
}
#[test]
fn test_dehtml_parse_href() {
let html = "text]>text bold]]>";
- let plain = dehtml(html).unwrap();
+ let plain = dehtml(html).unwrap().text;
assert_eq!(plain, "text *bold*<>");
}
@@ -396,7 +471,7 @@ mod tests {
let html =
"<>"'& äÄöÖüÜß fooÆçÇ ♦&noent;";
- let plain = dehtml(html).unwrap();
+ let plain = dehtml(html).unwrap().text;
assert_eq!(
plain,
@@ -420,32 +495,38 @@ mod tests {