Browse Source

Refactoring ParserHtml

pull/600/head
Artur Arseniev 9 years ago
parent
commit
8a9986e75e
  1. 41
      src/parser/model/ParserHtml.js

41
src/parser/model/ParserHtml.js

@ -143,43 +143,50 @@ module.exports = config => {
} }
// Check if it's a text node and if could be moved to the prevous model // Check if it's a text node and if could be moved to the prevous model
if(model.type == 'textnode'){ if (model.type == 'textnode') {
var prevIsText = nodePrev && nodePrev.type == 'textnode'; if (nodePrev && nodePrev.type == 'textnode') {
if(prevIsText){
nodePrev.content += model.content; nodePrev.content += model.content;
continue; continue;
} }
// Throw away empty nodes (keep spaces) // Throw away empty nodes (keep spaces)
var content = node.nodeValue; const content = node.nodeValue;
if(content != ' ' && !content.trim()){ if (content != ' ' && !content.trim()) {
continue; continue;
} }
} }
// If all children are texts and there is some textnode the parent should // If all children are texts and there is some textnode the parent should
// be text too otherwise I'm unable to edit texnodes // be text too otherwise I'm unable to edit texnodes
var comps = model.components; const comps = model.components;
if(!model.type && comps){ if (!model.type && comps) {
var allTxt = 1; let allTxt = 1;
var foundTextNode = 0; let foundTextNode = 0;
for(var ci = 0; ci < comps.length; ci++){
var comp = comps[ci]; for (let ci = 0; ci < comps.length; ci++) {
if(comp.type != 'text' && const comp = comps[ci];
comp.type != 'textnode' && const cType = comp.type;
c.textTags.indexOf(comp.tagName) < 0 ){
if (['text', 'textnode'].indexOf(cType) < 0 &&
c.textTags.indexOf(comp.tagName) < 0 ) {
allTxt = 0; allTxt = 0;
break; break;
} }
if(comp.type == 'textnode')
if (cType == 'textnode') {
foundTextNode = 1; foundTextNode = 1;
}
} }
if(allTxt && foundTextNode)
if (allTxt && foundTextNode) {
model.type = 'text'; model.type = 'text';
}
} }
// If tagName is still empty and is not a textnode, do not push it // If tagName is still empty and is not a textnode, do not push it
if(!model.tagName && model.type != 'textnode') if (!model.tagName && model.type != 'textnode') {
continue; continue;
}
result.push(model); result.push(model);
} }

Loading…
Cancel
Save