From d92bbd75b2fc9927cf969dfb2a64d4f157a5f4a6 Mon Sep 17 00:00:00 2001
From: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
Date: Fri, 26 Jun 2026 23:57:10 -0700
Subject: [PATCH] Protect code spans when stripping HTML tags in mobile preview
Ensure HTML-like content within code spans is not erroneously removed
by the tag stripping logic. We now protect markdown code blocks and
restore them after stripping tags and decoding HTML entities.
---
mobile/src/components/MobileMarkdown.test.ts | 3 +++
mobile/src/components/mobile-markdown-preview-html.ts | 7 +++++--
2 files changed, 8 insertions(+), 2 deletions(-)
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 {