From 4833d29c3f481d4ca39402ffbc831582b7e23398 Mon Sep 17 00:00:00 2001 From: faissaloux Date: Sun, 22 Jan 2023 23:58:10 +0100 Subject: [PATCH] fix url that contains brackets --- index.js | 2 +- test/remove-markdown.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a84d2be..91e721d 100644 --- a/index.js +++ b/index.js @@ -64,7 +64,7 @@ module.exports = function(md, options) { // Remove images .replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, options.useImgAltText ? '$1' : '') // Remove inline links - .replace(/\[([^\]]*?)\][\[\(].*?[\]\)]/g, options.replaceLinksWithURL ? '$2' : '$1') + .replace(/\[([^\]]*?)\][\[\(].*[\]\)]/g, options.replaceLinksWithURL ? '$2' : '$1') // Remove blockquotes .replace(/^\s{0,3}>\s?/gm, '') // .replace(/(^|\n)\s{0,3}>\s?/g, '\n\n') diff --git a/test/remove-markdown.js b/test/remove-markdown.js index a7f4674..33dc5db 100644 --- a/test/remove-markdown.js +++ b/test/remove-markdown.js @@ -167,6 +167,20 @@ describe('remove Markdown', function () { expect(removeMd(paragraph)).to.equal(expected); }); + it('should remove inline links', function () { + const link = '[Link](https://www.example.com)'; + const expected = 'Link'; + + expect(removeMd(link)).to.equal(expected); + }); + + it('should remove inline links with parentheses', function () { + const link = '[Link (parentheses) - Link](https://www.example.com/(parentheses))'; + const expected = 'Link (parentheses) - Link'; + + expect(removeMd(link)).to.equal(expected); + }); + it('should not strip paragraphs without content', function() { const paragraph = '\n#This paragraph\n##This paragraph#'; const expected = paragraph;