From c5d83a17321e0813a8f3a43317f52ed86e183154 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 4 Feb 2015 21:39:08 +0000 Subject: Pass list state as second argument instead of mutating attributes --- lib/writers/markdown-writer.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'lib') 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") { -- cgit v1.2.3