added ordered list support to HTML exporter. Was not that easy :). Also added a few comments to help the next guy

This commit is contained in:
Jean-Tiare Le Bigot 2011-12-09 19:49:46 +01:00
parent 4715900eeb
commit 7f34334eaf

View file

@ -306,13 +306,14 @@ function getHTMLFromAtext(pad, atext)
// People might use weird indenting, e.g. skip a level, // People might use weird indenting, e.g. skip a level,
// 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
var lists = []; // e.g. [[1,'bullet'], [3,'bullet'], ...] var lists = []; // e.g. [[1,'bullet'], [3,'bullet'], ...]
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 = getLineHTML(line.text, line.aline); var lineContent = getLineHTML(line.text, line.aline);
if (line.listLevel || lists.length > 0) if (line.listLevel)//If we are inside a list
{ {
// do list stuff // do list stuff
var whichList = -1; // index into lists or -1 var whichList = -1; // index into lists or -1
@ -328,41 +329,89 @@ function getHTMLFromAtext(pad, atext)
} }
} }
if (whichList >= lists.length) if (whichList >= lists.length)//means we are on a deeper level of indentation than the previous line
{ {
lists.push([line.listLevel, line.listTypeName]); lists.push([line.listLevel, line.listTypeName]);
if(line.listTypeName == "number")
{
pieces.push('<ol><li>', lineContent || '<br>');
}
else
{
pieces.push('<ul><li>', lineContent || '<br>'); pieces.push('<ul><li>', lineContent || '<br>');
} }
else if (whichList == -1) }
//the following code *seems* dead after my patch.
//I keep it just in case I'm wrong...
/*else if (whichList == -1)//means we are not inside a list
{ {
if (line.text) if (line.text)
{ {
console.log('trace 1');
// non-blank line, end all lists // non-blank line, end all lists
pieces.push(new Array(lists.length + 1).join('</li></ul\n>')); if(line.listTypeName == "number")
{
pieces.push(new Array(lists.length + 1).join('</li></ol>'));
}
else
{
pieces.push(new Array(lists.length + 1).join('</li></ul>'));
}
lists.length = 0; lists.length = 0;
pieces.push(lineContent, '<br>'); pieces.push(lineContent, '<br>');
} }
else else
{ {
console.log('trace 2');
pieces.push('<br><br>'); pieces.push('<br><br>');
} }
} }*/
else else//means we are getting closer to the lowest level of indentation
{ {
while (whichList < lists.length - 1) while (whichList < lists.length - 1)
{
if(lists[lists.length - 1][1] == "number")
{
pieces.push('</li></ol>');
}
else
{ {
pieces.push('</li></ul>'); pieces.push('</li></ul>');
}
lists.length--; lists.length--;
} }
pieces.push('</li><li>', lineContent || '<br>'); pieces.push('</li><li>', lineContent || '<br>');
} }
} }
else//outside any list
{
while (lists.length > 0)//if was in a list: close it before
{
if(lists[lists.length - 1][1] == "number")
{
pieces.push('</li></ol>');
}
else else
{ {
pieces.push('</li></ul>');
}
lists.length--;
}
pieces.push(lineContent, '<br>'); pieces.push(lineContent, '<br>');
} }
} }
pieces.push(new Array(lists.length + 1).join('</li></ul>'));
for (var k = lists.length - 1; k >= 0; k--)
{
if(lists[k][1] == "number")
{
pieces.push('</li></ol>');
}
else
{
pieces.push('</li></ul>');
}
}
return pieces.join(''); return pieces.join('');
} }