From 6e4e034e425523b9f0e2bf22674d8d36082fcbbd Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Mon, 29 Dec 2014 16:27:40 +0100 Subject: [PATCH] fix closing of lists --- src/node/utils/ExportHtml.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index bb29b34d3..a94c4d97a 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -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 { @@ -379,19 +381,23 @@ function getHTMLFromAtext(pad, atext, authorColors) }*/ 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('') if(lists[lists.length - 1][1] == "number") { - pieces.push(''); + pieces.push(new Array(toClose+1).join('')) + pieces.push('
  • ', lineContent || '
    '); } else { - pieces.push('
  • '); + pieces.push(new Array(toClose+1).join('')) + pieces.push('
  • ', lineContent || '
    '); } - lists.length--; + lists = lists.slice(0,whichList+1) + } else { + pieces.push('
  • ', lineContent || '
    '); } - pieces.push('
  • ', lineContent || '
    '); } } else//outside any list, need to close line.listLevel of lists @@ -399,10 +405,10 @@ function getHTMLFromAtext(pad, atext, authorColors) if(lists.length > 0){ if(lists[lists.length - 1][1] == "number"){ pieces.push('
  • '); - pieces.push(new Array(lists[lists.length - 1][0]).join('')) + pieces.push(new Array(listLevels[listLevels.length - 2]).join('')) } else { pieces.push(''); - pieces.push(new Array(lists[lists.length - 1][0]).join('')) + pieces.push(new Array(listLevels[listLevels.length - 2]).join('')) } } lists = []