From 1aff15c55de1ee6127291d9891eaf25c9fda13c2 Mon Sep 17 00:00:00 2001 From: DavHau Date: Thu, 4 Apr 2024 17:11:24 +0700 Subject: [PATCH] fix: escape html characters in name --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4015d0c..c30f336 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,12 +126,14 @@ fn build_toc(toc: &[(u32, String, String)]) -> String { for (level, name, slug) in toc { let width = 2 * (level - min_level) as usize; - writeln!(result, "{:width$}* [{name}](#{slug})", "").unwrap(); + let escaped_name = name.replace("<", "\\<").replace(">", "\\>"); + writeln!(result, "{:width$}* [{name}](#{slug})", "", name = escaped_name, width = width).unwrap(); } result } + fn add_toc(content: &str, cfg: &Config) -> Result { let mut toc_found = false;