11/**
22 * Utility function for escaping content in different modes
33 * @param unsafe The string to escape
4- * @param mode The escaping mode: "disabled", "normal", or "strict "
4+ * @param mode The escaping mode: "disabled", "normal", "strict", or "veryStrict "
55 * @returns The escaped string
66 * @throws Error if input is null or undefined
7+ *
8+ * Modes:
9+ * - disabled: No escaping applied
10+ * - normal: Basic escaping for Templater and Dataview compatibility
11+ * - strict: Remove potentially dangerous HTML/JS characters (preserves Unicode)
12+ * - veryStrict: Remove more special characters (preserves Unicode but more restrictive)
713 */
814export function escapeBody (
915 unsafe : string ,
@@ -18,15 +24,19 @@ export function escapeBody(
1824 }
1925
2026 if ( mode === "strict" ) {
21- // Allow alphanumeric, whitespace, common punctuation, and URL/Markdown specific characters
27+ // Allow Unicode characters, whitespace, common punctuation, and URL/Markdown specific characters
28+ // Remove potentially dangerous characters while preserving Chinese and other Unicode characters
2229 return unsafe
23- . replace ( / [ ^ a - z A - Z 0 - 9 \s . , ( ) \[ \] * + \- : " # ! ' ? & | * > ~ ^ \/ : ? = & % # _ ] / g, "" )
24- . replace ( / - - - / g, "- - -" ) ;
30+ . replace ( / [ < > { } $ ` \\ ] / g, "" ) // Remove potentially dangerous HTML/JS/template characters
31+ . replace ( / - - - / g, "- - -" ) ; // Escape YAML frontmatter separators
2532 }
2633
2734 if ( mode === "veryStrict" ) {
28- // Allow alphanumeric, whitespace, basic punctuation, and essential URL/Markdown image characters
29- return unsafe . replace ( / [ ^ a - z A - Z 0 - 9 \s . , ? ! \[ \] ( ) : \/ . \- ] / g, "" ) ;
35+ // Allow Unicode characters, whitespace, basic punctuation, and essential URL/Markdown characters
36+ // More restrictive than strict mode but still preserves Chinese and other Unicode characters
37+ return unsafe
38+ . replace ( / [ < > { } $ ` \\ " ' | & * ~ ^ ] / g, "" ) // Remove more potentially dangerous characters
39+ . replace ( / - - - / g, "- - -" ) ; // Escape YAML frontmatter separators
3040 }
3141
3242 // normal mode
0 commit comments