summaryrefslogtreecommitdiff
path: root/src/node/utils
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2014-12-30 13:47:31 +0100
committerJohn McLear <john@mclear.co.uk>2014-12-30 13:47:31 +0100
commit4687d226c62ad0e837ccbcb21971b246692b0e6f (patch)
treeefa224c0a482d3ac238150f82becbb5d3bd66bd0 /src/node/utils
parent19c78212e8c6cf3f3f3b8007a5dbb5590b8503c3 (diff)
parent6e4e034e425523b9f0e2bf22674d8d36082fcbbd (diff)
downloadetherpad-lite-4687d226c62ad0e837ccbcb21971b246692b0e6f.zip
Merge pull request #2417 from webzwo0i/fix-export
Fix ExportHtml.js list parsing code
Diffstat (limited to 'src/node/utils')
-rw-r--r--src/node/utils/ExportHtml.js51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js
index 85d5e7a2..a94c4d97 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
{
@@ -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,