Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Skip escaping if already escaped in the code tag. #606

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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