## Parser
You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object][1]
```js
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
```js
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 argument
* `parse:css` - On CSS parse, an object containing the input and the output of the parser is passed as an argument
## Methods
* [getConfig][2]
* [parseHtml][3]
* [parseCss][4]
## getConfig
Get the configuration object
### Examples
```javascript
console.log(Parser.getConfig())
```
Returns **[Object][5]** Configuration object
## parseHtml
Parse HTML string and return the object containing the Component Definition
### Parameters
* `input` **[String][6]** HTML string to parse
* `options` **[Object][5]?** Options (optional, default `{}`)
* `options.htmlType` **[String][6]?** [HTML mime type][7] to parse
### Examples
```javascript
const resHtml = Parser.parseHtml(`
`, {
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 `Hi
`
const resXml = Parser.parseHtml(``, {
htmlType: 'application/xml',
});
// This will preserve the original format as, from the XML point of view, is a valid format
```
Returns **[Object][5]** Object containing the result `{ html: ..., css: ... }`
## parseCss
Parse CSS string and return an array of valid definition objects for CSSRules
### Parameters
* `input` **[String][6]** CSS string to parse
### Examples
```javascript
const res = Parser.parseCss('.cls { color: red }');
// [{ ... }]
```
Returns **[Array][8]<[Object][5]>** Array containing the result
[1]: https://github.com/artf/grapesjs/blob/master/src/parser/config/config.js
[2]: #getconfig
[3]: #parsehtml
[4]: #parsecss
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[7]: https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString#Argument02
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array