diff --git a/mobile/src/components/MobileMarkdown.test.ts b/mobile/src/components/MobileMarkdown.test.ts index 41f282c01d4..52eb0e5ad2b 100644 --- a/mobile/src/components/MobileMarkdown.test.ts +++ b/mobile/src/components/MobileMarkdown.test.ts @@ -80,6 +80,9 @@ describe('parseMobileMarkdown', () => { expect(normalizeMobileMarkdownPreviewHtml('

Use Array<string>

')).toBe( 'Use `Array`' ) + expect( + normalizeMobileMarkdownPreviewHtml('

Use <div>x</div>

') + ).toBe('Use `
x
`') }) it('does not replace literal code placeholder text in markdown prose', () => { diff --git a/mobile/src/components/mobile-markdown-preview-html.ts b/mobile/src/components/mobile-markdown-preview-html.ts index 5de546ded53..4c72e2cb4c3 100644 --- a/mobile/src/components/mobile-markdown-preview-html.ts +++ b/mobile/src/components/mobile-markdown-preview-html.ts @@ -50,8 +50,9 @@ function decodeHtmlEntities(value: string, preserveEscapedEntities = false): str } function stripTags(value: string): string { - return decodeHtmlEntities( - value + const { protectedText, codeSpans, placeholderPrefix } = protectMarkdownCode(value) + const stripped = decodeHtmlEntities( + protectedText .replace(//g, '') .replace(/<\/?([A-Za-z][A-Za-z0-9:-]*)(?:\s[^<>]*)?\/?>/g, (tag, name: string) => strippableHtmlTagNames.has(name.toLowerCase()) ? '' : tag @@ -61,6 +62,8 @@ function stripTags(value: string): string { .replace(/[ \t]+\n/g, '\n') .replace(/\n{3,}/g, '\n\n') .trim() + + return restoreMarkdownCode(stripped, codeSpans, placeholderPrefix) } function attrValue(tag: string, name: string): string {