diff options
| -rw-r--r-- | lib/writers/markdown-writer.js | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js index b63d104..148d963 100644 --- a/lib/writers/markdown-writer.js +++ b/lib/writers/markdown-writer.js @@ -1,9 +1,10 @@ - var _ = require("underscore"); + function mdElement(start, end) { - if (end === undefined) + if (end === undefined) { end = start; + } this.open = function(attrs) { return start; @@ -17,6 +18,7 @@ function mdElement(start, end) { return this.open(attrs) + this.close(); }; } + function mdLink(link, text) { var attrs = {}; @@ -34,13 +36,14 @@ function mdLink(link, text) { // don't display empty content (this is mainly to remove images with no src data) var content = this.open(attrs) + this.close(); - if(content === "[]()") { + if (content === "[]()") { return ""; } return content; }; } + function mdList() { this.open = function(attrs) { return attrs.indent > -1 ? "\n" : ""; @@ -54,6 +57,7 @@ function mdList() { return this.open(attrs) + this.close(); }; } + function mdListItem() { this.open = function(attrs) { var output = ""; @@ -110,21 +114,20 @@ function mdWriter() { } function open(tagName, attributes) { - if(htmlmd[tagName]) { + if (htmlmd[tagName]) { attributes = attributes || {}; - if(tagName === "li") { + if (tagName === "li") { attributes.indent = list.indent; attributes.type = list.type; attributes.count = ++list.count; - } - else if(isList(tagName)) { + } else if (isList(tagName)) { attributes.indent = list.indent; } fragments.push(htmlmd[tagName].open(attributes)); - if(isList(tagName)) { + if (isList(tagName)) { listStack.push(_.clone(list)); list.type = tagName; @@ -135,8 +138,8 @@ function mdWriter() { } function close(tagName) { - if(htmlmd[tagName]) { - if(isList(tagName)) { + if (htmlmd[tagName]) { + if (isList(tagName)) { list = listStack.pop(); } @@ -145,7 +148,7 @@ function mdWriter() { } function selfClosing(tagName, attributes) { - if(htmlmd[tagName]) { + if (htmlmd[tagName]) { fragments.push(htmlmd[tagName].empty(attributes)); } } @@ -173,4 +176,4 @@ function mdWriter() { }; } -exports.writer = mdWriter;
\ No newline at end of file +exports.writer = mdWriter; |
