summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-02-04 21:16:41 +0000
committerMichael Williamson <mike@zwobble.org>2015-02-04 21:16:41 +0000
commitefcb9a9ae40c36c42af2711d3babb790cd9c470b (patch)
treebbcd2d111f8715a6cbb28a97c5d8de9c6c6d22ad
parent7b0edd554a0740c479db76dda531e5320a33b14c (diff)
Don't use new to create markdown elements
-rw-r--r--lib/writers/markdown-writer.js68
1 files changed, 38 insertions, 30 deletions
diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js
index ff2d4b4..1866be6 100644
--- a/lib/writers/markdown-writer.js
+++ b/lib/writers/markdown-writer.js
@@ -6,56 +6,62 @@ function markdownElement(start, end) {
end = start;
}
- this.open = function(attrs) {
+ function open(attrs) {
return start;
- };
+ }
- this.close = function() {
+ function close() {
return end;
- };
+ }
+
+ return {open: open, close: close};
}
function markdownLink() {
var href;
- this.open = function(attributes) {
+ function open(attributes) {
href = attributes.href;
return "[";
- };
+ }
- this.close = function() {
+ function close() {
return "](" + (href || "") + ")";
- };
+ }
- this.anchorPosition = "before";
+ return {open: open, close: close, anchorPosition: "before"};
}
function markdownImage() {
- this.open = function(attributes) {
+ function open(attributes) {
var src = attributes.src || "";
var altText = attributes.alt || "";
if (src || altText) {
return "![" + altText + "](" + src + ")";
}
- };
+ }
- this.close = function() {
+ function close() {
return "";
- };
+ }
+
+ return {open: open, close: close};
}
function markdownList() {
- this.open = function(attrs) {
+ function open(attrs) {
return attrs.indent > -1 ? "\n" : "";
- };
+ }
- this.close = function(attrs) {
+ function close(attrs) {
return attrs.indent > -1 ? "" : "\n";
- };
+ }
+
+ return {open: open, close: close};
}
function markdownListItem() {
- this.open = function(attrs) {
+ function open(attrs) {
var output = "";
for(var i = 0; i < attrs.indent; ++i) {
@@ -63,11 +69,13 @@ function markdownListItem() {
}
return output + (attrs.type === "ul" ? "-" : attrs.count + ".") + " ";
- };
+ }
- this.close = function() {
+ function close() {
return "\n";
- };
+ }
+
+ return {open: open, close: close};
}
// map HTML tags to Markdown syntax
@@ -75,15 +83,15 @@ var htmlmarkdown = {
// paragraphs elements use three line feeds to close
// this prevents them being caught by collapsing list elements in `asString`
// while still allowing them to be collapsed when multiple empty lines are removed
- "p": new markdownElement("", "\n\n\n"),
- "br": new markdownElement("", " \n"),
- "ul": new markdownList(),
- "ol": new markdownList(),
- "li": new markdownListItem(),
- "strong": new markdownElement("**"),
- "em": new markdownElement("*"),
- "a": new markdownLink(),
- "img": new markdownImage(),
+ "p": markdownElement("", "\n\n\n"),
+ "br": markdownElement("", " \n"),
+ "ul": markdownList(),
+ "ol": markdownList(),
+ "li": markdownListItem(),
+ "strong": markdownElement("**"),
+ "em": markdownElement("*"),
+ "a": markdownLink(),
+ "img": markdownImage(),
};
(function() {