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:
@@ -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("&"),
|
||||
'<' => out.push_str("<"),
|
||||
'>' => out.push_str(">"),
|
||||
'"' => out.push_str("""),
|
||||
_ => out.push(c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user