grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Defining new markup language

Open ateshuseyin opened this issue 9 years ago • 7 comments

Hi @artf, I want to define a new markup language like mjml to make design more easy and readable. I started with <error>tag as a POC. Write code below; model: `import Component from 'grapesjs/src/dom_components/model/Component';

const ComponentError = Component.extend({ defaults: { type: 'error', tagName: 'error', ...Component.prototype.defaults },

}, {

/**

  • Detect if the passed element is a valid component.
  • In case the element is valid an object abstracted
  • from the element will be returned
  • @param {HTMLElement}
  • @return {Object}
  • @private */ isComponent(el) { var result = ''; if (el.tagName == 'ERROR') { result = {type: 'error'}; } return result; },

});

export default ComponentError;`

view:

`import ComponentView from 'grapesjs/src/dom_components/view/ComponentView';

const ComponentErrorView = ComponentView.extend({

tagName: 'div',

getChildrenSelector() { return '[data-role="content"]'; },

render(p, c, opts, appendChildren) { this.renderAttributes(); this.el.innerHTML = <span style="color:red">Error:</span><span data-role="content"></span>; this.renderChildren(appendChildren); this.childNodes = this.getChildrenContainer().childNodes; return this; } });

export default ComponentErrorView;`

When I define block as content:'<error/>', it works. But for content: '<error> The message </error>' does not work properly. And editor cannot parse from element.

ateshuseyin avatar Oct 11 '17 10:10 ateshuseyin

Did you see that there is a preset from the author of this project for mjml, maybe this helps you? https://github.com/artf/grapesjs-mjml

gasserol avatar Oct 11 '17 10:10 gasserol

Thanks @gasserol. I saw but I could not find the problem.

ateshuseyin avatar Oct 11 '17 10:10 ateshuseyin

Now works on drop :) But still cannot parse from element.

ateshuseyin avatar Oct 11 '17 11:10 ateshuseyin

Try to add this inside isComponent

return {
     type: 'error',
     components: el.innerHTML
}

artf avatar Oct 12 '17 11:10 artf

Thanks @artf. I just fixed it. It was about place of editor.getModel().loadOnStart();. I moved this line after loading components. components: el.innerHTML has no effect.

ateshuseyin avatar Oct 12 '17 12:10 ateshuseyin

Ok I close then, but check Components to see how to add correctly new component types

artf avatar Oct 12 '17 12:10 artf

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Sep 18 '19 10:09 lock[bot]