From 251a75346d8672b17f5168e9e1eb6bae66a3257a Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 14 Dec 2014 17:48:19 +0100 Subject: [PATCH 1/8] make stringIterator aware of newlines --- src/static/js/Changeset.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 366ad15f9..629cf759d 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -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 }; }; From 51c14d994756e60333b0b60eccb7255cf0c86461 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 14 Dec 2014 17:51:34 +0100 Subject: [PATCH 2/8] check if op.lines is in sync with atext-newlines Conflicts: src/static/js/Changeset.js --- src/static/js/Changeset.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 629cf759d..acb59cc31 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -916,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(); @@ -925,16 +927,24 @@ exports.applyToText = function (cs, str) { break; case '-': removedLines += op.lines; + newlines = strIter.newlines() strIter.skip(op.chars); + if(!(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]; }; /** @@ -1605,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) }; }; From 3354b9406b94e1a04b5eee1c0152914dde73ba89 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Tue, 16 Dec 2014 12:29:33 +0100 Subject: [PATCH 3/8] op is ok, if it doesnt include newlines. op is ok, if op.lines is equal to newlines in op.chars --- src/static/js/Changeset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index acb59cc31..32da887df 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -929,7 +929,7 @@ exports.applyToText = function (cs, str) { removedLines += op.lines; newlines = strIter.newlines() strIter.skip(op.chars); - if(!(newlines - strIter.newlines() == op.lines)){ + if(!(newlines - strIter.newlines() == 0) && (newlines - strIter.newlines() != op.lines)){ newlinefail = true } break; From 53ca26d030649f3998a5bc5b3eb5953afa5eff8e Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 28 Dec 2014 02:27:53 +0100 Subject: [PATCH 4/8] add some import-export tests --- tests/frontend/specs/importexport.js | 249 +++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 tests/frontend/specs/importexport.js diff --git a/tests/frontend/specs/importexport.js b/tests/frontend/specs/importexport.js new file mode 100644 index 000000000..5c642ae35 --- /dev/null +++ b/tests/frontend/specs/importexport.js @@ -0,0 +1,249 @@ +describe("import functionality", function(){ + beforeEach(function(cb){ + helper.newPad(cb); // creates a new pad + this.timeout(60000); + }); + + function getinnertext(){ + var inner = helper.padInner$ + var newtext = "" + inner("div").each(function(line,el){ + newtext += el.innerHTML+"\n" + }) + return newtext + } + function importrequest(data,importurl,type){ + var success; + var error; + var result = $.ajax({ + url: importurl, + type: "post", + processData: false, + async: false, + contentType: 'multipart/form-data; boundary=boundary', + accepts: { + text: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + }, + data: 'Content-Type: multipart/form-data; boundary=--boundary\r\n\r\n--boundary\r\nContent-Disposition: form-data; name="file"; filename="import.'+type+'"\r\nContent-Type: text/plain\r\n\r\n' + data + '\r\n\r\n--boundary', + error: function(res){ + error = res + } + }) + expect(error).to.be(undefined) + return result + } + function exportfunc(link){ + var exportresults = [] + $.ajaxSetup({ + async:false + }) + $.get(link+"/export/html",function(data){ + var start = data.indexOf("") + var end = data.indexOf("") + var html = data.substr(start+6,end-start-6) + exportresults.push(["html",html]) + }) + $.get(link+"/export/txt",function(data){ + exportresults.push(["txt",data]) + }) + return exportresults + } + + it("import a pad with newlines from txt", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var textWithNewLines = 'imported text\nnewline' + importrequest(textWithNewLines,importurl,"txt") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('imported text\nnewline\n
\n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be("imported text
newline

") + expect(results[1][1]).to.be("imported text\nnewline\n\n") + done() + }) + it("import a pad with newlines from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithNewLines = 'htmltext
newline' + importrequest(htmlWithNewLines,importurl,"html") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('htmltext\nnewline\n
\n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be("htmltext
newline

") + expect(results[1][1]).to.be("htmltext\nnewline\n\n") + done() + }) + it("import a pad with attributes from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithNewLines = 'htmltext
newline' + importrequest(htmlWithNewLines,importurl,"html") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('htmltext\nnewline\n
\n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('htmltext
newline

') + expect(results[1][1]).to.be('htmltext\nnewline\n\n') + done() + }) + it("import a pad with bullets from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
  • bullet line 1
  • bullet line 2
    • bullet2 line 1
    • bullet2 line 2
' + importrequest(htmlWithBullets,importurl,"html") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('\ +
  • bullet line 1
\n\ +
  • bullet line 2
\n\ +
  • bullet2 line 1
\n\ +
  • bullet2 line 2
\n\ +
\n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('
  • bullet line 1
  • bullet line 2
    • bullet2 line 1
    • bullet2 line 2

') + expect(results[1][1]).to.be('\t* bullet line 1\n\t* bullet line 2\n\t\t* bullet2 line 1\n\t\t* bullet2 line 2\n\n') + done() + }) + it("import a pad with bullets and newlines from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
  • bullet line 1

  • bullet line 2
    • bullet2 line 1

    • bullet2 line 2
' + importrequest(htmlWithBullets,importurl,"html") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('\ +
  • bullet line 1
\n\ +
\n\ +
  • bullet line 2
\n\ +
  • bullet2 line 1
\n\ +
\n\ +
  • bullet2 line 2
\n\ +
\n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('
  • bullet line 1

  • bullet line 2
    • bullet2 line 1

    • bullet2 line 2

') + expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t* bullet2 line 2\n\n') + done() + }) + it("import a pad with bullets and newlines and attributes from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
  • bullet line 1

  • bullet line 2
    • bullet2 line 1

        • bullet4 line 2 bisu
        • bullet4 line 2 bs
        • bullet4 line 2 uuis
' + importrequest(htmlWithBullets,importurl,"html") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('\ +
  • bullet line 1
\n\
\n\ +
  • bullet line 2
\n\ +
  • bullet2 line 1
\n
\n\ +
  • bullet4 line 2 bisu
\n\ +
  • bullet4 line 2 bs
\n\ +
  • bullet4 line 2 uuis
\n\ +
\n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('
  • bullet line 1

  • bullet line 2
    • bullet2 line 1

        • bullet4 line 2 bisu
        • bullet4 line 2 bs
        • bullet4 line 2 uuis

') + expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\n') + done() + }) + + + //RESULT IS WRONG AT THE LAST LINE + xit("import a pad with 8 levels of bullets and newlines and attributes from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
  • bullet line 1

  • bullet line 2
    • bullet2 line 1

        • bullet4 line 2 bisu
        • bullet4 line 2 bs
        • bullet4 line 2 uuis
                • foo
                • foobar bs
          • foobar
    ' + importrequest(htmlWithBullets,importurl,"html") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('\ +
    • bullet line 1
    \n\
    \n\ +
    • bullet line 2
    \n\ +
    • bullet2 line 1
    \n
    \n\ +
    • bullet4 line 2 bisu
    \n\ +
    • bullet4 line 2 bs
    \n\ +
    • bullet4 line 2 uuis
    \n\ +
    • foo
    \n\ +
    • foobar bs
    \n\ +
    • foobar
    \n\ +
    \n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('
    • bullet line 1

    • bullet line 2
      • bullet2 line 1

          • bullet4 line 2 bisu
          • bullet4 line 2 bs
          • bullet4 line 2 uuis
                  • foo
                  • foobar bs
                  • foobar

    ') + expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\t\t\t\t\t\t\t\t* foo\n\t\t\t\t\t\t\t\t* foobar bs\n\t\t\t\t\t* foobar\n\n') + done() + }) + + xit("import a pad with indents from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithIndents = '
    • indent line 1
    • indent line 2
      • indent2 line 1
      • indent2 line 2
    ' + importrequest(htmlWithIndents,importurl,"html") + console.error(getinnertext()) + expect(getinnertext()).to.be('\ +
    • indent line 1
    \n\ +
    • indent line 2
    \n\ +
    • indent2 line 1
    \n\ +
    • indent2 line 2
    \n\ +
    \n') + var results = exportfunc(helper.padChrome$.window.location.href) + console.error(results[0][1]) + expect(results[0][1]).to.be('
    • indent line 1
    • indent line 2
      • indent2 line 1
      • indent2 line 2
    ') + expect(results[1][1]).to.be('') + done() + }) + xit("import a pad with indented lists and newlines from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithIndents = '
    • indent line 1

    • indent 10 line 2
      • indent 2 times line 1

      • indent 2 times line 2
    ' + importrequest(htmlWithIndents,importurl,"html") + expect(getinnertext()).to.be('\ +
    • indent line 1
    \n\ +
    \n\ +
    • indent 10 line 2
    \n\ +
    • indent 2 times line 1
    \n\ +
    \n\ +
    • indent 2 times line 2
    \n\ +
    \n') + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('') + expect(results[1][1]).to.be('') + done() + }) + xit("import a pad with ordered lists from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
    1. number 1 line 1
    1. number 2 line 2
    ' + importrequest(htmlWithBullets,importurl,"html") + -console.error(getinnertext()) + expect(getinnertext()).to.be('\ +
    1. number 1 line 1
    \n\ +
    1. number 2 line 2
    \n\ +
    \n') + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('
    1. number 1 line 1
    1. number 2 line 2
    ') + expect(results[1][1]).to.be('') + done() + }) + xit("import a pad with ordered lists and newlines from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
    1. number 9 line 1

    1. number 10 line 2
      1. number 2 times line 1

      1. number 2 times line 2
    ' + importrequest(htmlWithBullets,importurl,"html") + expect(getinnertext()).to.be('\ +
    1. number 9 line 1
    \n\ +
    \n\ +
    1. number 10 line 2
    \n\ +
    1. number 2 times line 1
    \n\ +
    \n\ +
    1. number 2 times line 2
    \n\ +
    \n') + var results = exportfunc(helper.padChrome$.window.location.href) + console.error(results) + done() + }) + xit("import a pad with nested ordered lists and attributes and newlines from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
    1. bold strikethrough italics underline line 1bold

    1. number 10 line 2
      1. number 2 times line 1

      1. number 2 times line 2
    ' + importrequest(htmlWithBullets,importurl,"html") + expect(getinnertext()).to.be('\ +
    1. bold strikethrough italics underline line 1bold
    \n\ +
    \n\ +
    1. number 10 line 2
    \n\ +
    1. number 2 times line 1
    \n\ +
    \n\ +
    1. number 2 times line 2
    \n\ +
    \n') + var results = exportfunc(helper.padChrome$.window.location.href) + console.error(results) + done() + }) +}) From d71b11f4b2845f82018184ad0a2383d2147fcf8c Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 28 Dec 2014 02:31:26 +0100 Subject: [PATCH 5/8] fix export of lists with bullets;
  • are closed before the next list starts. also, when closing, ensure that list-items are not nested --- src/node/utils/ExportHtml.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index 85d5e7a29..3e42b88b1 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -328,6 +328,9 @@ 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('
  • ') + } lists.push([line.listLevel, line.listTypeName]); if(line.listTypeName == "number") { @@ -363,7 +366,7 @@ function getHTMLFromAtext(pad, atext, authorColors) pieces.push('

    '); } }*/ - 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) { @@ -382,15 +385,23 @@ function getHTMLFromAtext(pad, atext, authorColors) } else//outside any list { + if(lists.length > 0){ + if(lists[lists.length - 1][1] == "number"){ + pieces.push(''); + } else { + pieces.push('
'); + } + lists.length--; + } while (lists.length > 0)//if was in a list: close it before { if(lists[lists.length - 1][1] == "number") { - pieces.push(''); + pieces.push(''); } else { - pieces.push(''); + pieces.push(''); } lists.length--; } From 6ca2c91fdf412358ffb71a1bf298bb8705b96308 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 28 Dec 2014 02:32:53 +0100 Subject: [PATCH 6/8] close and open lists according to the actual line.listLevel --- src/node/utils/ExportHtml.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index 3e42b88b1..bb29b34d3 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -332,12 +332,23 @@ function getHTMLFromAtext(pad, atext, authorColors) pieces.push('') } 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('
    ')) + } pieces.push('
    1. ', lineContent || '
      '); } else { + if(toOpen > 0){ + pieces.push(new Array(toOpen + 1).join('
        ')) + } pieces.push('
        • ', lineContent || '
          '); } } @@ -383,28 +394,19 @@ function getHTMLFromAtext(pad, atext, authorColors) pieces.push('
        • ', lineContent || '
          '); } } - else//outside any list + else//outside any list, need to close line.listLevel of lists { if(lists.length > 0){ if(lists[lists.length - 1][1] == "number"){ pieces.push('
    '); + pieces.push(new Array(lists[lists.length - 1][0]).join('
')) } else { pieces.push(''); + pieces.push(new Array(lists[lists.length - 1][0]).join('')) } - lists.length--; - } - while (lists.length > 0)//if was in a list: close it before - { - if(lists[lists.length - 1][1] == "number") - { - pieces.push(''); - } - else - { - pieces.push(''); - } - lists.length--; } + lists = [] + var lineContentFromHook = hooks.callAllStr("getLineHTMLForExport", { line: line, From 8e280f46c1d96adf5b32202dd455984c041a8a56 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Mon, 29 Dec 2014 16:25:41 +0100 Subject: [PATCH 7/8] fix bullet test case, remove indent-testcases because they are in separate file --- tests/frontend/specs/importexport.js | 63 +++++++++++----------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/tests/frontend/specs/importexport.js b/tests/frontend/specs/importexport.js index 5c642ae35..4ba8d57b7 100644 --- a/tests/frontend/specs/importexport.js +++ b/tests/frontend/specs/importexport.js @@ -140,10 +140,29 @@ describe("import functionality", function(){ expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\n') done() }) - - - //RESULT IS WRONG AT THE LAST LINE - xit("import a pad with 8 levels of bullets and newlines and attributes from html", function(done){ + it("import a pad with nested bullets from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithBullets = '
  • bullet line 1
  • bullet line 2
    • bullet2 line 1
        • bullet4 line 2
        • bullet4 line 2
        • bullet4 line 2
      • bullet3 line 1
  • bullet2 line 1
' + importrequest(htmlWithBullets,importurl,"html") + var oldtext=getinnertext() + helper.waitFor(function(){ + return oldtext != getinnertext() +// return expect(getinnertext()).to.be('\ +//
  • bullet line 1
\n\ +//
  • bullet line 2
\n\ +//
  • bullet2 line 1
\n\ +//
  • bullet4 line 2
\n\ +//
  • bullet4 line 2
\n\ +//
  • bullet4 line 2
\n\ +//
\n') + }) + + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('
  • bullet line 1
  • bullet line 2
    • bullet2 line 1
        • bullet4 line 2
        • bullet4 line 2
        • bullet4 line 2
      • bullet3 line 1
  • bullet2 line 1

') + expect(results[1][1]).to.be('\t* bullet line 1\n\t* bullet line 2\n\t\t* bullet2 line 1\n\t\t\t\t* bullet4 line 2\n\t\t\t\t* bullet4 line 2\n\t\t\t\t* bullet4 line 2\n\t\t\t* bullet3 line 1\n\t* bullet2 line 1\n\n') + done() + }) + it("import a pad with 8 levels of bullets and newlines and attributes from html", function(done){ var importurl = helper.padChrome$.window.location.href+'/import' var htmlWithBullets = '
  • bullet line 1

  • bullet line 2
    • bullet2 line 1

        • bullet4 line 2 bisu
        • bullet4 line 2 bs
        • bullet4 line 2 uuis
                • foo
                • foobar bs
          • foobar
    ' importrequest(htmlWithBullets,importurl,"html") @@ -161,45 +180,11 @@ describe("import functionality", function(){
    \n') }) var results = exportfunc(helper.padChrome$.window.location.href) - expect(results[0][1]).to.be('
    • bullet line 1

    • bullet line 2
      • bullet2 line 1

          • bullet4 line 2 bisu
          • bullet4 line 2 bs
          • bullet4 line 2 uuis
                  • foo
                  • foobar bs
                  • foobar

    ') + expect(results[0][1]).to.be('
    • bullet line 1

    • bullet line 2
      • bullet2 line 1

          • bullet4 line 2 bisu
          • bullet4 line 2 bs
          • bullet4 line 2 uuis
                  • foo
                  • foobar bs
            • foobar

    ') expect(results[1][1]).to.be('\t* bullet line 1\n\n\t* bullet line 2\n\t\t* bullet2 line 1\n\n\t\t\t\t* bullet4 line 2 bisu\n\t\t\t\t* bullet4 line 2 bs\n\t\t\t\t* bullet4 line 2 uuis\n\t\t\t\t\t\t\t\t* foo\n\t\t\t\t\t\t\t\t* foobar bs\n\t\t\t\t\t* foobar\n\n') done() }) - xit("import a pad with indents from html", function(done){ - var importurl = helper.padChrome$.window.location.href+'/import' - var htmlWithIndents = '
    • indent line 1
    • indent line 2
      • indent2 line 1
      • indent2 line 2
    ' - importrequest(htmlWithIndents,importurl,"html") - console.error(getinnertext()) - expect(getinnertext()).to.be('\ -
    • indent line 1
    \n\ -
    • indent line 2
    \n\ -
    • indent2 line 1
    \n\ -
    • indent2 line 2
    \n\ -
    \n') - var results = exportfunc(helper.padChrome$.window.location.href) - console.error(results[0][1]) - expect(results[0][1]).to.be('
    • indent line 1
    • indent line 2
      • indent2 line 1
      • indent2 line 2
    ') - expect(results[1][1]).to.be('') - done() - }) - xit("import a pad with indented lists and newlines from html", function(done){ - var importurl = helper.padChrome$.window.location.href+'/import' - var htmlWithIndents = '
    • indent line 1

    • indent 10 line 2
      • indent 2 times line 1

      • indent 2 times line 2
    ' - importrequest(htmlWithIndents,importurl,"html") - expect(getinnertext()).to.be('\ -
    • indent line 1
    \n\ -
    \n\ -
    • indent 10 line 2
    \n\ -
    • indent 2 times line 1
    \n\ -
    \n\ -
    • indent 2 times line 2
    \n\ -
    \n') - var results = exportfunc(helper.padChrome$.window.location.href) - expect(results[0][1]).to.be('') - expect(results[1][1]).to.be('') - done() - }) xit("import a pad with ordered lists from html", function(done){ var importurl = helper.padChrome$.window.location.href+'/import' var htmlWithBullets = '
    1. number 1 line 1
    1. number 2 line 2
    ' From 6e4e034e425523b9f0e2bf22674d8d36082fcbbd Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Mon, 29 Dec 2014 16:27:40 +0100 Subject: [PATCH 8/8] 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 = []