Skip to content

Commit

Permalink
Document the JSON methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Moor committed Oct 13, 2020
1 parent 5b11857 commit 7d88a2e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ const doc = Node.fromJSON(schema, {
const ydoc = prosemirrorToYDoc(doc)
```

Because JSON is a common usecase there is an equivalent method that skips the need
to create a Prosemirror Node.

```js
import { prosemirrorJSONToYDoc } from 'y-prosemirror'

// Pass JSON previously output from Prosemirror
const ydoc = prosemirrorJSONToYDoc(schema, {
type: "doc",
content: [...]
})
```

```js
import { yDocToProsemirror } from 'y-prosemirror'

Expand All @@ -153,6 +166,19 @@ ydoc.applyUpdate(update)
const node = yDocToProsemirror(schema, ydoc)
```

Because JSON is a common usecase there is an equivalent method that outputs JSON
directly, this method does not require the Prosemirror schema.

```js
import { yDocToProsemirrorJSON } from 'y-prosemirror'

// apply binary updates from elsewhere
const ydoc = new Y.Doc()
ydoc.applyUpdate(update)

const node = yDocToProsemirrorJSON(ydoc)
```

### License

[The MIT License](./LICENSE) © Kevin Jahns

0 comments on commit 7d88a2e

Please sign in to comment.