markloom

Rich text · Markdown isomorphism · AI-native

The loom for
Markdown.

A schema-constrained tree, reversible Steps, and MD as a first-class projection — not “export later.” Optional AI streams into real blocks; collab is one options field. No ProseMirror.

Tree ↔ MD
isomorphic projection
4 Steps
apply ∘ invert = id
AI draft
same history stack
0 PM
kernel is zero-DOM

One model. Three surfaces.

Markdown source, stable-id tree, and the controlled editor are the same document. AI appends a draft block — accept commits, discard undoes. No second history.

  • mdToDoc
  • block ids
  • Step history
  • aiDraft
Idle
note.md source
# Shipping notes
**markloom** keeps MD honest.

- Tree is source of truth
- Steps are reversible
- AI writes real blocks

```ts
apply ∘ invert = id
```

Paste text/plain as MD · HTML as blocks

doc tree · ids
doc #root
heading #h1a “Shipping notes”
paragraph #p2 bold + text
bullet_list #l3 ×3 items
code_block #c4 lang=ts
paragraph #ai5 aiDraft

Agents address id · paths move with structure

editor · projection

Shipping notes

markloom keeps MD honest.

  • Tree is source of truth
  • Steps are reversible
  • AI writes real blocks
apply ∘ invert = id

Next: ship collab presence to production…

AI draft · accept / undo

contentEditable owned · beforeinput → Steps

What you actually get

Four primitives. Product surfaces without a second document model.

Markdown

Isomorphic, not export

mdToDoc / docToMd via mdast. Clean blocks keep source spans so untouched prose doesn’t reformat away.

Kernel

Reversible Steps

Insert, delete, replace, splice. apply ∘ invert = identity — undo, history, and AI rollback are the same mechanism.

View

Fully controlled DOM

Preact + contentEditable owned via beforeinput. Model is truth; IME is a 3-way merge, not hope.

AI

Write as a transaction

Slash /ai, format-bar continue/rewrite, stream into real draft blocks. Accept = commit; discard = undo.

Collab

OT + Durable Object

collab: { url, room } on the editor. Centralized OT, presence avatars, per-person undo. Worker included.

Surface

Product chrome built-in

Slash menu, bubble bar, drag handle, tables, callouts, TOC, comments — extensions without forking the kernel.

markloom /ˈmɑːrk.luːm/ — weave Markdown into structure without losing the thread.

Install once. Import the piece you need.

Kernel has no DOM. View, AI, collab, and React are optional entrypoints on the same package.

npm i markloom

import { Editor } from 'markloom/view'
import 'markloom/view/theme.css'

const ed = new Editor(root, doc, {
  onChange: d => save(docToMd(d)),
  // ai: { provider | endpoint | stream }
  // collab: { url, room, name }
})

Package map

ImportWhat it is
markloomTree, Steps, history, MD, appendText / diffById
markloom/viewEditor + theme.css
markloom/aiAI controller + stream helper + theme
markloom/collabRealtime OT client (pair with worker/)
markloom/reactOptional React wrapper

One tree.
Honest Markdown.

Stop gluing paste, IME, undo, and AI cards. Start from reversible Steps.