')?; + let body = after_p.get(gt + 1..)?; + let close = find_ascii_ci(body, "
")?; + let text = normalize_text(&strip_tags_and_decode(body.get(..close)?)); + if text.len() < 4 || text.eq_ignore_ascii_case(title) { + return None; + } + Some(truncate_chars(&text, MAX_SUMMARY_CHARS)) +} + +fn extract_attr_value<'a>(tag: &'a str, attr_name: &str) -> Option<&'a str> { + let lower = tag.to_ascii_lowercase(); + let needle = format!("{attr_name}="); + let pos = lower.find(&needle)?; + let after = tag.get(pos + needle.len()..)?.trim_start(); + let first = after.as_bytes().first().copied()?; + if first == b'"' || first == b'\'' { + let rest = after.get(1..)?; + let end = rest.find(char::from(first))?; + rest.get(..end) + } else { + let end = after.find(|c: char| c.is_ascii_whitespace() || c == '>').unwrap_or(after.len()); + after.get(..end) + } +} + +fn strip_tags_and_decode(input: &str) -> String { + let mut no_tags = String::with_capacity(input.len()); + let mut in_tag = false; + for ch in input.chars() { + match ch { + '<' => { + in_tag = true; + no_tags.push(' '); + } + '>' => in_tag = false, + _ if !in_tag => no_tags.push(ch), + _ => {} + } + } + decode_html_entities(&no_tags) +} + +fn decode_html_entities(input: &str) -> String { + let mut out = String::with_capacity(input.len()); + let mut rest = input; + while let Some(amp) = rest.find('&') { + out.push_str(rest.get(..amp).unwrap_or("")); + let after = rest.get(amp + 1..).unwrap_or(""); + if let Some(semi) = after.find(';').filter(|&idx| idx <= 12) { + let entity = after.get(..semi).unwrap_or(""); + if let Some(ch) = decode_single_entity(entity) { + out.push(ch); + rest = after.get(semi + 1..).unwrap_or(""); + continue; + } + } + out.push('&'); + rest = after; + } + out.push_str(rest); + out +} + +fn decode_single_entity(entity: &str) -> OptionV-Notch now runs on pure Rust core with lower RAM & faster blur.
+ 12 +