Get Started
Fastest path: install the package, mount Editor, persist with docToMd.
npm i markloom
# or: bun add markloom / pnpm add markloom
import { mdToDoc, docToMd } from 'markloom'
import { Editor } from 'markloom/view'
import 'markloom/view/theme.css'
const root = document.getElementById('editor')!
const doc = mdToDoc('# Hello\n\nStart writing…')
const ed = new Editor(root, doc, {
onChange: (d) => {
localStorage.setItem('note', docToMd(d))
},
})
import 'markloom/ai/theme.css'
new Editor(root, doc, {
onChange: (d) => save(docToMd(d)),
ai: {
provider: {
host: 'https://api.x.ai',
apiKey: import.meta.env.VITE_AI_KEY,
model: 'grok-3',
},
},
})
Slash /ai and the format bar’s continue / rewrite use the same transport.
Full options: AI write.
new Editor(root, doc, {
collab: {
url: 'wss://your-worker.example',
room: 'demo',
name: 'Alice',
},
})
See Collaboration for the Durable Object worker.
import { apply, appendText, mdToDoc, docToMd } from 'markloom'
const doc = mdToDoc(source)
const next = apply(doc, appendText(doc, blockId, token))
await save(docToMd(next))