refactor: consolidate escape functions and extract weight constants

- Create escape.rs with shared html_escape, html_escape_into, xml_escape
- Remove duplicate implementations from render.rs, highlight.rs, feed.rs, sitemap.rs
- Add DEFAULT_WEIGHT (50) and DEFAULT_WEIGHT_HIGH (99) constants to content.rs
- Replace all magic number weight defaults with named constants

No functional changes; all 67 tests pass.
This commit is contained in:
Timothy DeHerrera
2026-02-05 14:35:24 -07:00
parent 7a7dc929b1
commit 16f04eb95b
7 changed files with 84 additions and 55 deletions

View File

@@ -8,6 +8,7 @@ use std::collections::HashMap;
use std::sync::LazyLock;
use std::time::Duration;
use crate::escape::{html_escape, html_escape_into};
use ropey::RopeSlice;
use tree_house::highlighter::{Highlight, HighlightEvent, Highlighter};
use tree_house::{
@@ -624,26 +625,6 @@ fn render_html<'a>(source: &str, mut highlighter: Highlighter<'a, 'a, SukrLoader
html
}
/// Simple HTML escape for fallback.
fn html_escape(s: &str) -> String {
let mut result = String::with_capacity(s.len());
html_escape_into(&mut result, s);
result
}
/// Escape HTML characters into an existing string.
fn html_escape_into(out: &mut String, s: &str) {
for c in s.chars() {
match c {
'&' => out.push_str("&amp;"),
'<' => out.push_str("&lt;"),
'>' => out.push_str("&gt;"),
'"' => out.push_str("&quot;"),
_ => out.push(c),
}
}
}
#[cfg(test)]
mod tests {
use super::*;