diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-04 21:39:08 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-04 21:39:08 +0000 |
| commit | c5d83a17321e0813a8f3a43317f52ed86e183154 (patch) | |
| tree | 5a143c980f7b79dbe7cfe5b2e6857ebc4530b062 | |
| parent | 48b0924ce891aed19299d03a8f67ab0f82bd3224 (diff) | |
Pass list state as second argument instead of mutating attributes
| -rw-r--r-- | lib/writers/markdown-writer.js | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js index cdbfc78..eb3ada5 100644 --- a/lib/writers/markdown-writer.js +++ b/lib/writers/markdown-writer.js @@ -27,16 +27,16 @@ function markdownImage(attributes) { } } -function markdownList(attributes) { +function markdownList(attributes, list) { return { - start: attributes.indent > -1 ? "\n" : "", - end: attributes.indent > -1 ? "" : "\n" + start: list.indent > -1 ? "\n" : "", + end: list.indent > -1 ? "" : "\n" }; } -function markdownListItem(attributes) { - var start = repeatString("\t", Math.max(attributes.indent, 0)) + - (attributes.type === "ul" ? "-" : attributes.count + ".") + " "; +function markdownListItem(attributes, list) { + var start = repeatString("\t", Math.max(list.indent, 0)) + + (list.type === "ul" ? "-" : list.count + ".") + " "; return {start: start, end: "\n"}; } @@ -84,17 +84,13 @@ function markdownWriter() { attributes = attributes || {}; if (tagName === "li") { - attributes.indent = list.indent; - attributes.type = list.type; - attributes.count = ++list.count; - } else if (isList(tagName)) { - attributes.indent = list.indent; + list.count++; } var idHasBeenWritten = false; var createElement = htmlmarkdown[tagName] || function() { return {}; }; - var element = createElement(attributes); + var element = createElement(attributes, list); elementStack.push({end: element.end, list: list}); if (element.anchorPosition === "before") { |
