Skip to content

Commit a872651

Browse files
authored
Merge pull request #606 from shibomb/fix/code-double-escaped
fix: Skip escaping if already escaped in the code tag.
2 parents 3a38d05 + 67a305a commit a872651

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/pages/_utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ export const escapeCodeTagsContent = (htmlString: string): string => {
239239

240240
// Get the current text and HTML inside the <code> tag
241241
const currentHtml = $(this).html() ?? "";
242+
243+
// Check if the content is already escaped by looking for common HTML entities
244+
if (
245+
currentHtml.includes("&lt;") ||
246+
currentHtml.includes("&gt;") ||
247+
currentHtml.includes("&amp;") ||
248+
currentHtml.includes("&quot;") ||
249+
currentHtml.includes("&#39;")
250+
) {
251+
return; // Already escaped, skip this <code> tag
252+
}
253+
242254
// Use he to escape HTML entities
243255
const escapedHtml = he.escape(currentHtml);
244256
// Update the <code> tag content with the escaped HTML

0 commit comments

Comments
 (0)