begin understanding why HTML export can be broken on weird content

This commit is contained in:
John McLear 2013-04-16 21:06:37 +01:00
parent a3ed936d5f
commit 40780ae32f

View file

@ -128,7 +128,7 @@ function getHTMLFromAtext(pad, atext, authorColors)
function getLineHTML(text, attribs) function getLineHTML(text, attribs)
{ {
var propVals = [false, false, false]; var propVals = [false, false, false, false, false, false];
var ENTER = 1; var ENTER = 1;
var STAY = 2; var STAY = 2;
var LEAVE = 0; var LEAVE = 0;
@ -222,32 +222,41 @@ function getHTMLFromAtext(pad, atext, authorColors)
while (iter.hasNext()) while (iter.hasNext())
{ {
var o = iter.next(); var o = iter.next();
//console.warn("o.attribs", o.attribs);
var propChanged = false; var propChanged = false;
Changeset.eachAttribNumber(o.attribs, function (a) Changeset.eachAttribNumber(o.attribs, function (a)
{ {
//console.warn("a", a);
if (a in anumMap) if (a in anumMap)
{ {
//console.warn("anumapa", anumMap[a], a);
var i = anumMap[a]; // i = 0 => bold, etc. var i = anumMap[a]; // i = 0 => bold, etc.
if (!propVals[i]) console.warn("propVals[i]", propVals[i]);
if (!propVals[i]) // do we already have an open tag for this?
{ {
console.warn("creating ", props[i])
propVals[i] = ENTER; propVals[i] = ENTER;
propChanged = true; propChanged = true;
} }
else else
{ {
console.warn("Staying ", props[i])
propVals[i] = STAY; propVals[i] = STAY;
} }
} }
}); });
for (var i = 0; i < propVals.length; i++) for (var i = 0; i < propVals.length; i++)
{ {
// console.warn("Here", props[i], propVals[i]);
if (propVals[i] === true) if (propVals[i] === true)
{ {
console.warn("Preparing to Leave ", props[i])
propVals[i] = LEAVE; propVals[i] = LEAVE;
propChanged = true; propChanged = true;
} }
else if (propVals[i] === STAY) else if (propVals[i] === STAY)
{ {
console.warn("Staying with ", props[i]);
propVals[i] = true; // set it back propVals[i] = true; // set it back
} }
} }
@ -264,6 +273,15 @@ function getHTMLFromAtext(pad, atext, authorColors)
{ {
if (v === LEAVE) if (v === LEAVE)
{ {
// Is another tag open that was open after this one and is it different from the current tag/
// If so, close it else we will get bad HTML
console.warn(openTags);
var lastItem = openTags.slice(-1)[0]; // Get the last opened item IE 5
console.warn(i, lastItem);
if(lastItem !== i){
console.warn("Attempting to close a tag that isn't open at this level");
}
console.warn("Leaving ", props[i])
left = true; left = true;
} }
} }