mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 17:06:16 -04:00
Merge branch 'develop' of github.com:ether/etherpad-lite into develop
This commit is contained in:
commit
716b1c6113
3 changed files with 292 additions and 19 deletions
|
@ -305,10 +305,12 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
// want to deal gracefully with blank lines.
|
||||
// => keeps track of the parents level of indentation
|
||||
var lists = []; // e.g. [[1,'bullet'], [3,'bullet'], ...]
|
||||
var listLevels = []
|
||||
for (var i = 0; i < textLines.length; i++)
|
||||
{
|
||||
var line = _analyzeLine(textLines[i], attribLines[i], apool);
|
||||
var lineContent = getLineHTML(line.text, line.aline);
|
||||
listLevels.push(line.listLevel)
|
||||
|
||||
if (line.listLevel)//If we are inside a list
|
||||
{
|
||||
|
@ -328,13 +330,27 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
|
||||
if (whichList >= lists.length)//means we are on a deeper level of indentation than the previous line
|
||||
{
|
||||
if(lists.length > 0){
|
||||
pieces.push('</li>')
|
||||
}
|
||||
lists.push([line.listLevel, line.listTypeName]);
|
||||
|
||||
// if there is a previous list we need to open x tags, where x is the difference of the levels
|
||||
// if there is no previous list we need to open x tags, where x is the wanted level
|
||||
var toOpen = lists.length > 1 ? line.listLevel - lists[lists.length - 2][0] - 1 : line.listLevel - 1
|
||||
|
||||
if(line.listTypeName == "number")
|
||||
{
|
||||
if(toOpen > 0){
|
||||
pieces.push(new Array(toOpen + 1).join('<ol>'))
|
||||
}
|
||||
pieces.push('<ol class="'+line.listTypeName+'"><li>', lineContent || '<br>');
|
||||
}
|
||||
else
|
||||
{
|
||||
if(toOpen > 0){
|
||||
pieces.push(new Array(toOpen + 1).join('<ul>'))
|
||||
}
|
||||
pieces.push('<ul class="'+line.listTypeName+'"><li>', lineContent || '<br>');
|
||||
}
|
||||
}
|
||||
|
@ -363,37 +379,40 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
|||
pieces.push('<br><br>');
|
||||
}
|
||||
}*/
|
||||
else//means we are getting closer to the lowest level of indentation
|
||||
else//means we are getting closer to the lowest level of indentation or are at the same level
|
||||
{
|
||||
while (whichList < lists.length - 1)
|
||||
{
|
||||
var toClose = lists.length > 0 ? listLevels[listLevels.length - 2] - line.listLevel : 0
|
||||
if( toClose > 0){
|
||||
pieces.push('</li>')
|
||||
if(lists[lists.length - 1][1] == "number")
|
||||
{
|
||||
pieces.push('</li></ol>');
|
||||
pieces.push(new Array(toClose+1).join('</ol>'))
|
||||
pieces.push('<li>', lineContent || '<br>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pieces.push('</li></ul>');
|
||||
pieces.push(new Array(toClose+1).join('</ul>'))
|
||||
pieces.push('<li>', lineContent || '<br>');
|
||||
}
|
||||
lists.length--;
|
||||
lists = lists.slice(0,whichList+1)
|
||||
} else {
|
||||
pieces.push('</li><li>', lineContent || '<br>');
|
||||
}
|
||||
pieces.push('</li><li>', lineContent || '<br>');
|
||||
}
|
||||
}
|
||||
else//outside any list
|
||||
else//outside any list, need to close line.listLevel of lists
|
||||
{
|
||||
while (lists.length > 0)//if was in a list: close it before
|
||||
{
|
||||
if(lists[lists.length - 1][1] == "number")
|
||||
{
|
||||
if(lists.length > 0){
|
||||
if(lists[lists.length - 1][1] == "number"){
|
||||
pieces.push('</li></ol>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pieces.push(new Array(listLevels[listLevels.length - 2]).join('</ol>'))
|
||||
} else {
|
||||
pieces.push('</li></ul>');
|
||||
pieces.push(new Array(listLevels[listLevels.length - 2]).join('</ul>'))
|
||||
}
|
||||
lists.length--;
|
||||
}
|
||||
lists = []
|
||||
|
||||
var lineContentFromHook = hooks.callAllStr("getLineHTMLForExport",
|
||||
{
|
||||
line: line,
|
||||
|
|
|
@ -507,6 +507,10 @@ exports.opAssembler = function () {
|
|||
*/
|
||||
exports.stringIterator = function (str) {
|
||||
var curIndex = 0;
|
||||
var newLines = str.split("\n").length - 1
|
||||
function getnewLines(){
|
||||
return newLines
|
||||
}
|
||||
|
||||
function assertRemaining(n) {
|
||||
exports.assert(n <= remaining(), "!(", n, " <= ", remaining(), ")");
|
||||
|
@ -515,6 +519,7 @@ exports.stringIterator = function (str) {
|
|||
function take(n) {
|
||||
assertRemaining(n);
|
||||
var s = str.substr(curIndex, n);
|
||||
newLines -= s.split("\n").length - 1
|
||||
curIndex += n;
|
||||
return s;
|
||||
}
|
||||
|
@ -537,7 +542,8 @@ exports.stringIterator = function (str) {
|
|||
take: take,
|
||||
skip: skip,
|
||||
remaining: remaining,
|
||||
peek: peek
|
||||
peek: peek,
|
||||
newlines: getnewLines
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -910,6 +916,8 @@ exports.applyToText = function (cs, str) {
|
|||
var csIter = exports.opIterator(unpacked.ops);
|
||||
var bankIter = exports.stringIterator(unpacked.charBank);
|
||||
var strIter = exports.stringIterator(str);
|
||||
var newlines = 0
|
||||
var newlinefail = false
|
||||
var assem = exports.stringAssembler();
|
||||
while (csIter.hasNext()) {
|
||||
var op = csIter.next();
|
||||
|
@ -919,16 +927,24 @@ exports.applyToText = function (cs, str) {
|
|||
break;
|
||||
case '-':
|
||||
removedLines += op.lines;
|
||||
newlines = strIter.newlines()
|
||||
strIter.skip(op.chars);
|
||||
if(!(newlines - strIter.newlines() == 0) && (newlines - strIter.newlines() != op.lines)){
|
||||
newlinefail = true
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
newlines = strIter.newlines()
|
||||
assem.append(strIter.take(op.chars));
|
||||
if(!(newlines - strIter.newlines() == op.lines)){
|
||||
newlinefail = true
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
exports.assert(totalNrOfLines >= removedLines,"cannot remove ", removedLines, " lines from text with ", totalNrOfLines, " lines");
|
||||
assem.append(strIter.take(strIter.remaining()));
|
||||
return assem.toString();
|
||||
return [assem.toString(),newlinefail];
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1599,8 +1615,12 @@ exports.makeAText = function (text, attribs) {
|
|||
* @param pool {AttribPool} Attribute Pool to add to
|
||||
*/
|
||||
exports.applyToAText = function (cs, atext, pool) {
|
||||
var text = exports.applyToText(cs, atext.text)
|
||||
if(text[1]){
|
||||
throw new Error()
|
||||
}
|
||||
return {
|
||||
text: exports.applyToText(cs, atext.text),
|
||||
text: text[0],
|
||||
attribs: exports.applyToAttribution(cs, atext.attribs, pool)
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue