Shared schema for Editor
Use the setConfig
function to config them
List of configs:
embedRegex
: regex to match URLs for automatically convert to embed
schemaExtensions
: Full schema extensions arraycreateSchemaExtensions
: Use for extend extensions with NodeViewrichInputExtensions
: Extensions for RichInput component
gallerySettings
: Classes for galleryschema
: ProseMirror schemaparse
: Convert html string to ProseMirror documentrender
: Convert ProseMirror document to htmlrenderFragment
: Convert ProseMirror fragment to htmlwalkTree
: Traverse ProseMirror's Node and allow you to modify specific kinds of NodeloadDocument
: Convert ProseMirror json to ProseMirror NodestopEvent
: ForNodeView
to configure thestopEvent
purify
: Sanitize HTMLassertJSON(x)
: ifx
is a valid JSON string, returnx
, else returnnull
safeParse(x)
: ifx
is a valid JSON string, return the parsed result, else returnnull
Please see tests/examples/doc-example.spec.ts for runnable example
const node = parse(html)
// then you can use `walkTree` to modify ProseMirror Node
const node = parse(html)
console.log(node.toJSON())
In this example, we wrap all the image node's URL with $
ProseMirror Node is an immutable structure, you'll need to create a new node with node.type.create
const node = parse(html)
const result = await walkTree(node, {
image: (node: Node) => {
// This will create a new Node with
return node.type.create({
...node.attrs,
src: `$${node.attrs.src}$`,
})
},
})
$ yarn install
$ yarn build
$ yarn test
這個 repo 裡主要都是靠 integration test 的方式,直接去載入 build 好的檔案進行測試
目前已經修好了無法正常 import 檔案測試的問題,可以用一般的 unit test 測試