Separate description list terms and details when indexing

This commit is contained in:
dualfroz committed 2026-10-02 16:23:03 +02:00
1 parent 4a2d8974bb
commit a3e68ffd4d
1 file changed
+22 -2
+22 -2
View File
@@ -21,7 +21,8 @@ lazy_static! {
} }
const SENTENCE_SELECTORS: &[&'static str] = &[ const SENTENCE_SELECTORS: &[&'static str] = &[
"h1", "h2", "h3", "h4", "h5", "h6", "p", "td", "div", "ul", "li", "article", "section", "h1", "h2", "h3", "h4", "h5", "h6", "p", "td", "div", "ul", "li", "dl", "dt", "dd", "article",
"section",
]; ];
const INLINE_SELECTORS: &[&'static str] = &[ const INLINE_SELECTORS: &[&'static str] = &[
"a", "abbr", "acronym", "b", "bdo", "big", "br", "button", "cite", "code", "dfn", "em", "i", "a", "abbr", "acronym", "b", "bdo", "big", "br", "button", "cite", "code", "dfn", "em", "i",
@@ -361,11 +362,13 @@ impl<'a> DomParser<'a> {
// Similarly, we want to separate block elements // Similarly, we want to separate block elements
// with punctuation, so that the excerpts read nicely. // with punctuation, so that the excerpts read nicely.
// (As long as it doesn't already end with, say, a . or ?) // (As long as it doesn't already end with, say, a . or ?)
// Description list terms lead into their details,
// so they get a colon instead.
if node.current_value.chars() if node.current_value.chars()
.last() .last()
.filter(|c| SENTENCE_CHARS.is_match(&c.to_string())) .filter(|c| SENTENCE_CHARS.is_match(&c.to_string()))
.is_some() { .is_some() {
node.current_value.push('.'); node.current_value.push(if tag_name == "dt" { ':' } else { '.' });
} }
node.current_value.push(' '); node.current_value.push(' ');
} }
@@ -837,6 +840,23 @@ mod tests {
) )
} }
#[test]
fn description_list_formatting() {
let data = test_parse(vec![
"<dl>",
"<dt>Morgawr</dt>",
"<dd>A sea serpent</dd>",
"<dt>Owlman:</dt>",
"<dd>A giant owl-like creature</dd>",
"</dl>",
]);
assert_eq!(
data.digest,
"Morgawr: A sea serpent. Owlman: A giant owl-like creature."
)
}
#[test] #[test]
fn inline_tag_formatting() { fn inline_tag_formatting() {
let data = test_parse(vec![ let data = test_parse(vec![