mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
export: txt import include correct OL prefix (#4086)
Includes test coverage Final part of solving https://github.com/ether/etherpad-lite/issues/3447
This commit is contained in:
parent
423be7f081
commit
aff93d24dd
2 changed files with 55 additions and 5 deletions
|
@ -190,7 +190,12 @@ function getTXTFromAtext(pad, atext, authorColors)
|
||||||
// so we want to do something reasonable there. We also
|
// so we want to do something reasonable there. We also
|
||||||
// want to deal gracefully with blank lines.
|
// want to deal gracefully with blank lines.
|
||||||
// => keeps track of the parents level of indentation
|
// => keeps track of the parents level of indentation
|
||||||
|
|
||||||
|
var listNumbers = {};
|
||||||
|
var prevListLevel;
|
||||||
|
|
||||||
for (var i = 0; i < textLines.length; i++) {
|
for (var i = 0; i < textLines.length; i++) {
|
||||||
|
|
||||||
var line = _analyzeLine(textLines[i], attribLines[i], apool);
|
var line = _analyzeLine(textLines[i], attribLines[i], apool);
|
||||||
var lineContent = getLineTXT(line.text, line.aline);
|
var lineContent = getLineTXT(line.text, line.aline);
|
||||||
|
|
||||||
|
@ -198,15 +203,49 @@ function getTXTFromAtext(pad, atext, authorColors)
|
||||||
lineContent = "* " + lineContent; // add a bullet
|
lineContent = "* " + lineContent; // add a bullet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (line.listTypeName !== "number") {
|
||||||
|
// We're no longer in an OL so we can reset counting
|
||||||
|
for (var key in listNumbers) {
|
||||||
|
delete listNumbers[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (line.listLevel > 0) {
|
if (line.listLevel > 0) {
|
||||||
for (var j = line.listLevel - 1; j >= 0; j--) {
|
for (var j = line.listLevel - 1; j >= 0; j--) {
|
||||||
pieces.push('\t');
|
pieces.push('\t'); // tab indent list numbers..
|
||||||
|
if(!listNumbers[line.listLevel]){
|
||||||
|
listNumbers[line.listLevel] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.listTypeName == "number") {
|
if (line.listTypeName == "number") {
|
||||||
pieces.push(line.listLevel + ". ");
|
/*
|
||||||
// This is bad because it doesn't truly reflect what the user
|
* listLevel == amount of indentation
|
||||||
// sees because browsers do magic on nested <ol><li>s
|
* listNumber(s) == item number
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* 1. foo
|
||||||
|
* 1.1 bah
|
||||||
|
* 2. latte
|
||||||
|
* 2.1 latte
|
||||||
|
*
|
||||||
|
* To handle going back to 2.1 when prevListLevel is lower number
|
||||||
|
* than current line.listLevel then reset the object value
|
||||||
|
*/
|
||||||
|
if(line.listLevel < prevListLevel){
|
||||||
|
delete listNumbers[prevListLevel];
|
||||||
|
}
|
||||||
|
|
||||||
|
listNumbers[line.listLevel]++;
|
||||||
|
if(line.listLevel > 1){
|
||||||
|
var x = 1;
|
||||||
|
while(x <= line.listLevel-1){
|
||||||
|
pieces.push(listNumbers[x]+".")
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pieces.push(listNumbers[line.listLevel]+". ")
|
||||||
|
prevListLevel = line.listLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
pieces.push(lineContent, '\n');
|
pieces.push(lineContent, '\n');
|
||||||
|
|
|
@ -36,8 +36,19 @@ var testImports = {
|
||||||
expectedHTML: '<!DOCTYPE HTML><html><body><ul class="bullet"><li>FOO</ul><br></body></html>',
|
expectedHTML: '<!DOCTYPE HTML><html><body><ul class="bullet"><li>FOO</ul><br></body></html>',
|
||||||
expectedText: '\t* FOO\n\n'
|
expectedText: '\t* FOO\n\n'
|
||||||
},
|
},
|
||||||
|
"prefixcorrectlinenumber":{
|
||||||
|
input: '<html><body><ol><li>should be 1</li><li>should be 2</li></ol></body></html>',
|
||||||
|
expectedHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1</li><li>should be 2</ol><br></body></html>',
|
||||||
|
expectedText: '\t1. should be 1\n\t2. should be 2\n\n'
|
||||||
|
},
|
||||||
|
"prefixcorrectlinenumbernested":{
|
||||||
|
input: '<html><body><ol><li>should be 1</li><ol><li>foo</li></ol><li>should be 2</li></ol></body></html>',
|
||||||
|
expectedHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1<ol start="2" class="number"><li>foo</ol><li>should be 2</ol><br></body></html>',
|
||||||
|
expectedText: '\t1. should be 1\n\t\t1.1. foo\n\t2. should be 2\n\n'
|
||||||
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
"prefixcorrectlinenumber #3450":{
|
"prefixcorrectlinenumber when introduced none list item - currently not supported see #3450":{
|
||||||
input: '<html><body><ol><li>should be 1</li>test<li>should be 2</li></ol></body></html>',
|
input: '<html><body><ol><li>should be 1</li>test<li>should be 2</li></ol></body></html>',
|
||||||
expectedHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1</li>test<li>should be 2</li></ol><br></body></html>',
|
expectedHTML: '<!DOCTYPE HTML><html><body><ol start="1" class="number"><li>should be 1</li>test<li>should be 2</li></ol><br></body></html>',
|
||||||
expectedText: '\t1. should be 1\n\ttest\n\t2. should be 2\n\n'
|
expectedText: '\t1. should be 1\n\ttest\n\t2. should be 2\n\n'
|
||||||
|
|
Loading…
Reference in a new issue