From c25983466093e99c625ff11bf750dfbbf4c5f845 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 4 Feb 2015 19:17:52 +0000 Subject: Simplify self-closing tags in markdown --- lib/writers/markdown-writer.js | 39 +++++---------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js index 711f722..f39e018 100644 --- a/lib/writers/markdown-writer.js +++ b/lib/writers/markdown-writer.js @@ -13,10 +13,6 @@ function markdownElement(start, end) { this.close = function() { return end; }; - - this.empty = function(attrs) { - return this.open(attrs) + this.close(); - }; } function markdownLink() { @@ -30,34 +26,20 @@ function markdownLink() { this.close = function() { return "](" + (href || "") + ")"; }; - - this.empty = function(attrs) { - // don't display empty content (this is mainly to remove images with no src data) - return this.open(attrs) + this.close(); - }; } function markdownImage() { this.open = function(attributes) { var src = attributes.src || ""; var altText = attributes.alt || ""; - return "![" + altText + "](" + src + ")"; + if (src || altText) { + return "![" + altText + "](" + src + ")"; + } }; this.close = function() { return ""; }; - - this.empty = function(attrs) { - // don't display empty content (this is mainly to remove images with no src data) - var content = this.open(attrs) + this.close(); - - if (content === "![]()") { - return ""; - } - - return content; - }; } function markdownList() { @@ -68,10 +50,6 @@ function markdownList() { this.close = function(attrs) { return attrs.indent > -1 ? "" : "\n"; }; - - this.empty = function(attrs) { - return this.open(attrs) + this.close(); - }; } function markdownListItem() { @@ -88,10 +66,6 @@ function markdownListItem() { this.close = function() { return "\n"; }; - - this.empty = function(attrs) { - return this.open(attrs) + this.close(); - }; } // map HTML tags to Markdown syntax @@ -164,11 +138,8 @@ function markdownWriter() { } function selfClosing(tagName, attributes) { - attributes = attributes || {}; - - if (htmlmarkdown[tagName]) { - fragments.push(htmlmarkdown[tagName].empty(attributes)); - } + open(tagName, attributes); + close(tagName); } function text(value) { -- cgit v1.2.3