From d656dba638cd0755f8043b60d7ab2c84b9953e30 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 4 Feb 2015 21:52:47 +0000 Subject: Handle list state immediately --- lib/writers/markdown-writer.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js index 9f09e34..5a6f5e0 100644 --- a/lib/writers/markdown-writer.js +++ b/lib/writers/markdown-writer.js @@ -29,8 +29,8 @@ function markdownImage(attributes) { function markdownList(attributes, list) { return { - start: list.indent > -1 ? "\n" : "", - end: list.indent > -1 ? "" : "\n" + start: list.indent > 0 ? "\n" : "", + end: list.indent > 0 ? "" : "\n" }; } @@ -84,11 +84,21 @@ function markdownWriter() { function open(tagName, attributes) { attributes = attributes || {}; + var parentElementList = list; + + if (isList(tagName)) { + list = { + type: tagName, + indent: list.indent + 1, + count: 0 + }; + } + var idHasBeenWritten = false; var createElement = htmlmarkdown[tagName] || function() { return {}; }; var element = createElement(attributes, list); - elementStack.push({end: element.end, list: list}); + elementStack.push({end: element.end, list: parentElementList}); if (element.anchorPosition === "before") { writeAnchor(attributes); @@ -96,14 +106,6 @@ function markdownWriter() { } fragments.push(element.start || ""); - - if (isList(tagName)) { - list = { - type: tagName, - indent: list.indent + 1, - count: 0 - }; - } if (!idHasBeenWritten) { writeAnchor(attributes); } -- cgit v1.2.3