From deee500761d499d4ea50d3e75b1f626268879527 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 8 Feb 2015 20:22:55 +0000 Subject: Ignore anchor tags if href is not set --- lib/writers/markdown-writer.js | 14 +++++++++----- 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"}); -- cgit v1.2.3