mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Attempted adding tricky custom block
Attempted adding callouts, which have the challenge of being shown via HTML within markdown content. Got stuck on parsing back to the state from markdown.
This commit is contained in:
@ -2,9 +2,35 @@ import {Schema} from "prosemirror-model";
|
||||
import {schema as basicSchema} from "prosemirror-schema-basic";
|
||||
import {addListNodes} from "prosemirror-schema-list";
|
||||
|
||||
const bookstackSchema = new Schema({
|
||||
nodes: addListNodes(basicSchema.spec.nodes, "paragraph block*", "block"),
|
||||
const baseNodes = addListNodes(basicSchema.spec.nodes, "paragraph block*", "block");
|
||||
|
||||
const nodeCallout = {
|
||||
attrs: {
|
||||
type: {default: 'info'},
|
||||
},
|
||||
content: "inline*",
|
||||
group: "block",
|
||||
defining: true,
|
||||
parseDOM: [
|
||||
{tag: 'p.callout.info', attrs: {type: 'info'}},
|
||||
{tag: 'p.callout.success', attrs: {type: 'success'}},
|
||||
{tag: 'p.callout.danger', attrs: {type: 'danger'}},
|
||||
{tag: 'p.callout.warning', attrs: {type: 'warning'}},
|
||||
{tag: 'p.callout', attrs: {type: 'info'}},
|
||||
],
|
||||
toDOM: function(node) {
|
||||
const type = node.attrs.type || 'info';
|
||||
return ['p', {class: 'callout ' + type}, 0];
|
||||
}
|
||||
};
|
||||
|
||||
const customNodes = baseNodes.prepend({
|
||||
callout: nodeCallout,
|
||||
});
|
||||
|
||||
const schema = new Schema({
|
||||
nodes: customNodes,
|
||||
marks: basicSchema.spec.marks
|
||||
})
|
||||
|
||||
export {bookstackSchema as schema};
|
||||
export default schema;
|
Reference in New Issue
Block a user