diff --git a/app/javascript/dashboard/constants/editor.js b/app/javascript/dashboard/constants/editor.js index 95ac94b69..6b1a99f23 100644 --- a/app/javascript/dashboard/constants/editor.js +++ b/app/javascript/dashboard/constants/editor.js @@ -237,8 +237,11 @@ export const MARKDOWN_PATTERNS = [ patterns: [{ pattern: /`([^`]+)`/g, replacement: '$1' }], }, { - type: 'link', // PM: link, eg: [text](url) - patterns: [{ pattern: /\[([^\]]+)\]\([^)]+\)/g, replacement: '$1' }], + type: 'link', // PM: link, eg: [text](url) or + patterns: [ + { pattern: /\[([^\]]+)\]\([^)]+\)/g, replacement: '$1' }, // [text](url) -> text + { pattern: /<(https?:\/\/[^>]+)>/g, replacement: '$1' }, // -> url (autolinks) + ], }, ]; diff --git a/app/javascript/dashboard/helper/specs/editorHelper.spec.js b/app/javascript/dashboard/helper/specs/editorHelper.spec.js index 1ae765ca7..f928b1d28 100644 --- a/app/javascript/dashboard/helper/specs/editorHelper.spec.js +++ b/app/javascript/dashboard/helper/specs/editorHelper.spec.js @@ -896,6 +896,11 @@ describe('stripUnsupportedFormatting', () => { expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content); }); + it('preserves autolinks when schema supports links', () => { + const content = 'Check out '; + expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content); + }); + it('preserves lists when schema supports them', () => { const content = '- item 1\n- item 2\n1. first\n2. second'; expect(stripUnsupportedFormatting(content, fullSchema)).toBe(content); @@ -967,6 +972,18 @@ describe('stripUnsupportedFormatting', () => { ).toBe('Check this link'); }); + it('converts autolinks to plain URLs when schema does not support links', () => { + const content = 'Visit for more info'; + const expected = 'Visit https://cegrafic.com/catalogo/ for more info'; + expect(stripUnsupportedFormatting(content, emptySchema)).toBe(expected); + }); + + it('handles multiple autolinks in content', () => { + const content = 'Check and '; + const expected = 'Check https://example.com and https://test.com'; + expect(stripUnsupportedFormatting(content, emptySchema)).toBe(expected); + }); + it('strips bullet list markers', () => { expect( stripUnsupportedFormatting('- item 1\n- item 2', emptySchema)