| 436 | |
| 437 | // handle <ul> or <ol> nodes |
| 438 | var recursiveListFormat = function(listNode, tablevel){ |
| 439 | var _html = ''; |
| 440 | var _subnodes = listNode.childNodes; |
| 441 | tablevel++; |
| 442 | // tab out and add the <ul> or <ol> html piece |
| 443 | _html += _repeat('\t', tablevel-1) + listNode.outerHTML.substring(0, 4); |
| 444 | forEach(_subnodes, function (index, node) { |
| 445 | /* istanbul ignore next: browser catch */ |
| 446 | var nodeName = node.nodeName.toLowerCase(); |
| 447 | if (nodeName === '#comment') { |
| 448 | _html += '<!--' + node.nodeValue + '-->'; |
| 449 | return; |
| 450 | } |
| 451 | if (nodeName === '#text') { |
| 452 | _html += node.textContent; |
| 453 | return; |
| 454 | } |
| 455 | /* istanbul ignore next: not tested, and this was original code -- so not wanting to possibly cause an issue, leaving it... */ |
| 456 | if(!node.outerHTML) { |
| 457 | // no html to add |
| 458 | return; |
| 459 | } |
| 460 | if(nodeName === 'ul' || nodeName === 'ol') { |
| 461 | _html += '\n' + recursiveListFormat(node, tablevel); |
| 462 | } |
| 463 | else { |
| 464 | // no reformatting within this subnode, so just do the tabing... |
| 465 | _html += '\n' + _repeat('\t', tablevel) + node.outerHTML; |
| 466 | } |
| 467 | }); |
| 468 | // now add on the </ol> or </ul> piece |
| 469 | _html += '\n' + _repeat('\t', tablevel-1) + listNode.outerHTML.substring(listNode.outerHTML.lastIndexOf('<')); |
| 470 | return _html; |
| 471 | }; |
| 472 | // handle formating of something like: |
| 473 | // <ol><!--First comment--> |
| 474 | // <li>Test Line 1<!--comment test list 1--></li> |