fix: Backslash issue with -- and improve autolink handling (#13208)

This commit is contained in:
Sivin Varghese
2026-01-12 11:22:44 +05:30
committed by GitHub
parent f5957e7970
commit a2e348df06
4 changed files with 40 additions and 8 deletions

View File

@@ -237,10 +237,11 @@ export const MARKDOWN_PATTERNS = [
patterns: [{ pattern: /`([^`]+)`/g, replacement: '$1' }], patterns: [{ pattern: /`([^`]+)`/g, replacement: '$1' }],
}, },
{ {
type: 'link', // PM: link, eg: [text](url) or <url> type: 'link', // PM: link
patterns: [ patterns: [
{ pattern: /\[([^\]]+)\]\([^)]+\)/g, replacement: '$1' }, // [text](url) -> text { pattern: /\[([^\]]+)\]\([^)]+\)/g, replacement: '$1' }, // [text](url) -> text
{ pattern: /<(https?:\/\/[^>]+)>/g, replacement: '$1' }, // <url> -> url (autolinks) { pattern: /<([a-zA-Z][a-zA-Z0-9+.-]*:[^\s>]+)>/g, replacement: '$1' }, // <https://...>, <mailto:...>, <tel:...>, <ftp://...>, etc
{ pattern: /<([^\s@]+@[^\s@>]+)>/g, replacement: '$1' }, // <user@example.com> -> user@example.com
], ],
}, },
]; ];

View File

@@ -901,6 +901,17 @@ describe('stripUnsupportedFormatting', () => {
expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content); expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content);
}); });
it('preserves various URI scheme autolinks', () => {
const content =
'Email <mailto:user@example.com> or call <tel:+1234567890>';
expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content);
});
it('preserves email autolinks', () => {
const content = 'Contact us at <support@chatwoot.com>';
expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content);
});
it('preserves lists when schema supports them', () => { it('preserves lists when schema supports them', () => {
const content = '- item 1\n- item 2\n1. first\n2. second'; const content = '- item 1\n- item 2\n1. first\n2. second';
expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content); expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content);
@@ -984,6 +995,26 @@ describe('stripUnsupportedFormatting', () => {
expect(stripUnsupportedFormatting(content, emptySchema)).toBe(expected); expect(stripUnsupportedFormatting(content, emptySchema)).toBe(expected);
}); });
it('converts URI scheme autolinks to plain text', () => {
const content =
'Email <mailto:support@example.com> or call <tel:+1234567890>';
const expected =
'Email mailto:support@example.com or call tel:+1234567890';
expect(stripUnsupportedFormatting(content, emptySchema)).toBe(expected);
});
it('converts email autolinks to plain text', () => {
const content = 'Reach us at <admin@chatwoot.com> for help';
const expected = 'Reach us at admin@chatwoot.com for help';
expect(stripUnsupportedFormatting(content, emptySchema)).toBe(expected);
});
it('handles mixed autolink types', () => {
const content = 'Visit <https://example.com> or email <info@example.com>';
const expected = 'Visit https://example.com or email info@example.com';
expect(stripUnsupportedFormatting(content, emptySchema)).toBe(expected);
});
it('strips bullet list markers', () => { it('strips bullet list markers', () => {
expect( expect(
stripUnsupportedFormatting('- item 1\n- item 2', emptySchema) stripUnsupportedFormatting('- item 1\n- item 2', emptySchema)

View File

@@ -33,7 +33,7 @@
"dependencies": { "dependencies": {
"@breezystack/lamejs": "^1.2.7", "@breezystack/lamejs": "^1.2.7",
"@chatwoot/ninja-keys": "1.2.3", "@chatwoot/ninja-keys": "1.2.3",
"@chatwoot/prosemirror-schema": "1.3.4", "@chatwoot/prosemirror-schema": "1.3.5",
"@chatwoot/utils": "^0.0.51", "@chatwoot/utils": "^0.0.51",
"@formkit/core": "^1.6.7", "@formkit/core": "^1.6.7",
"@formkit/vue": "^1.6.7", "@formkit/vue": "^1.6.7",

10
pnpm-lock.yaml generated
View File

@@ -23,8 +23,8 @@ importers:
specifier: 1.2.3 specifier: 1.2.3
version: 1.2.3 version: 1.2.3
'@chatwoot/prosemirror-schema': '@chatwoot/prosemirror-schema':
specifier: 1.3.4 specifier: 1.3.5
version: 1.3.4 version: 1.3.5
'@chatwoot/utils': '@chatwoot/utils':
specifier: ^0.0.51 specifier: ^0.0.51
version: 0.0.51 version: 0.0.51
@@ -454,8 +454,8 @@ packages:
'@chatwoot/ninja-keys@1.2.3': '@chatwoot/ninja-keys@1.2.3':
resolution: {integrity: sha512-xM8d9P5ikDMZm2WbaCTk/TW5HFauylrU3cJ75fq5je6ixKwyhl/0kZbVN/vbbZN4+AUX/OaSIn6IJbtCgIF67g==} resolution: {integrity: sha512-xM8d9P5ikDMZm2WbaCTk/TW5HFauylrU3cJ75fq5je6ixKwyhl/0kZbVN/vbbZN4+AUX/OaSIn6IJbtCgIF67g==}
'@chatwoot/prosemirror-schema@1.3.4': '@chatwoot/prosemirror-schema@1.3.5':
resolution: {integrity: sha512-XY1UyG9topVy7fNCt45YgiU/QzlJJRhrcrSWcvAIIcDYKomnEcGOyeAfM3WeFD6GgOuLzRUyIHrW+WQGpHaZvA==} resolution: {integrity: sha512-3Koj3jwO1qOxJG84D4FqPOJ6o8k6ehZi1zedO3vKRERATm2Cy1p+ET6FEvVYWUpoBvDwR6hNVScXrcNNVobhsA==}
'@chatwoot/utils@0.0.51': '@chatwoot/utils@0.0.51':
resolution: {integrity: sha512-WlEmWfOTzR7YZRUWzn5Wpm15/BRudpwqoNckph8TohyDbiim1CP4UZGa+qjajxTbNGLLhtKlm0Xl+X16+5Wceg==} resolution: {integrity: sha512-WlEmWfOTzR7YZRUWzn5Wpm15/BRudpwqoNckph8TohyDbiim1CP4UZGa+qjajxTbNGLLhtKlm0Xl+X16+5Wceg==}
@@ -4970,7 +4970,7 @@ snapshots:
hotkeys-js: 3.8.7 hotkeys-js: 3.8.7
lit: 2.2.6 lit: 2.2.6
'@chatwoot/prosemirror-schema@1.3.4': '@chatwoot/prosemirror-schema@1.3.5':
dependencies: dependencies:
markdown-it-sup: 2.0.0 markdown-it-sup: 2.0.0
prosemirror-commands: 1.6.0 prosemirror-commands: 1.6.0