small improvement AI result sanitazion

This commit is contained in:
overcuriousity 2025-07-31 19:09:37 +02:00
parent 895c476476
commit c96aa70413
3 changed files with 98788 additions and 98776 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -497,15 +497,27 @@ document.addEventListener('DOMContentLoaded', () => {
} }
function formatWorkflowSuggestion(text) { function formatWorkflowSuggestion(text) {
// Type safety: ensure text is a string
if (!text || typeof text !== 'string') {
console.warn('[FORMAT] Invalid text input:', typeof text, text);
return `<p style="margin: 0; line-height: 1.6; color: var(--color-text);">Inhalt nicht verfügbar</p>`;
}
// Sanitize and trim the text
const cleanText = text.trim();
if (cleanText.length === 0) {
return `<p style="margin: 0; line-height: 1.6; color: var(--color-text);">Keine Informationen verfügbar</p>`;
}
// Improved handling for different list formats // Improved handling for different list formats
const numberedListPattern = /(\d+\.\s)/g; const numberedListPattern = /(\d+\.\s)/g;
if (numberedListPattern.test(text)) { if (numberedListPattern.test(cleanText)) {
const items = text.split(/\d+\.\s/).filter(item => item.trim().length > 0); const items = cleanText.split(/\d+\.\s/).filter(item => item.trim().length > 0);
if (items.length > 1) { if (items.length > 1) {
const listItems = items.map(item => const listItems = items.map(item =>
`<li style="margin-bottom: 0.5rem; line-height: 1.6;">${item.trim()}</li>` `<li style="margin-bottom: 0.5rem; line-height: 1.6;">${sanitizeHTML(item.trim())}</li>`
).join(''); ).join('');
return `<ol style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ol>`; return `<ol style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ol>`;
@ -514,12 +526,12 @@ document.addEventListener('DOMContentLoaded', () => {
// Handle bullet points // Handle bullet points
const bulletPattern = /^[\s]*[-\*•]\s/gm; const bulletPattern = /^[\s]*[-\*•]\s/gm;
if (bulletPattern.test(text)) { if (bulletPattern.test(cleanText)) {
const items = text.split(/^[\s]*[-\*•]\s/gm).filter(item => item.trim().length > 0); const items = cleanText.split(/^[\s]*[-\*•]\s/gm).filter(item => item.trim().length > 0);
if (items.length > 1) { if (items.length > 1) {
const listItems = items.map(item => const listItems = items.map(item =>
`<li style="margin-bottom: 0.5rem; line-height: 1.6;">${item.trim()}</li>` `<li style="margin-bottom: 0.5rem; line-height: 1.6;">${sanitizeHTML(item.trim())}</li>`
).join(''); ).join('');
return `<ul style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ul>`; return `<ul style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ul>`;
@ -527,11 +539,11 @@ document.addEventListener('DOMContentLoaded', () => {
} }
// Handle line breaks as lists // Handle line breaks as lists
if (text.includes('\n')) { if (cleanText.includes('\n')) {
const lines = text.split('\n').filter(line => line.trim().length > 0); const lines = cleanText.split('\n').filter(line => line.trim().length > 0);
if (lines.length > 1) { if (lines.length > 1) {
const listItems = lines.map(line => const listItems = lines.map(line =>
`<li style="margin-bottom: 0.5rem; line-height: 1.6;">${line.trim()}</li>` `<li style="margin-bottom: 0.5rem; line-height: 1.6;">${sanitizeHTML(line.trim())}</li>`
).join(''); ).join('');
return `<ul style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ul>`; return `<ul style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ul>`;
@ -539,7 +551,7 @@ document.addEventListener('DOMContentLoaded', () => {
} }
// Default paragraph formatting // Default paragraph formatting
return `<p style="margin: 0; line-height: 1.6; color: var(--color-text);">${text}</p>`; return `<p style="margin: 0; line-height: 1.6; color: var(--color-text);">${sanitizeHTML(cleanText)}</p>`;
} }
function renderBackgroundKnowledge(backgroundKnowledge) { function renderBackgroundKnowledge(backgroundKnowledge) {