implement image upload

This commit is contained in:
Juergen Kunz
2025-06-24 17:16:13 +00:00
parent 90fc8bed35
commit fca3638f7f
5 changed files with 321 additions and 13 deletions

View File

@ -37,6 +37,13 @@ export class WysiwygConverters {
return '';
case 'divider':
return '<hr>';
case 'image':
const imageUrl = block.metadata?.url;
if (imageUrl) {
const altText = this.escapeHtml(block.content || 'Image');
return `<img src="${imageUrl}" alt="${altText}" />`;
}
return '';
default:
return `<p>${content}</p>`;
}
@ -67,6 +74,10 @@ export class WysiwygConverters {
}
case 'divider':
return '---';
case 'image':
const imageUrl = block.metadata?.url;
const altText = block.content || 'Image';
return imageUrl ? `![${altText}](${imageUrl})` : '';
default:
return block.content;
}
@ -152,6 +163,15 @@ export class WysiwygConverters {
content: ' ',
});
break;
case 'img':
const imgElement = element as HTMLImageElement;
blocks.push({
id: `block-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,
type: 'image',
content: imgElement.alt || '',
metadata: { url: imgElement.src }
});
break;
default:
// Process children for other elements
element.childNodes.forEach(child => processNode(child));
@ -237,6 +257,17 @@ export class WysiwygConverters {
type: 'divider',
content: ' ',
});
} else if (line.match(/^!\[([^\]]*)\]\(([^\)]+)\)$/)) {
// Parse markdown image syntax ![alt](url)
const match = line.match(/^!\[([^\]]*)\]\(([^\)]+)\)$/);
if (match) {
blocks.push({
id: `block-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,
type: 'image',
content: match[1] || '',
metadata: { url: match[2] }
});
}
} else if (line.trim()) {
blocks.push({
id: `block-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,