Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #69 from accordproject/ds-plugins-block-input
Browse files Browse the repository at this point in the history
(fix) allow plugins to extend schema
  • Loading branch information
dselman authored Jul 9, 2019
2 parents c4e07ba + 0af20dd commit 23c3484
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/SlateAsInputEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,28 @@ function SlateAsInputEditor(props) {
useEffect(() => {
const schema = JSON.parse(JSON.stringify(baseSchema));
plugins.forEach((plugin) => {
// add all markdown tags to the root of the document
plugin.tags.forEach((tag) => {
schema.document.nodes[0].match.push({ type: tag.slate });
});

// merge the rest of the elements into the schema
const pluginSchema = plugin.schema;
if (pluginSchema) {
if (pluginSchema.blocks) {
schema.blocks = { ...schema.blocks, ...pluginSchema.blocks };
}

if (pluginSchema.inlines) {
schema.inlines = { ...schema.inlines, ...pluginSchema.inlines };
}

if (pluginSchema.rules) {
schema.rules = schema.rules.concat(pluginSchema.rules);
}
}
});
console.log(schema);
setSlateSchema(schema);
}, [plugins]);

Expand Down
3 changes: 3 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const schema = {
},
],
},
inlines: {
},
rules: [],
blocks: {
paragraph: {
nodes: [
Expand Down

0 comments on commit 23c3484

Please sign in to comment.