Fix script tag preservation and increase translation content limit

This commit is contained in:
Russell Ballestrini 2025-07-01 15:40:39 -04:00
parent bd09659d3b
commit 6e4770c07e

View file

@ -84,6 +84,13 @@ export function preserveSpecialContent(text) {
let preservedText = text;
// HTML code elements (most important in HTML context)
preservedText = preservedText.replace(/<script[\s\S]*?<\/script>/gi, (match) => {
const index = preservations.length;
const placeholder = `__CODE_${index}__`;
preservations.push({ type: 'CODE', content: match, placeholder });
return placeholder;
});
preservedText = preservedText.replace(/<pre[\s\S]*?<\/pre>/gi, (match) => {
const index = preservations.length;
const placeholder = `__CODE_${index}__`;
@ -238,8 +245,8 @@ export function extractPageContent() {
for (const selector of contentSelectors) {
const element = document.querySelector(selector);
if (element) {
// Get text content but preserve some structure
content = element.innerText || element.textContent;
// Get HTML content to preserve structure for translation
content = element.innerHTML;
break;
}
}
@ -259,7 +266,7 @@ export async function translateCurrentPage(targetLanguage) {
}
// Limit content length to avoid overwhelming the AI
const maxLength = 8000;
const maxLength = 15000; // Increased limit for better coverage
const contentToTranslate = pageContent.length > maxLength
? pageContent.substring(0, maxLength) + '...'
: pageContent;