A Go port of ProseMirror for server-side parsing, validation, and canonical HTML
serialization of documents, with a TypeScript companion (the @tozd/prosemirror NPM package) that builds the same
schema in the browser from the same shareable JSON.
The components currently available:
modelpackage, ported from prosemirror-model v1.25.8 – the document model: schemas, nodes, marks, content expressions, HTML fragment parsing, and canonical HTML serialization.
Each ported component mirrors the structure of its ProseMirror TypeScript source so the two can be kept in sync. See PORTING.md for the porting contract.
It is used by PeerDB, a collaborative database.
You can add it to your project using go get:
go get gitlab.com/tozd/go/prosemirror/modelIt requires Go 1.25 or newer.
You can add frontend utilities for Go port of ProseMirror to your project using npm:
npm install --save @tozd/prosemirror prosemirror-modelIt requires node 22 or newer.
schema, errE := model.NewSchema(schemaJSON, map[string]model.AttrValidator{
"linkURL": validateLinkURL,
})
if errE != nil {
// Handle the error.
}
doc, errE := model.ParseHTML(schema, `<p>Hello, <b>world</b>!</p>`, model.ParseOptions{})
if errE != nil {
// Handle the error.
}
canonical := model.SerializeHTML(doc)
ok, errE := model.IsCanonicalHTML(schema, canonical, model.ParseOptions{})
// ok is true: serializing a parsed document always yields the canonical form.See full package documentation with examples on pkg.go.dev.
The same schema JSON can be built into a ProseMirror schema in the browser:
import { buildSchema } from "@tozd/prosemirror"
const schema = buildSchema(schemaJSON, { linkURL: validateLinkURL })buildSchema takes a parsed schema JSON object and a registry of named attribute validators and returns a
prosemirror-model Schema, with parseDOM and toDOM derived from the dialect, the browser-usable counterpart of
model.NewSchema. prosemirror-model is a peer dependency. The frontend and the Go backend build the same schema from
one shared JSON definition.
Schemas are described by a single JSON document that can be shared with a ProseMirror TypeScript implementation.
Functions cannot live in JSON, so attribute validators are referenced by name (resolved against a registry passed to
model.NewSchema) and the HTML mapping is declarative (toHTML and parseHTML keys on nodes and marks).
model.NewSchema accepts any spec in this dialect, not only the example schema shipped as a fixture: toHTML covers
the declarative subset of ProseMirror's DOMOutputSpec (including nested elements such as a code block rendered as
pre wrapping code), and parseHTML accepts a full CSS selector in tag (matched with
cascadia), style rules keyed on an inline CSS declaration
({"style": "font-weight=bold"}), and a namespace constraint, alongside context and priority. See
PORTING.md for the full specification of the dialect.
The one documented fidelity boundary is style matching: a style rule matches only an element's own inline longhand
declarations and does not perform CSSOM shorthand expansion or value normalization. So style="font-weight: bold"
matches a font-weight rule, but style="font: bold 12px serif" (which exposes font-weight only after shorthand
expansion in a browser) does not. Everything else parses identically to the browser. Editor-only behaviors and the
transform and collaboration layers are out of scope.
- prosemirror-go – a similar port which is somewhat stale and is licensed under AGPL.
There is also a read-only GitHub mirror available, if you need to fork the project there.
Port has been fully generated and maintained by AI.
Licensed under the Apache License, Version 2.0 (see LICENSE). The ported packages are derivative works of the corresponding ProseMirror packages, used under the MIT license (see NOTICE).