From e1c683be3f47a350e6bac3146507bd2d7d7478f6 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Mon, 29 Dec 2014 16:12:07 +0100 Subject: [PATCH 1/2] differentiate between indents and bullets in unordered lists --- src/static/js/contentcollector.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index a378d2c2e..b33b1e6e8 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -518,9 +518,24 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class } if (tname == "ul" || tname == "ol") { - var type; + var type = node.attribs.class; var rr = cls && /(?:^| )list-([a-z]+[12345678])\b/.exec(cls); - type = rr && rr[1] || (tname == "ul" ? "bullet" : "number") + String(Math.min(_MAX_LIST_LEVEL, (state.listNesting || 0) + 1)); + // lists do not need to have a type, so before we make a wrong guess, check if we find a better hint within the node's children + if(!rr && !type){ + for (var i in node.children){ + if(node.children[i] && node.children[i].name=='ul'){ + type = node.children[i].attribs.class + if(type){ + break + } + } + } + } + if(rr && rr[1]){ + type = rr[1] + } else { + type = (tname == "ul" ? (type.match("indent") || node.attribs.class && node.attribs.class.match("indent") ? "indent" : "bullet") : "number") + String(Math.min(_MAX_LIST_LEVEL, (state.listNesting || 0) + 1)); + } oldListTypeOrNull = (_enterList(state, type) || 'none'); } else if ((tname == "div" || tname == "p") && cls && cls.match(/(?:^| )ace-line\b/)) From a36d6f36a07abb69a8e51b9cfe66d7ea91622e51 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Mon, 29 Dec 2014 16:12:46 +0100 Subject: [PATCH 2/2] add testcase for import of intended lists --- tests/frontend/specs/importindents.js | 111 ++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/frontend/specs/importindents.js diff --git a/tests/frontend/specs/importindents.js b/tests/frontend/specs/importindents.js new file mode 100644 index 000000000..db2b33b0d --- /dev/null +++ b/tests/frontend/specs/importindents.js @@ -0,0 +1,111 @@ +describe("import indents 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 indents from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithIndents = '' + importrequest(htmlWithIndents,importurl,"html") + helper.waitFor(function(){ + return expect(getinnertext()).to.be('\ +\n\ +\n\ +\n\ +\n\ +
\n') + }) + var results = exportfunc(helper.padChrome$.window.location.href) + expect(results[0][1]).to.be('
') + expect(results[1][1]).to.be('\tindent line 1\n\tindent line 2\n\t\tindent2 line 1\n\t\tindent2 line 2\n\n') + done() + }) + + it("import a pad with indented lists and newlines from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithIndents = '

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


') + expect(results[1][1]).to.be('\tindent line 1\n\n\tindent 1 line 2\n\t\tindent 2 times line 1\n\n\t\tindent 2 times line 2\n\n') + done() + }) + it("import a pad with 8 levels of indents and newlines and attributes from html", function(done){ + var importurl = helper.padChrome$.window.location.href+'/import' + var htmlWithIndents = '