Issue #407Opened October 11, 2017by ateshuseyin0 reactions

Defining new markup language

Question

Code SnippetTEXT
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, 20170 reactions

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

ateshuseyinOctober 11, 20170 reactions

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.