diff --git a/editors/editoria/src/Editoria.js b/editors/editoria/src/Editoria.js index 2341165a69974cc9d061b0dfbb4b25240440ec56..8bad7ed11b5377d51501935b08ff0228434438d5 100644 --- a/editors/editoria/src/Editoria.js +++ b/editors/editoria/src/Editoria.js @@ -48,7 +48,7 @@ const Editoria = () => ( autoFocus placeholder="Type Something..." fileUpload={file => renderImage(file)} - value="<p> hello <code> this is the code</code></p>" + value="<p> <span style='font-style:italic;'>test</span>hello <code> this is the code</code></p>" layout={EditoriaLayout} user={user} /> diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index 0ee634bb16b3a2440ce420c8aa4d011348f322a6..0bc808b5ff2e521f3b99aa6e50cb485267bc8802 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -43,6 +43,7 @@ class Wax extends Component { super(props); this.application = Application.create(props); const schema = this.application.getSchema(); + console.log(schema); this.application.bootServices(); const { value, onChange } = this.props; diff --git a/wax-prosemirror-services/.gitignore b/wax-prosemirror-services/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7a2f31d8e3f6bfb63391deb56b2acc49193477a1 --- /dev/null +++ b/wax-prosemirror-services/.gitignore @@ -0,0 +1,21 @@ +# dependencies +/node_modules + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +yarn.lock +package-lock.json diff --git a/wax-prosemirror-services/src/SchemaService/Mark.js b/wax-prosemirror-services/src/SchemaService/Mark.js index bee9a57e60b9cd553600da49917601ba19d5a94c..eaa0e99e9dd79d15384c87f72aea9efa8a882e20 100644 --- a/wax-prosemirror-services/src/SchemaService/Mark.js +++ b/wax-prosemirror-services/src/SchemaService/Mark.js @@ -1,3 +1,4 @@ +import { isPlainObject } from "lodash"; import ParseRule from "./ParseRule"; import Middleware from "../lib/Middleware"; @@ -32,15 +33,23 @@ export default class Mark { Object.assign(this._attrs, value); } - set parseDOM(value) { - let parseRule = this._parseRules.find( - parseRule => parseRule.tag === value.tag - ); - if (!parseRule) { - parseRule = new ParseRule(value); - this._parseRules.push(parseRule); + set parseDOM(parseDom) { + let values = parseDom; + if (isPlainObject(parseDom)) { + values = [parseDom]; } - parseRule.addStack(value.getAttrs); + values.forEach(value => { + let parseRule = this._parseRules.find(parseRule => { + if (value.tag) return parseRule.tag === value.tag; + if (value.style) return parseRule.style === value.style; + return false; + }); + if (!parseRule) { + parseRule = new ParseRule(value); + this._parseRules.push(parseRule); + } + parseRule.addStack(value.getAttrs); + }); } toJSON() { diff --git a/wax-prosemirror-services/src/SchemaService/Node.js b/wax-prosemirror-services/src/SchemaService/Node.js index 3b7e738ec0d32924bcd233e9bcdd3bbb1046b94c..085296abaa08a8d89e7b5d4393a4bea4e25ce73b 100644 --- a/wax-prosemirror-services/src/SchemaService/Node.js +++ b/wax-prosemirror-services/src/SchemaService/Node.js @@ -1,3 +1,4 @@ +import { isPlainObject } from "lodash"; import ParseRule from "./ParseRule"; import Middleware from "../lib/Middleware"; @@ -32,15 +33,23 @@ export default class Node { Object.assign(this._attrs, value); } - set parseDOM(value) { - let parseRule = this._parseRules.find( - parseRule => parseRule.tag === value.tag - ); - if (!parseRule) { - parseRule = new ParseRule(value); - this._parseRules.push(parseRule); + set parseDOM(parseDom) { + let values = parseDom; + if (isPlainObject(parseDom)) { + values = [parseDom]; } - parseRule.addStack(value.getAttrs); + values.forEach(value => { + let parseRule = this._parseRules.find(parseRule => { + if (value.tag) return parseRule.tag === value.tag; + if (value.style) return parseRule.style === value.style; + return false; + }); + if (!parseRule) { + parseRule = new ParseRule(value); + this._parseRules.push(parseRule); + } + parseRule.addStack(value.getAttrs); + }); } toJSON() { diff --git a/wax-prosemirror-services/src/SchemaService/ParseRule.js b/wax-prosemirror-services/src/SchemaService/ParseRule.js index f47be611bd3558e3406dae6987593df857e13429..03a91f519c0707016570a11613f4cc69ae8a21e8 100644 --- a/wax-prosemirror-services/src/SchemaService/ParseRule.js +++ b/wax-prosemirror-services/src/SchemaService/ParseRule.js @@ -2,11 +2,13 @@ import { omit } from "lodash"; import Middleware from "../lib/Middleware"; export default class ParseRule { - tag = ""; + tag = null; + style = null; exporter = null; - constructor({ getAttrs, tag }) { + constructor({ getAttrs, tag, style }) { this.tag = tag; + this.style = style; if (getAttrs) { this.exporter = new Middleware(); } @@ -20,7 +22,15 @@ export default class ParseRule { } parseSchema(exporter) { - const rule = { tag: this.tag }; + let rule = {}; + if (this.tag) { + rule = { tag: this.tag }; + } + + if (this.style) { + rule = { style: this.style }; + } + if (this.exporter) { rule.getAttrs = dom => { let hooks = {};