diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-04 21:52:47 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-04 21:52:47 +0000 |
| commit | d656dba638cd0755f8043b60d7ab2c84b9953e30 (patch) | |
| tree | 84c167939eeed223ecafb4272677a0f727ee007b | |
| parent | eb704f552257042e264cc3d9c4dea974aa2b15e2 (diff) | |
Handle list state immediately
| -rw-r--r-- | lib/writers/markdown-writer.js | 24 |
1 files changed, 13 insertions, 11 deletions
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); } |
