Skip to content
Snippets Groups Projects
Commit 4396a87a authored by Giannis Kopanas's avatar Giannis Kopanas
Browse files

fix(schemaService); support array of parseRUles and style match of nodes marks

parent 491a053c
No related branches found
No related tags found
1 merge request!45Develop
...@@ -48,7 +48,7 @@ const Editoria = () => ( ...@@ -48,7 +48,7 @@ const Editoria = () => (
autoFocus autoFocus
placeholder="Type Something..." placeholder="Type Something..."
fileUpload={file => renderImage(file)} 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} layout={EditoriaLayout}
user={user} user={user}
/> />
......
...@@ -43,6 +43,7 @@ class Wax extends Component { ...@@ -43,6 +43,7 @@ class Wax extends Component {
super(props); super(props);
this.application = Application.create(props); this.application = Application.create(props);
const schema = this.application.getSchema(); const schema = this.application.getSchema();
console.log(schema);
this.application.bootServices(); this.application.bootServices();
const { value, onChange } = this.props; const { value, onChange } = this.props;
......
# 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
import { isPlainObject } from "lodash";
import ParseRule from "./ParseRule"; import ParseRule from "./ParseRule";
import Middleware from "../lib/Middleware"; import Middleware from "../lib/Middleware";
...@@ -32,15 +33,23 @@ export default class Mark { ...@@ -32,15 +33,23 @@ export default class Mark {
Object.assign(this._attrs, value); Object.assign(this._attrs, value);
} }
set parseDOM(value) { set parseDOM(parseDom) {
let parseRule = this._parseRules.find( let values = parseDom;
parseRule => parseRule.tag === value.tag if (isPlainObject(parseDom)) {
); values = [parseDom];
if (!parseRule) {
parseRule = new ParseRule(value);
this._parseRules.push(parseRule);
} }
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() { toJSON() {
......
import { isPlainObject } from "lodash";
import ParseRule from "./ParseRule"; import ParseRule from "./ParseRule";
import Middleware from "../lib/Middleware"; import Middleware from "../lib/Middleware";
...@@ -32,15 +33,23 @@ export default class Node { ...@@ -32,15 +33,23 @@ export default class Node {
Object.assign(this._attrs, value); Object.assign(this._attrs, value);
} }
set parseDOM(value) { set parseDOM(parseDom) {
let parseRule = this._parseRules.find( let values = parseDom;
parseRule => parseRule.tag === value.tag if (isPlainObject(parseDom)) {
); values = [parseDom];
if (!parseRule) {
parseRule = new ParseRule(value);
this._parseRules.push(parseRule);
} }
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() { toJSON() {
......
...@@ -2,11 +2,13 @@ import { omit } from "lodash"; ...@@ -2,11 +2,13 @@ import { omit } from "lodash";
import Middleware from "../lib/Middleware"; import Middleware from "../lib/Middleware";
export default class ParseRule { export default class ParseRule {
tag = ""; tag = null;
style = null;
exporter = null; exporter = null;
constructor({ getAttrs, tag }) { constructor({ getAttrs, tag, style }) {
this.tag = tag; this.tag = tag;
this.style = style;
if (getAttrs) { if (getAttrs) {
this.exporter = new Middleware(); this.exporter = new Middleware();
} }
...@@ -20,7 +22,15 @@ export default class ParseRule { ...@@ -20,7 +22,15 @@ export default class ParseRule {
} }
parseSchema(exporter) { 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) { if (this.exporter) {
rule.getAttrs = dom => { rule.getAttrs = dom => {
let hooks = {}; let hooks = {};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment