diff --git a/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.test.ts b/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.test.ts index c662787c66b..6a02911344d 100644 --- a/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.test.ts +++ b/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.test.ts @@ -88,6 +88,22 @@ describe('markdownUtils', () => { ); }); + it('should escape HTML in inline code', () => { + const text = '``'; + + const html = transformMarkdownToHtml(text); + + expect(removeLineBreaks(html)).toBe( + removeLineBreaks( + unindentHtml(` +

+ <html> +

+ `) + ) + ); + }); + it('should transform unordered lists', () => { const text = '* item A\n* item B'; @@ -188,33 +204,90 @@ describe('markdownUtils', () => { ); }); - it('should transform tables', () => { - const text = '| Col A | Col B |\n| --- | --- |\n| A | B |'; + describe('tables', () => { + it('should transform tables', () => { + const text = '| Col A | Col B |\n| --- | --- |\n| A | B |'; - const html = transformMarkdownToHtml(text); + const html = transformMarkdownToHtml(text); - expect(removeLineBreaks(html)).toBe( - removeLineBreaks( - unindentHtml(` -
- - - - - - - - - - - - - -
Col ACol B
AB
-
- `) - ) - ); + expect(removeLineBreaks(html)).toBe( + removeLineBreaks( + unindentHtml(` +
+ + + + + + + + + + + + + +
Col ACol B
AB
+
+ `) + ) + ); + }); + + it('should escape HTML in table cell', () => { + const text = '| Example |\n| --- |\n| |'; + + const html = transformMarkdownToHtml(text); + + expect(removeLineBreaks(html)).toBe( + removeLineBreaks( + unindentHtml(` +
+ + + + + + + + + + + +
Example
<html>
+
`) + ) + ); + }); + + it('should keep HTML from Markdown formatting', () => { + const text = '| Example |\n| --- |\n| **bold text** |'; + + const html = transformMarkdownToHtml(text); + + expect(removeLineBreaks(html)).toBe( + removeLineBreaks( + unindentHtml(` +
+ + + + + + + + + + + +
Example
+ bold text +
+
+ `) + ) + ); + }); }); describe('headings', () => { diff --git a/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.ts b/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.ts index 4c82e199006..8659f42840a 100644 --- a/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.ts +++ b/packages/atomic/src/components/common/generated-answer/generated-content/markdown-utils.ts @@ -51,6 +51,10 @@ const customRenderer = { return `
${text}
`; }, + html(text: string) { + return escapeHtml(text); + }, + list(body: string, ordered: boolean, start: number | '') { const type = ordered ? 'ol' : 'ul'; const part = ordered ? 'answer-ordered-list' : 'answer-unordered-list';