mirror of
https://github.com/stablyai/orca.git
synced 2026-10-16 16:03:26 +00:00
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.
This commit is contained in:
@@ -80,6 +80,9 @@ describe('parseMobileMarkdown', () => {
|
||||
expect(normalizeMobileMarkdownPreviewHtml('<p>Use <code>Array<string></code></p>')).toBe(
|
||||
'Use `Array<string>`'
|
||||
)
|
||||
expect(
|
||||
normalizeMobileMarkdownPreviewHtml('<p>Use <code><div>x</div></code></p>')
|
||||
).toBe('Use `<div>x</div>`')
|
||||
})
|
||||
|
||||
it('does not replace literal code placeholder text in markdown prose', () => {
|
||||
|
||||
@@ -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(/<!--[\s\S]*?-->/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 {
|
||||
|
||||
Reference in New Issue
Block a user