prosemirror-go

module
v0.4.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2020 License: AGPL-3.0

README

ProseMirror in Go

go.dev reference Build Status Go Report Card

Introduction

ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas. This repository contains a port in Go of prosemirror-model and prosemirror-transform in order to have the server part of the collaborative editing in Go.

Notes

  1. Only the code necessary for writing a server for collaborative editing will be ported, not things like translating a document to/from a DOM representation which are only useful on the clients.

  2. In go, the maps don't preserve the order of the key (and even the JSON spec doesn't say that there is an order for object fields). OrderedMap in the JS schema needs to be serialized in JSON to an array of tuples [key, value] to keep the order:

[
  ["em", { "inclusive": true, "group": "fontStyle" }],
  ["strong", { "inclusive": true, "group": "fontStyle" }]
]
  1. Go doesn't support optional arguments like JS does. We are emulating this with variadic arguments:
  // :: (number, number, (node: Node, pos: number, parent: Node, index: number) → ?bool, ?number)
  nodesBetween(from, to, f, startPos = 0) {
    this.content.nodesBetween(from, to, f, startPos, this)
  }
func (n *Node) NodesBetween(from, to int, fn NBCallback, startPos ...int) {
	s := 0
	if len(startPos) > 0 {
		s = startPos[0]
	}
	n.Content.NodesBetween(from, to, fn, s, n)
}
  1. Exceptions in JS can be manager in Go by returning an error, or with a panic. We have tried to panic only for logic bugs and out of bounds access, and returning an error everywhere else.

License

The port in Go of ProseMirror has been developed by Cozy Cloud and is distributed under the AGPL v3 license.

Directories

Path Synopsis
Package model implements ProseMirror's document model, along with the mechanisms needed to support schemas.
Package model implements ProseMirror's document model, along with the mechanisms needed to support schemas.
schema
basic
Package basic defines a basic ProseMirror document schema, whose elements can be reused in other schemas.
Package basic defines a basic ProseMirror document schema, whose elements can be reused in other schemas.
list
Package list exports list-related schema elements and commands.
Package list exports list-related schema elements and commands.
test
builder
Package builder is a module used to write tests for ProseMirror.
Package builder is a module used to write tests for ProseMirror.
Package transform implements document transforms, which are used by the editor to treat changes as first-class values, which can be saved, shared, and reasoned about.
Package transform implements document transforms, which are used by the editor to treat changes as first-class values, which can be saved, shared, and reasoned about.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL