# content-on-sx: Documents, blocks & collaborative editing on Smalltalk > **DRAFT outline.** The CMS vertical — blog, WYSIWYG editor, Ghost sync. Depends > on `persist-on-sx` (document history as an event log). Ghost/CMS sync stays a thin > external adapter (Python/FFI) until a native replacement exists. rose-ash's `blog` domain is content management: a block-based WYSIWYG editor, navigation, Ghost CMS sync. A document is a tree of live blocks; editing is a stream of operations; collaboration needs conflict-free merge. That is an object model — blocks are objects, edits are messages, and a document is the object graph responding to them. Smalltalk's "everything is an object responding to messages" maps directly to a block/WYSIWYG model, and a semilattice (CRDT) merge keeps concurrent edits conflict-free. End-state: a Smalltalk-on-SX document model (typed blocks, structural ops), operation log + CRDT merge for collaborative editing, versioning/history via the event store, and a render boundary to HTML/SX. External CMS (Ghost) sync is an injected adapter, not core. ## Status (rolling) `bash lib/content/conformance.sh` → **551/551** (Phases 1–4 COMPLETE + extensions: HTML/SX escaping, Markdown render + import/export incl. tables & frontmatter (full round-trip), CRDT replication, tree-aware validation, snapshot cache, doc metadata, plain-text render, nested block trees + deep tree editing, doc stats, table block, HTML page wrapper + SEO page, doc composition, portable data + wire serialization) ## Ground rules - **Scope:** only `lib/content/**` and `plans/content-on-sx.md`. May **import** from `lib/smalltalk/`, and (once it exists) `lib/persist/`. Do not edit substrates. - **Architecture:** a document is an ordered tree of blocks (objects); an edit is a message (`insert`/`update`/`move`/`delete`); concurrent edits merge via a commutative (CRDT/semilattice) operation so order doesn't matter. History is the `persist` event stream; any version is a replay. - **Determinism:** merge must be commutative + idempotent (test: apply ops in any order / twice → same document). - **Commits:** one feature per commit. Progress log + tick boxes. ## Architecture sketch ``` Edit op Rendered document (insert block after id) ... HTML / SX tree │ ▲ ▼ │ lib/content/block.sx lib/content/render.sx — typed blocks as objects — block tree → HTML/SX — heading/text/image/embed — (reuses SX render boundary) │ ▲ ▼ │ lib/content/doc.sx lib/content/merge.sx — ordered block tree — CRDT/semilattice op merge — apply op, structural moves — concurrent-edit reconciliation │ ▲ ▼ │ lib/content/api.sx ── (content/edit) (content/render) (content/history) ──┐ │ │ ├── op log + versions → persist │ └── Ghost/CMS sync → injected external adapter (thin, non-core) ──┘ ``` ## Phase 1 — Block document model - [x] `block.sx` — typed block objects - [x] `doc.sx` — ordered tree, apply edit op, structural moves - [x] `render.sx` — block tree → HTML/SX - [x] `api.sx` + tests + scoreboard + conformance.sh ## Phase 2 — Op log + versioning - [x] edit ops as `persist` events; replay to any version - [x] `(content/history doc)`, diff between versions ## Phase 3 — Collaborative merge (CRDT) - [x] commutative/idempotent op merge - [x] concurrent-edit tests (any order, double-apply → identical) ## Phase 4 — External sync + federation - [x] Ghost/CMS sync via injected adapter (import/export) - [x] federated documents (peer-authored blocks) — trust-gated stub - [x] tests: round-trip import/export, conflict on concurrent external edit ## Extensions (post-roadmap) - [x] HTML escaping at the render boundary (`String>>htmlEscaped`: & < > ") - [x] asSx wire string-escaping (`String>>sxEscaped`: \ and " in SX literals) - [x] Markdown render mode (`asMarkdown:` / `content/render doc "md"`) - [x] durable CRDT replication (`crdt-store.sx`: ops on persist, replay + converge) - [x] document validation (`validate.sx`: ids, per-type fields, duplicate ids; tree-aware — descends into sections, tree-wide dup ids, section field check) - [x] Markdown import adapter (`md-import.sx`: text → blocks, round-trips export; incl. pipe tables + frontmatter → metadata) - [x] Markdown doc export (`md-doc.sx`: content/markdown-doc, frontmatter from metadata, full round-trip) - [x] snapshot cache over replay (`snapshot.sx`: cache-not-primary, transparent) - [x] document metadata (`meta.sx`: title/slug/tags + Ghost title plumbing) - [x] plain-text render + excerpt (`text.sx`: asText, content/excerpt) - [x] nested block trees (`section.sx`: CtSection container, recursive render, deep-find) - [x] document statistics (`stats.sx`: word/char/block counts, reading time) - [x] table block (`table.sx`: CtTable, renders html/sx/text/md, validated) - [x] HTML page wrapper (`page.sx`: content/page, escaped title from metadata) - [x] SEO page (`page-full.sx`: content/page-full, lang + meta description from excerpt) - [x] document composition (`compose.sx`: concat/prepend/concat-all/wrap-section) - [x] deep tree editing (`tree-edit.sx`: doc-deep-update/replace/delete/insert-into) - [x] portable data serialization (`data.sx`: content/to-data + from-data, round-trips tree) - [x] wire serialization (`wire.sx`: content/to-wire + from-wire, SX-text on the wire) ## Progress log - 2026-06-07 — Extension: deep tree editing (`tree-edit.sx`). `doc-deep-update` / `doc-deep-replace` / `doc-deep-delete` / `doc-deep-insert-into` mutate blocks anywhere in the nested tree (descending into CtSection children), completing tree mutation to match the deep-find read path; all immutable. 17 tests; suite 551/551. - 2026-06-07 — Extension: on-the-wire serialization (`wire.sx`). `content/to-wire` serialises a document to a transmittable SX-text string (data form + SX serializer); `content/from-wire` parses it back into a live document. The whole-document format for persistence / HTTP / federation (distinct from the per-op persist log); round-trips nested trees + tables; reads externally authored wire strings. 11 tests; suite 534/534. - 2026-06-07 — Extension: portable data serialization (`data.sx`). `content/to-data` converts a document to plain SX data (`{:id :title :slug :tags :blocks [{:id :type :fields}]}`, sections recursing); `content/from-data` reconstructs real block objects (section/table handled specially, others generically via mk-block). Round-trips the full tree + metadata (render-equal), decoupling storage/transport from the Smalltalk instance shape. 21 tests; suite 523/523. - 2026-06-07 — Extension: document composition (`compose.sx`). `content/concat` / `content/prepend` / `content/concat-all` combine documents (keeping the first's id + metadata, concatenating blocks, immutable); `content/wrap-section` collapses a doc's blocks into a single nested section. For assembling pages from header/body/footer parts and templates. 17 tests; suite 502/502. - 2026-06-07 — Extension: SEO-complete page (`page-full.sx`). `content/page-full` extends content/page with `` and a `` drawn from the document excerpt (plain text, escaped, 160 chars), composing the page/metadata/text layers into the SEO-ready artifact. 4 tests; suite 485/485. - 2026-06-07 — Extension: Markdown document export (`md-doc.sx`). `content/markdown-doc` emits a `---` frontmatter block from metadata (title/slug/tags, only present fields) ahead of the Markdown body, or plain asMarkdown when there's no metadata. Completes the metadata round-trip: `md/import ∘ content/markdown-doc` preserves title/slug/tags + blocks. 12 tests; suite 481/481. - 2026-06-07 — Extension: Markdown frontmatter. `md/import` parses a leading `---` / `key: value` / `---` block into document metadata (title, slug, comma-separated tags via `doc-with-meta`) before parsing the body; a `---` elsewhere stays a divider. Ties the Markdown importer to the metadata layer the way real blog posts work. +9 tests; suite 469/469. - 2026-06-07 — Extension: Markdown table import. `md-import.sx` now recognizes a `| … |` header row followed by a `| --- |` separator and parses a `CtTable` (cells trimmed, mixed with other blocks via blank-line separation), completing the Markdown table round-trip (import∘export == identity). +5 tests; suite 460/460. - 2026-06-07 — Extension: HTML page wrapper (`page.sx`). `content/page` composes metadata + render into a minimal valid HTML5 document — escaped `