diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-04 19:02:25 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-04 19:02:25 +0000 |
| commit | cdffcd49c9d9bda72974e079ba5a9275f5ae719a (patch) | |
| tree | 1d4281d84ebabf1b90ebfb7b1945c755100cd4d8 /lib | |
| parent | 65244218366555756c068b1b8edb37515f6f4e9b (diff) | |
Normalise formatting in markdown-writer.js
Diffstat (limited to 'lib')
| -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; |
