listItem.js 670 B

12345678910111213141516171819202122232425
  1. showdown.subParser('makeMarkdown.listItem', function (node, globals) {
  2. 'use strict';
  3. var listItemTxt = '';
  4. var children = node.childNodes,
  5. childrenLenght = children.length;
  6. for (var i = 0; i < childrenLenght; ++i) {
  7. listItemTxt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  8. }
  9. // if it's only one liner, we need to add a newline at the end
  10. if (!/\n$/.test(listItemTxt)) {
  11. listItemTxt += '\n';
  12. } else {
  13. // it's multiparagraph, so we need to indent
  14. listItemTxt = listItemTxt
  15. .split('\n')
  16. .join('\n ')
  17. .replace(/^ {4}$/gm, '')
  18. .replace(/\n\n+/g, '\n\n');
  19. }
  20. return listItemTxt;
  21. });