diff --git a/src/commonmark-rules.js b/src/commonmark-rules.js index 77a4c529..f32a8933 100644 --- a/src/commonmark-rules.js +++ b/src/commonmark-rules.js @@ -153,8 +153,9 @@ rules.inlineLink = { replacement: function (content, node) { var href = node.getAttribute('href') + if (href) href = href.replace(/([()])/g, '\\$1') var title = cleanAttribute(node.getAttribute('title')) - if (title) title = ' "' + title + '"' + if (title) title = ' "' + title.replace(/"/g, '\\"') + '"' return '[' + content + '](' + href + title + ')' } } diff --git a/test/index.html b/test/index.html index 26fa586c..065de26e 100644 --- a/test/index.html +++ b/test/index.html @@ -217,6 +217,16 @@ link") +
+
An anchor
+
[An anchor](http://example.com "\"hello\"")
+
+ +
+
An anchor
+
[An anchor](http://example.com?\(query\))
+
+
Anchor without a title
Anchor without a title