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