mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.9 KiB
2.9 KiB
Parser
You can customize the initial state of the module from the editor initialization, by passing the following Configuration Object
const editor = grapesjs.init({
parser: {
// options
}
})
Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
const { Parser } = editor;
Available Events
parse:html- On HTML parse, an object containing the input and the output of the parser is passed as an argumentparse:css- On CSS parse, an object containing the input and the output of the parser is passed as an argument
Methods
getConfig
Get the configuration object
Examples
console.log(Parser.getConfig())
Returns Object Configuration object
parseHtml
Parse HTML string and return the object containing the Component Definition
Parameters
-
inputString HTML string to parse -
optionsObject? Options (optional, default{})options.htmlTypeString? HTML mime type to parseoptions.allowScriptsBoolean Allow<script>tags (optional, defaultfalse)options.allowUnsafeAttrBoolean Allow unsafe HTML attributes (eg.on*inline event handlers) (optional, defaultfalse)
Examples
const resHtml = Parser.parseHtml(`<table><div>Hi</div></table>`, {
htmlType: 'text/html', // default
});
// By using the `text/html`, this will fix automatically all the HTML syntax issues
// Indeed the final representation, in this case, will be `<div>Hi</div><table></table>`
const resXml = Parser.parseHtml(`<table><div>Hi</div></table>`, {
htmlType: 'application/xml',
});
// This will preserve the original format as, from the XML point of view, is a valid format
Returns Object Object containing the result { html: ..., css: ... }
parseCss
Parse CSS string and return an array of valid definition objects for CSSRules
Parameters
inputString CSS string to parse
Examples
const res = Parser.parseCss('.cls { color: red }');
// [{ ... }]