refactor: split the page, markdown pipeline and escaping out of main.rs
- assets/page/{page.html,page.css,page.js} now hold the UI. build_page only
fills __MDP_*__ placeholders, so editing the page no longer means escaping
braces inside a format! string. Output was verified byte-identical for the
home page, a math/mermaid document and the startup page.
- src/markdown.rs: md -> html pipeline (GFM, AI-output dialect, front matter,
embedded images, ==highlight==, heading ids).
- src/page.rs: page assembly.
- src/escape.rs: shared JS/HTML escaping.
- src/main.rs drops from 5535 to 3709 lines. No behavior change; 62 tests.
This commit is contained in:
25
src/escape.rs
Normal file
25
src/escape.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
//! Small text/JS escaping helpers shared by the page builder, the Markdown
|
||||
//! pipeline and the renderer.
|
||||
|
||||
pub fn escape_js(s: &str) -> String {
|
||||
s.replace('\\', "\\\\")
|
||||
.replace('\'', "\\'")
|
||||
.replace('\n', "\\n")
|
||||
.replace('\r', "\\r")
|
||||
}
|
||||
|
||||
pub fn html_escape_ta(s: &str) -> String {
|
||||
s.replace('&', "&").replace('<', "<")
|
||||
}
|
||||
|
||||
pub fn html_escape_attr(s: &str) -> String {
|
||||
s.replace('&', "&")
|
||||
.replace('"', """)
|
||||
.replace('<', "<")
|
||||
}
|
||||
|
||||
pub fn html_escape_text(s: &str) -> String {
|
||||
s.replace('&', "&")
|
||||
.replace('<', "<")
|
||||
.replace('>', ">")
|
||||
}
|
||||
Reference in New Issue
Block a user