Browse Source

Improve Parser docs

pull/3691/head
Artur Arseniev 5 years ago
parent
commit
cb8df67527
  1. 14
      src/parser/config/config.js
  2. 6
      src/parser/model/ParserHtml.js

14
src/parser/config/config.js

@ -5,11 +5,17 @@ export default {
// @see https://grapesjs.com/docs/guides/Custom-CSS-parser.html
parserCss: null,
// Custom HTML parser
// At the moment, the custom HTML parser should rely on DOM Node instance as the result
// @example
// The return should be an instance of an Node as the root to traverse
// https://developer.mozilla.org/en-US/docs/Web/API/Node
// parserHtml: (input, opts = {}) => (new DOMParser()).parseFromString(input, 'text/xml')
// Here the result will be XMLDocument, which extends Node
parserHtml: null,
// DOMParser mime type (default 'text/html')
// @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString
// If you use the `text/html` parser, it will fix the invalid syntax automatically
htmlType: null,
// TODO: Custom HTML parser
parserHtml: null
htmlType: null
};

6
src/parser/model/ParserHtml.js

@ -1,4 +1,4 @@
import { each, isString } from 'underscore';
import { each, isString, isFunction } from 'underscore';
import BrowserParserHtml from './BrowserParserHtml';
export default config => {
@ -287,7 +287,9 @@ export default config => {
const conf = (em && em.get('Config')) || {};
const res = { html: null, css: null };
const cf = { ...config, ...opts };
const el = BrowserParserHtml(str, cf);
const el = isFunction(cf.parserHtml)
? cf.parserHtml(str, cf)
: BrowserParserHtml(str, cf);
const scripts = el.querySelectorAll('script');
let i = scripts.length;

Loading…
Cancel
Save