Merge pull request #2032 from webzwo0i/fix-exporthtml-styling-tags
Fix exporthtml styling tags
This commit is contained in:
commit
37015e728b
|
@ -21,7 +21,6 @@ var padManager = require("../db/PadManager");
|
|||
var ERR = require("async-stacktrace");
|
||||
var Security = require('ep_etherpad-lite/static/js/security');
|
||||
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||
var getPadPlainText = require('./ExportHelper').getPadPlainText;
|
||||
var _analyzeLine = require('./ExportHelper')._analyzeLine;
|
||||
var _encodeWhitespace = require('./ExportHelper')._encodeWhitespace;
|
||||
|
||||
|
@ -79,6 +78,10 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
|
||||
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
|
||||
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
|
||||
// holds a map of used styling attributes (*1, *2, etc) in the apool
|
||||
// and maps them to an index in props
|
||||
// *3:2 -> the attribute *3 means strong
|
||||
// *2:5 -> the attribute *2 means s(trikethrough)
|
||||
var anumMap = {};
|
||||
var css = "";
|
||||
|
||||
|
@ -117,6 +120,8 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
css+="</style>";
|
||||
}
|
||||
|
||||
// iterates over all props(h1,h2,strong,...), checks if it is used in
|
||||
// this pad, and if yes puts its attrib id->props value into anumMap
|
||||
props.forEach(function (propName, i)
|
||||
{
|
||||
var propTrueNum = apool.putAttrib([propName, true], true);
|
||||
|
@ -128,11 +133,6 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
|
||||
function getLineHTML(text, attribs)
|
||||
{
|
||||
var propVals = [false, false, false];
|
||||
var ENTER = 1;
|
||||
var STAY = 2;
|
||||
var LEAVE = 0;
|
||||
|
||||
// Use order of tags (b/i/u) as order of nesting, for simplicity
|
||||
// and decent nesting. For example,
|
||||
// <b>Just bold<b> <b><i>Bold and italics</i></b> <i>Just italics</i>
|
||||
|
@ -175,6 +175,7 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
}
|
||||
}
|
||||
|
||||
// this closes an open tag and removes its reference from openTags
|
||||
function emitCloseTag(i)
|
||||
{
|
||||
openTags.shift();
|
||||
|
@ -189,22 +190,6 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
}
|
||||
}
|
||||
|
||||
function orderdCloseTags(tags2close)
|
||||
{
|
||||
for(var i=0;i<openTags.length;i++)
|
||||
{
|
||||
for(var j=0;j<tags2close.length;j++)
|
||||
{
|
||||
if(tags2close[j] == openTags[i])
|
||||
{
|
||||
emitCloseTag(tags2close[j]);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var urls = _findURLs(text);
|
||||
|
||||
var idx = 0;
|
||||
|
@ -219,92 +204,51 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
var iter = Changeset.opIterator(Changeset.subattribution(attribs, idx, idx + numChars));
|
||||
idx += numChars;
|
||||
|
||||
// this iterates over every op string and decides which tags to open or to close
|
||||
// based on the attribs used
|
||||
while (iter.hasNext())
|
||||
{
|
||||
var o = iter.next();
|
||||
var propChanged = false;
|
||||
var usedAttribs = [];
|
||||
|
||||
// mark all attribs as used
|
||||
Changeset.eachAttribNumber(o.attribs, function (a)
|
||||
{
|
||||
if (a in anumMap)
|
||||
{
|
||||
var i = anumMap[a]; // i = 0 => bold, etc.
|
||||
if (!propVals[i])
|
||||
{
|
||||
propVals[i] = ENTER;
|
||||
propChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
propVals[i] = STAY;
|
||||
}
|
||||
usedAttribs.push(anumMap[a]); // i = 0 => bold, etc.
|
||||
}
|
||||
});
|
||||
for (var i = 0; i < propVals.length; i++)
|
||||
var outermostTag = -1;
|
||||
// find the outer most open tag that is no longer used
|
||||
for (var i = openTags.length - 1; i >= 0; i--)
|
||||
{
|
||||
if (propVals[i] === true)
|
||||
if (usedAttribs.indexOf(openTags[i]) === -1)
|
||||
{
|
||||
propVals[i] = LEAVE;
|
||||
propChanged = true;
|
||||
}
|
||||
else if (propVals[i] === STAY)
|
||||
{
|
||||
propVals[i] = true; // set it back
|
||||
outermostTag = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// now each member of propVal is in {false,LEAVE,ENTER,true}
|
||||
// according to what happens at start of span
|
||||
if (propChanged)
|
||||
|
||||
// close all tags upto the outer most
|
||||
if (outermostTag != -1)
|
||||
{
|
||||
// leaving bold (e.g.) also leaves italics, etc.
|
||||
var left = false;
|
||||
for (var i = 0; i < propVals.length; i++)
|
||||
while ( outermostTag >= 0 )
|
||||
{
|
||||
var v = propVals[i];
|
||||
if (!left)
|
||||
{
|
||||
if (v === LEAVE)
|
||||
{
|
||||
left = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (v === true)
|
||||
{
|
||||
propVals[i] = STAY; // tag will be closed and re-opened
|
||||
}
|
||||
}
|
||||
emitCloseTag(openTags[0]);
|
||||
outermostTag--;
|
||||
}
|
||||
}
|
||||
|
||||
var tags2close = [];
|
||||
|
||||
for (var i = propVals.length - 1; i >= 0; i--)
|
||||
// open all tags that are used but not open
|
||||
for (i=0; i < usedAttribs.length; i++)
|
||||
{
|
||||
if (openTags.indexOf(usedAttribs[i]) === -1)
|
||||
{
|
||||
if (propVals[i] === LEAVE)
|
||||
{
|
||||
//emitCloseTag(i);
|
||||
tags2close.push(i);
|
||||
propVals[i] = false;
|
||||
}
|
||||
else if (propVals[i] === STAY)
|
||||
{
|
||||
//emitCloseTag(i);
|
||||
tags2close.push(i);
|
||||
}
|
||||
emitOpenTag(usedAttribs[i])
|
||||
}
|
||||
}
|
||||
|
||||
orderdCloseTags(tags2close);
|
||||
|
||||
for (var i = 0; i < propVals.length; i++)
|
||||
{
|
||||
if (propVals[i] === ENTER || propVals[i] === STAY)
|
||||
{
|
||||
emitOpenTag(i);
|
||||
propVals[i] = true;
|
||||
}
|
||||
}
|
||||
// propVals is now all {true,false} again
|
||||
} // end if (propChanged)
|
||||
var chars = o.chars;
|
||||
if (o.lines)
|
||||
{
|
||||
|
@ -320,17 +264,11 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
assem.append(_encodeWhitespace(Security.escapeHTML(s)));
|
||||
} // end iteration over spans in line
|
||||
|
||||
var tags2close = [];
|
||||
for (var i = propVals.length - 1; i >= 0; i--)
|
||||
// close all the tags that are open after the last op
|
||||
while (openTags.length > 0)
|
||||
{
|
||||
if (propVals[i])
|
||||
{
|
||||
tags2close.push(i);
|
||||
propVals[i] = false;
|
||||
}
|
||||
emitCloseTag(openTags[0])
|
||||
}
|
||||
|
||||
orderdCloseTags(tags2close);
|
||||
} // end processNextChars
|
||||
if (urls)
|
||||
{
|
||||
|
@ -573,8 +511,8 @@ function _processSpaces(s){
|
|||
}
|
||||
}
|
||||
// beginning of line is nbsp
|
||||
for (var i = 0; i < parts.length; i++){
|
||||
var p = parts[i];
|
||||
for (i = 0; i < parts.length; i++){
|
||||
p = parts[i];
|
||||
if (p == " "){
|
||||
parts[i] = ' ';
|
||||
break;
|
||||
|
@ -586,8 +524,8 @@ function _processSpaces(s){
|
|||
}
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < parts.length; i++){
|
||||
var p = parts[i];
|
||||
for (i = 0; i < parts.length; i++){
|
||||
p = parts[i];
|
||||
if (p == " "){
|
||||
parts[i] = ' ';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue