Closed pavelhoral closed 7 months ago
I have specifically changed only the link destination escaping, however a quick glance on the link title specification reveals that this is also not correctly handled / escaped. So maybe this PR should cover that as well?
diff --git a/src/commonmark-rules.js b/src/commonmark-rules.js
index 8aa1617..f32a893 100644
--- a/src/commonmark-rules.js
+++ b/src/commonmark-rules.js
@@ -155,7 +155,7 @@ rules.inlineLink = {
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 + ')'
}
}
I have added title escaping as well.
This adds escaping parenthesis according to Common Mark spec - https://spec.commonmark.org/0.31.2/#link-destination.
Alternative solution would be to detect presence of parenthesis and enclosing the link in pointy brackets
[text](<link>)
.