From 2e1b7c030e83f7fddde10a19cb8223ab8523611e Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 31 Aug 2022 11:57:48 +0200 Subject: [PATCH] Fix anchors containing block elements Fixes https://github.com/mixmark-io/turndown/issues/409 --- src/commonmark-rules.js | 3 ++- test/index.html | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/commonmark-rules.js b/src/commonmark-rules.js index 77a4c529..66ee01db 100644 --- a/src/commonmark-rules.js +++ b/src/commonmark-rules.js @@ -155,7 +155,7 @@ rules.inlineLink = { var href = node.getAttribute('href') var title = cleanAttribute(node.getAttribute('title')) if (title) title = ' "' + title + '"' - return '[' + content + '](' + href + title + ')' + return '[' + content.trim() + '](' + href + title + ')' } } @@ -169,6 +169,7 @@ rules.referenceLink = { }, replacement: function (content, node, options) { + content = content.trim() var href = node.getAttribute('href') var title = cleanAttribute(node.getAttribute('title')) if (title) title = ' "' + title + '"' diff --git a/test/index.html b/test/index.html index 26fa586c..281b52cd 100644 --- a/test/index.html +++ b/test/index.html @@ -227,6 +227,22 @@
[Some `code`](http://example.com/code)
+
+ +
[heading
+=======](http://example.com/heading)
+
+ +
+ +
[paragraph](http://example.com/paragraph)
+
+ +
+ +
[div](http://example.com/div)
+
+
[Reference link][1]