Defining new markup language
Question
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)
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
Thanks @gasserol. I saw but I could not find the problem.
Now works on drop :) But still cannot parse from element.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1805
Define new Image component
I'm new to GrapesJs and am unable to figure out how to create an image component. For example, I have an img tag and have defined the src ,...
Issue #1998
Extending Link component not working properly.
hello @hello @artf I am trying to extend the link component and add new traits like href and target the code is given below. `function load...
Issue #1733
How to remove script tag which is added by add block manager script
Hello @artf I want to export final/production based html content excluding the script(Only which is added by block manager). Suppose i am a...
Issue #459
Error when including a custom component inside another block
Sorry for the vague title. I'm not sure how to describe this concisely. I have a custom block where i want to restrict that only images can...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.