const { useState, useRef, useEffect } = React;
function formatMarkdown(text) {
if (!text) return '';
let html = text
.replace(/&/g, "&")
.replace(//g, ">");
// LÍNEAS DIVISORIAS ESTRUCTURADAS
html = html.replace(/^---$/gim, '
');
// ENCABEZADOS DE NIVELES CON ESTILIZADO ENTERPRISE
html = html.replace(/^### (.*$)/gim, '
$1
');
html = html.replace(/^## (.*$)/gim, '
$1
');
html = html.replace(/^# (.*$)/gim, '
$1
');
// NEGRITAS Y CURSIVAS
html = html.replace(/\*\*(.*?)\*\*/g, '$1');
html = html.replace(/\*(.*?)\*/g, '$1');
// ENCABEZADOS DE DOCUMENTOS LEGALES (PARA, DE, FECHA, ASUNTO)
html = html.replace(/\b(Para|De|Fecha|Asunto):\s*(.*$)/gim, '
$1$2
');
// TABLAS MARKDOWN ELEGANTES
if (html.includes('|')) {
const lines = html.split('\n');
let inTable = false;
let tableHtml = '
';
let newLines = [];
lines.forEach(line => {
const trimmed = line.trim();
if (trimmed.startsWith('|') && trimmed.endsWith('|')) {
const cells = trimmed.split('|').filter((_, i, arr) => i > 0 && i < arr.length - 1);
if (trimmed.includes('---')) return;
if (!inTable) {
inTable = true;
tableHtml += '