small improvement AI result sanitazion
This commit is contained in:
parent
895c476476
commit
c96aa70413
File diff suppressed because one or more lines are too long
197478
data/embeddings.json
197478
data/embeddings.json
File diff suppressed because it is too large
Load Diff
@ -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) {
|
|
||||||
const listItems = items.map(item =>
|
|
||||||
`<li style="margin-bottom: 0.5rem; line-height: 1.6;">${item.trim()}</li>`
|
|
||||||
).join('');
|
|
||||||
|
|
||||||
return `<ol style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ol>`;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Handle bullet points
|
// Sanitize and trim the text
|
||||||
const bulletPattern = /^[\s]*[-\*•]\s/gm;
|
const cleanText = text.trim();
|
||||||
if (bulletPattern.test(text)) {
|
if (cleanText.length === 0) {
|
||||||
const items = text.split(/^[\s]*[-\*•]\s/gm).filter(item => item.trim().length > 0);
|
return `<p style="margin: 0; line-height: 1.6; color: var(--color-text);">Keine Informationen verfügbar</p>`;
|
||||||
|
|
||||||
if (items.length > 1) {
|
|
||||||
const listItems = items.map(item =>
|
|
||||||
`<li style="margin-bottom: 0.5rem; line-height: 1.6;">${item.trim()}</li>`
|
|
||||||
).join('');
|
|
||||||
|
|
||||||
return `<ul style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ul>`;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Handle line breaks as lists
|
// Improved handling for different list formats
|
||||||
if (text.includes('\n')) {
|
const numberedListPattern = /(\d+\.\s)/g;
|
||||||
const lines = text.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;">${line.trim()}</li>`
|
|
||||||
).join('');
|
|
||||||
|
|
||||||
return `<ul style="margin: 0; padding-left: 1.5rem; color: var(--color-text);">${listItems}</ul>`;
|
if (numberedListPattern.test(cleanText)) {
|
||||||
|
const items = cleanText.split(/\d+\.\s/).filter(item => item.trim().length > 0);
|
||||||
|
|
||||||
|
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>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Default paragraph formatting
|
// Handle bullet points
|
||||||
return `<p style="margin: 0; line-height: 1.6; color: var(--color-text);">${text}</p>`;
|
const bulletPattern = /^[\s]*[-\*•]\s/gm;
|
||||||
}
|
if (bulletPattern.test(cleanText)) {
|
||||||
|
const items = cleanText.split(/^[\s]*[-\*•]\s/gm).filter(item => item.trim().length > 0);
|
||||||
|
|
||||||
|
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>`;
|
||||||
|
}
|
||||||
|
|
||||||
function renderBackgroundKnowledge(backgroundKnowledge) {
|
function renderBackgroundKnowledge(backgroundKnowledge) {
|
||||||
if (!backgroundKnowledge || backgroundKnowledge.length === 0) {
|
if (!backgroundKnowledge || backgroundKnowledge.length === 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user