File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,9 +193,16 @@ export async function markdownToHtml(s: string): Promise<string> {
193193
194194export function sanitizeMarkdownV2 ( text : string , isInsideLink = false ) : string {
195195 // Standard MarkdownV2 characters that MUST be escaped outside of code/pre
196- let escaped = text . replace ( / ( [ _ * [ \] ( ) ~ ` > # + \- = | { } . ! \\ ] ) / g, '\\$1' ) ;
196+ // First, we unescape any existing escapes to avoid double-escaping
197+ // We keep the full list of potentially escaped characters here for robustness
198+ let unescaped = text . replace ( / \\ ( [ _ * [ \] ( ) ~ ` > # + \- = | { } . ! \\ ] ) / g, '$1' ) ;
199+
200+ // We only escape characters that are truly likely to cause parsing issues or are essential markup
201+ // Reduced list: _ * [ ] ~ ` \ |
202+ let escaped = unescaped . replace ( / ( [ _ * [ \] ~ ` \\ | ] ) / g, '\\$1' ) ;
203+
197204 if ( isInsideLink ) {
198- // Inside links, additional characters need escaping
205+ // Inside links, additional characters need escaping to avoid breaking the link syntax
199206 escaped = escaped . replace ( / ( [ ( ) ] ) / g, '\\$1' ) ;
200207 }
201208 return escaped ;
@@ -223,7 +230,7 @@ export async function markdownToMarkdownV2(s: string): Promise<string> {
223230 for ( let i = 0 ; i < items . length ; i ++ ) {
224231 const item = items [ i ] ;
225232 const prefix = ordered
226- ? `${ start !== '' && start !== undefined ? Number ( start ) + i : i + 1 } \\ . `
233+ ? `${ start !== '' && start !== undefined ? Number ( start ) + i : i + 1 } . `
227234 : '• ' ;
228235 result += `${ prefix } ${ renderer . listitem ( item ) } \n` ;
229236 }
You can’t perform that action at this time.
0 commit comments