Issue #407💬 AnsweredOpened October 11, 2017by ateshuseyin0 reactions

Defining new markup language

快速解答by gasserol

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

Read full answer below ↓

Question

代码片段TEXT
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.

Answers (3)

ateshuseyinOctober 11, 2017

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

ateshuseyinOctober 11, 2017

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

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.