diff --git a/src/pages/_utils.ts b/src/pages/_utils.ts index 4ab234a9b9..186261000d 100644 --- a/src/pages/_utils.ts +++ b/src/pages/_utils.ts @@ -239,6 +239,18 @@ export const escapeCodeTagsContent = (htmlString: string): string => { // Get the current text and HTML inside the tag const currentHtml = $(this).html() ?? ""; + + // Check if the content is already escaped by looking for common HTML entities + if ( + currentHtml.includes("<") || + currentHtml.includes(">") || + currentHtml.includes("&") || + currentHtml.includes(""") || + currentHtml.includes("'") + ) { + return; // Already escaped, skip this tag + } + // Use he to escape HTML entities const escapedHtml = he.escape(currentHtml); // Update the tag content with the escaped HTML