Browse Source

Update textnode parser

pull/36/head
Artur Arseniev 10 years ago
parent
commit
71e249d8cb
  1. 7
      src/dom_components/model/ComponentImage.js
  2. 30
      src/parser/model/ParserHtml.js

7
src/dom_components/model/ComponentImage.js

@ -12,6 +12,13 @@ define(['./Component'],
traits: ['alt'], traits: ['alt'],
}), }),
initialize: function(o, opt) {
Component.prototype.initialize.apply(this, arguments);
var attr = this.get('attributes');
if(attr.src)
this.set('src', attr.src);
},
/** /**
* Returns object of attributes for HTML * Returns object of attributes for HTML
* @return {Object} * @return {Object}

30
src/parser/model/ParserHtml.js

@ -92,11 +92,13 @@ define(function(require) {
var nodeName = attrs[j].nodeName; var nodeName = attrs[j].nodeName;
var nodeValue = attrs[j].nodeValue; var nodeValue = attrs[j].nodeValue;
//Isolate style, class and src attributes //Isolate few attributes
if(nodeName == 'style') if(nodeName == 'style')
model.style = this.parseStyle(nodeValue); model.style = this.parseStyle(nodeValue);
else if(nodeName == 'class') else if(nodeName == 'class')
model.classes = this.parseClass(nodeValue); model.classes = this.parseClass(nodeValue);
else if (nodeName == 'contenteditable')
continue;
else else
model.attributes[nodeName] = nodeValue; model.attributes[nodeName] = nodeValue;
} }
@ -125,30 +127,26 @@ define(function(require) {
} }
} }
var prevIsText = prevSib && prevSib.type == 'textnode'; // 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 = prevSib && prevSib.type == 'textnode';
if(prevIsText){ if(prevIsText){
prevSib.content += model.content; prevSib.content += model.content;
continue; continue;
} }
} // Throw away empty nodes (keep spaces)
// Check if it's a text node and if it could be moved to the prevous model var content = node.nodeValue;
/* if(content != ' ' && !content.trim()){
if(c.textTags.indexOf(model.tagName) >= 0){
if(prevIsText){
prevSib.content += node.outerHTML;
continue; continue;
}else{
console.log(model);
model = { type: 'text', tagName: TEXT_NODE, content: node.outerHTML,};
} }
}*/ }
// If all components are texts and textnodes the parent should be text too // If all children are texts and there is some textnode the parent should
// otherwise I'm unable to edit texts // be text too otherwise I'm unable to edit texnodes
var comps = model.components; var comps = model.components;
if(!model.type && comps){ if(!model.type && comps){
var allTxt = 1; var allTxt = 1;
var foundTextNode = 0;
for(var ci = 0; ci < comps.length; ci++){ for(var ci = 0; ci < comps.length; ci++){
var comp = comps[ci]; var comp = comps[ci];
if(comp.type != 'text' && if(comp.type != 'text' &&
@ -157,8 +155,10 @@ define(function(require) {
allTxt = 0; allTxt = 0;
break; break;
} }
if(comp.type == 'textnode')
foundTextNode = 1;
} }
if(allTxt) if(allTxt && foundTextNode)
model.type = 'text'; model.type = 'text';
} }

Loading…
Cancel
Save