Enhance Richtext editor

This commit is contained in:
Stefan Hardegger
2025-07-24 13:15:31 +02:00
parent 131e2e8c25
commit aae6091ef4
2 changed files with 51 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
import { useState, useRef, useEffect } from 'react';
import { Textarea } from '../ui/Input';
import Button from '../ui/Button';
import { sanitizeHtmlSync, preloadSanitizationConfig } from '../../lib/sanitization';
import { sanitizeHtmlSync } from '../../lib/sanitization';
interface RichTextEditorProps {
value: string;
@@ -25,7 +25,11 @@ export default function RichTextEditor({
// Preload sanitization config
useEffect(() => {
preloadSanitizationConfig().catch(console.error);
// Clear cache and reload config to get latest sanitization rules
import('../../lib/sanitization').then(({ clearSanitizationCache, preloadSanitizationConfig }) => {
clearSanitizationCache();
preloadSanitizationConfig().catch(console.error);
});
}, []);
const handleVisualChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
@@ -109,7 +113,15 @@ export default function RichTextEditor({
console.log('Raw HTML:', htmlContent.substring(0, 500));
const sanitizedHtml = sanitizeHtmlSync(htmlContent);
console.log('Sanitized HTML:', sanitizedHtml.substring(0, 500));
console.log('Sanitized HTML length:', sanitizedHtml.length);
console.log('Sanitized HTML preview:', sanitizedHtml.substring(0, 500));
// Check if sanitization removed too much content
const ratio = sanitizedHtml.length / htmlContent.length;
console.log('Sanitization ratio (kept/original):', ratio.toFixed(3));
if (ratio < 0.1) {
console.warn('Sanitization removed >90% of content - this might be too aggressive');
}
// Insert at cursor position instead of just appending
const textarea = visualTextareaRef.current;