Created
May 23, 2023 14:19
-
-
Save eric-burel/8f85849192b2d969a0cec77793f7ff78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {EditorState} = require("prosemirror-state") | |
const {EditorView} = require("prosemirror-view") | |
const {Schema, DOMParser} = require("prosemirror-model") | |
const {schema} = require("prosemirror-schema-basic") | |
const {addListNodes} = require("prosemirror-schema-list") | |
const {exampleSetup} = require("prosemirror-example-setup") | |
const { inputRules, InputRule } = require("prosemirror-inputrules") | |
const starRule = new InputRule(/\*(.+)\*/, (state, match, start, end) => { | |
console.log("triggered star rule") | |
console.log({start, end, "match.index": match.index}) | |
if (match.index !== start - 1) { | |
console.warn("match and start mismatch") | |
} | |
return null | |
}) | |
// Mix the nodes from prosemirror-schema-list into the basic schema to | |
// create a schema with list support. | |
const mySchema = new Schema({ | |
nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"), | |
marks: schema.spec.marks | |
}) | |
window.view = new EditorView(document.querySelector("#editor"), { | |
state: EditorState.create({ | |
doc: DOMParser.fromSchema(mySchema).parse(document.querySelector("#content")), | |
plugins: [...exampleSetup({schema: mySchema}), | |
inputRules({rules: [ | |
starRule | |
]}) | |
] | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment