diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-08 20:22:55 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-08 20:22:55 +0000 |
| commit | deee500761d499d4ea50d3e75b1f626268879527 (patch) | |
| tree | 0af943a1089e0b3549a617a663da6735fdf38360 | |
| parent | de53ae77d8696ef9a8c89fc9661c1fb1acdd1ce1 (diff) | |
Ignore anchor tags if href is not set
| -rw-r--r-- | lib/writers/markdown-writer.js | 14 | ||||
| -rw-r--r-- | tests/writers/markdown-writer.tests.js | 14 |
2 files changed, 12 insertions, 16 deletions
diff --git a/lib/writers/markdown-writer.js b/lib/writers/markdown-writer.js index 5908e3b..268b8fb 100644 --- a/lib/writers/markdown-writer.js +++ b/lib/writers/markdown-writer.js @@ -13,11 +13,15 @@ function markdownElement(start, end) { function markdownLink(attributes) { var href = attributes.href || ""; - return { - start: "[", - end: "](" + href + ")", - anchorPosition: "before" - }; + if (href) { + return { + start: "[", + end: "](" + href + ")", + anchorPosition: "before" + }; + } else { + return {}; + } } function markdownImage(attributes) { diff --git a/tests/writers/markdown-writer.tests.js b/tests/writers/markdown-writer.tests.js index 9d3def5..fbf1e61 100644 --- a/tests/writers/markdown-writer.tests.js +++ b/tests/writers/markdown-writer.tests.js @@ -75,22 +75,14 @@ describe('markdown-writer', function() { return assert.equal(writer.asString(), "[Hello](http://example.com)"); }); - test('can generate hyperlinks with missing href attribute', function() { - var writer = mdWriter.writer(); - writer.open("a", {}); - writer.text("Hello"); - writer.close("a"); - return assert.equal(writer.asString(), "[Hello]()"); - }); - - test('can generate hyperlinks with empty attributes', function() { + test('anchor tags without href attribute are treated as ordinary text', function() { var writer = mdWriter.writer(); writer.open("a"); writer.text("Hello"); writer.close("a"); - return assert.equal(writer.asString(), "[Hello]()"); + return assert.equal(writer.asString(), "Hello"); }); - + test('elements with IDs have anchor tags with IDs appended to start of markdown element', function() { var writer = mdWriter.writer(); writer.open("h1", {id: "start"}); |
