Skip to content

Commit

Permalink
Merge pull request #606 from shibomb/fix/code-double-escaped
Browse files Browse the repository at this point in the history
fix: Skip escaping if already escaped in the code tag.
  • Loading branch information
davepagurek authored Oct 22, 2024
2 parents 3a38d05 + 67a305a commit a872651
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pages/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ export const escapeCodeTagsContent = (htmlString: string): string => {

// Get the current text and HTML inside the <code> tag
const currentHtml = $(this).html() ?? "";

// Check if the content is already escaped by looking for common HTML entities
if (
currentHtml.includes("&lt;") ||
currentHtml.includes("&gt;") ||
currentHtml.includes("&amp;") ||
currentHtml.includes("&quot;") ||
currentHtml.includes("&#39;")
) {
return; // Already escaped, skip this <code> tag
}

// Use he to escape HTML entities
const escapedHtml = he.escape(currentHtml);
// Update the <code> tag content with the escaped HTML
Expand Down

0 comments on commit a872651

Please sign in to comment.