A deployable markdown editor that connects with your self hosted files and lets you edit in a beautiful interface
1import TurndownService from 'turndown';
2import { unified } from 'unified';
3import remarkParse from 'remark-parse';
4import remarkHtml from 'remark-html';
5
6// Initialize Turndown for HTML to Markdown conversion
7const turndownService = new TurndownService({
8 headingStyle: 'atx',
9 codeBlockStyle: 'fenced',
10 fence: '```',
11 emDelimiter: '_',
12 strongDelimiter: '**',
13 bulletListMarker: '-',
14});
15
16export function htmlToMarkdown(html: string): string {
17 return turndownService.turndown(html);
18}
19
20// Convert markdown to HTML using remark
21export async function markdownToHtml(markdown: string): Promise<string> {
22 const file = await unified()
23 .use(remarkParse)
24 .use(remarkHtml, { sanitize: false })
25 .process(markdown);
26
27 return String(file);
28}
29
30// Synchronous version for TipTap initialization
31export function markdownToHtmlSync(markdown: string): string {
32 // For now, return the markdown as-is and let TipTap handle it
33 // This will be processed asynchronously by the editor
34 return markdown;
35}