@fileverse/content-processor
v0.1.0
Published
Convert markdown files to Yjs-encoded strings compatible with ddoc Tiptap editor
Downloads
562
Readme
markdown-to-yjs
Convert markdown files to Yjs-encoded strings compatible with the ddoc Tiptap editor.
Installation
npm installBuild
npm run buildUsage
import { markdownToYjs } from 'markdown-to-yjs';
import fs from 'fs';
const markdown = fs.readFileSync('document.md', 'utf-8');
const yjsContent = markdownToYjs(markdown);
// yjsContent is a base64-encoded Yjs state string
// ready to be used with the ddoc editorAPI
markdownToYjs(markdown: string, options?: MarkdownToYjsOptions): string
Converts a markdown string to a Yjs-encoded string.
Options:
wrapInDBlock(boolean, default:true): Wrap content in dBlock nodes for ddoc compatibility.
mergeYjsUpdates(updates: string[]): string
Merges multiple Yjs update strings into one.
applyYjsUpdate(existingContent: string, update: string): string
Applies a Yjs update to existing content.
isYjsEncoded(content: string): boolean
Checks if a string is Yjs-encoded (base64).
convertMarkdownToHTML(markdown: string): string
Converts markdown to HTML (intermediate step).
stripFrontmatter(markdown: string): string
Removes YAML frontmatter from markdown.
Supported Markdown Features
- Headings (h1-h6)
- Bold, italic, strikethrough, underline
- Links and images
- Code blocks and inline code
- Bullet lists, ordered lists, task lists
- Blockquotes
- Tables
- Footnotes
- Superscript (
^text^) and subscript (~text~) - Page breaks (
===) - Callouts (
<aside class="callout">)
Test
npm test