import { JSX } from 'solid-js' import styles from '../styles/CodePreview.module.css' /** * Компонент для простого просмотра текста без подсветки syntax * Убирает HTML теги и показывает чистый текст */ interface TextPreviewProps extends JSX.HTMLAttributes { content: string maxHeight?: string showLineNumbers?: boolean } /** * Убирает HTML теги и декодирует HTML entity */ function stripHtmlTags(text: string): string { // Убираем HTML теги let cleaned = text.replace(/<[^>]*>/g, '') // Декодируем базовые HTML entity cleaned = cleaned .replace(/</g, '<') .replace(/>/g, '>') .replace(/&/g, '&') .replace(/"/g, '"') .replace(/'/g, "'") .replace(/ /g, ' ') return cleaned.trim() } const TextPreview = (props: TextPreviewProps) => { const cleanedContent = () => stripHtmlTags(props.content) const contentWithLines = () => { if (!props.showLineNumbers) return cleanedContent() const lines = cleanedContent().split('\n') return lines.map((line, index) => `${(index + 1).toString().padStart(3, ' ')} | ${line}`).join('\n') } return (
      {contentWithLines()}
    
) } export default TextPreview