import TurndownService from 'turndown'; import { unified } from 'unified'; import remarkParse from 'remark-parse'; import remarkHtml from 'remark-html'; // Initialize Turndown for HTML to Markdown conversion const turndownService = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced', fence: '```', emDelimiter: '_', strongDelimiter: '**', bulletListMarker: '-', }); export function htmlToMarkdown(html: string): string { return turndownService.turndown(html); } // Convert markdown to HTML using remark export async function markdownToHtml(markdown: string): Promise { const file = await unified() .use(remarkParse) .use(remarkHtml, { sanitize: false }) .process(markdown); return String(file); } // Synchronous version for TipTap initialization export function markdownToHtmlSync(markdown: string): string { // For now, return the markdown as-is and let TipTap handle it // This will be processed asynchronously by the editor return markdown; }