Browse Source

Improve parsing XML

pull/3691/head
Artur Arseniev 5 years ago
parent
commit
8842059513
  1. 10
      src/dom_components/model/Component.js
  2. 3
      src/dom_components/model/ComponentScript.js
  3. 3
      src/parser/model/BrowserParserHtml.js
  4. 4
      src/parser/model/ParserHtml.js
  5. 2
      src/utils/mixins.js

10
src/dom_components/model/Component.js

@ -11,7 +11,13 @@ import {
bindAll,
keys
} from 'underscore';
import { shallowDiff, capitalize, isEmptyObj, isObject } from 'utils/mixins';
import {
shallowDiff,
capitalize,
isEmptyObj,
isObject,
toLowerCase
} from 'utils/mixins';
import Styleable from 'domain_abstract/model/Styleable';
import { Model } from 'backbone';
import Components from './Components';
@ -1736,7 +1742,7 @@ export default class Component extends Model.extend(Styleable) {
* @private
*/
Component.isComponent = el => {
return { tagName: el.tagName ? el.tagName.toLowerCase() : '' };
return { tagName: toLowerCase(el.tagName) };
};
Component.ensureInList = model => {

3
src/dom_components/model/ComponentScript.js

@ -1,4 +1,5 @@
import Component from './Component';
import { toLowerCase } from 'utils/mixins';
const type = 'script';
@ -15,7 +16,7 @@ export default Component.extend(
},
{
isComponent(el) {
if (el.tagName == 'SCRIPT') {
if (toLowerCase(el.tagName) == type) {
const result = { type };
if (el.src) {

3
src/parser/model/BrowserParserHtml.js

@ -1,8 +1,7 @@
import { each } from 'underscore';
const htmlType = 'text/html';
// const defaultType = 'application/xml';
const defaultType = htmlType;
const defaultType = 'application/xml';
export default (str, config = {}) => {
const parser = new DOMParser();

4
src/parser/model/ParserHtml.js

@ -5,6 +5,7 @@ export default config => {
var TEXT_NODE = 'span';
var c = config;
var modelAttrStart = 'data-gjs-';
const event = 'parse:html';
return {
compTypes: '',
@ -301,12 +302,13 @@ export default config => {
if (styleStr) res.css = parserCss.parse(styleStr);
}
em && em.trigger(`${event}:root`, { input: str, root: el });
const result = this.parseNode(el);
// I have to keep it otherwise it breaks the DomComponents.addComponent (returns always array)
const resHtml =
result.length === 1 && !c.returnArray ? result[0] : result;
res.html = resHtml;
em && em.trigger('parse:html', { input: str, output: res });
em && em.trigger(event, { input: str, output: res });
return res;
}

2
src/utils/mixins.js

@ -2,6 +2,8 @@ import { keys, isUndefined, isElement, isArray } from 'underscore';
export const hasWin = () => typeof window !== 'undefined';
export const toLowerCase = str => (str || '').toLowerCase();
const elProt = hasWin() ? window.Element.prototype : {};
const matches =
elProt.matches ||

Loading…
Cancel
Save