api: decode HTML entities in article excerpts
This commit is contained in:
parent
81439edf87
commit
571d80fa6b
1 changed files with 14 additions and 3 deletions
17
src/api.rs
17
src/api.rs
|
|
@ -249,9 +249,20 @@ fn plain_text_excerpt(html: &str, max_chars: usize) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let collapsed: String = out.split_whitespace().collect::<Vec<_>>().join(" ");
|
let collapsed: String = out.split_whitespace().collect::<Vec<_>>().join(" ");
|
||||||
if collapsed.chars().count() <= max_chars {
|
let decoded = decode_html_entities(&collapsed);
|
||||||
collapsed
|
if decoded.chars().count() <= max_chars {
|
||||||
|
decoded
|
||||||
} else {
|
} else {
|
||||||
collapsed.chars().take(max_chars).collect::<String>() + "…"
|
decoded.chars().take(max_chars).collect::<String>() + "…"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn decode_html_entities(s: &str) -> String {
|
||||||
|
s.replace("&", "&")
|
||||||
|
.replace("<", "<")
|
||||||
|
.replace(">", ">")
|
||||||
|
.replace(""", "\"")
|
||||||
|
.replace("'", "'")
|
||||||
|
.replace("'", "'")
|
||||||
|
.replace(" ", " ")
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue