import { BaseBlockHandler, type IBlockEventHandlers } from '../block.base.js'; import type { IBlock } from '../../wysiwyg.types.js'; import { cssManager } from '@design.estate/dees-element'; import { WysiwygSelection } from '../../wysiwyg.selection.js'; import hlight from 'highlight.js'; /** * New CodeBlockHandler with improved architecture * * Key improvements: * 1. Simpler DOM structure * 2. Better line number handling * 3. Non-intrusive syntax highlighting * 4. Cleaner event handling */ export class CodeBlockHandler extends BaseBlockHandler { type = 'code'; private highlightTimer: any = null; render(block: IBlock, isSelected: boolean): string { const language = block.metadata?.language || 'javascript'; const content = block.content || ''; const lineCount = content.split('\n').length; // Generate line numbers let lineNumbersHtml = ''; for (let i = 1; i <= lineCount; i++) { lineNumbersHtml += `
${this.escapeHtml(content)}