remove-markdown 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/index.js +3 -3
- package/package.json +1 -1
- package/test/remove-markdown.js +18 -0
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/remove-markdown)
|
|
2
|
+
[](https://npm-compare.com/remove-markdown/#timeRange=THREE_YEARS)
|
|
3
|
+
[](https://github.com/zuchka/remove-markdown/actions/workflows/default.yaml)
|
|
2
4
|
|
|
3
5
|
## What is it?
|
|
4
6
|
**remove-markdown** is a node.js module that will remove (strip) Markdown formatting from text.
|
package/index.js
CHANGED
|
@@ -29,8 +29,8 @@ module.exports = function(md, options) {
|
|
|
29
29
|
.replace(/~{3}.*\n/g, '')
|
|
30
30
|
// Strikethrough
|
|
31
31
|
.replace(/~~/g, '')
|
|
32
|
-
// Fenced codeblocks
|
|
33
|
-
.replace(
|
|
32
|
+
// Fenced codeblocks with backticks
|
|
33
|
+
.replace(/```(?:.*)\n([\s\S]*?)```/g, (_, code) => code.trim());
|
|
34
34
|
}
|
|
35
35
|
if (options.abbr) {
|
|
36
36
|
// Remove abbreviations
|
|
@@ -72,7 +72,7 @@ module.exports = function(md, options) {
|
|
|
72
72
|
// 1. Either there is a whitespace character before opening _ and after closing _.
|
|
73
73
|
// 2. Or _ is at the start/end of the string.
|
|
74
74
|
.replace(/(^|\W)([_]+)(\S)(.*?\S)??\2($|\W)/g, '$1$3$4$5')
|
|
75
|
-
// Remove code blocks
|
|
75
|
+
// Remove single-line code blocks (already handled multiline above in gfm section)
|
|
76
76
|
.replace(/(`{3,})(.*?)\1/gm, '$2')
|
|
77
77
|
// Remove inline code
|
|
78
78
|
.replace(/`(.+?)`/g, '$1')
|
package/package.json
CHANGED
package/test/remove-markdown.js
CHANGED
|
@@ -57,6 +57,24 @@ describe('remove Markdown', function () {
|
|
|
57
57
|
expect(removeMd(string)).to.equal(expected);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
+
it('should strip simple multiline code tags', function () {
|
|
61
|
+
const string = '```\ncode\n```';
|
|
62
|
+
const expected = 'code';
|
|
63
|
+
expect(removeMd(string)).to.equal(expected);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should strip complex multiline code blocks with language specified', function () {
|
|
67
|
+
const string = '```javascript\nconst x = 1;\nconst y = 2;\nconsole.log(x + y);\n```';
|
|
68
|
+
const expected = 'const x = 1;\nconst y = 2;\nconsole.log(x + y);';
|
|
69
|
+
expect(removeMd(string)).to.equal(expected);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should strip multiline code blocks with multiple paragraphs', function () {
|
|
73
|
+
const string = 'Text before\n\n```\ncode line 1\n\ncode line 2\n```\n\nText after';
|
|
74
|
+
const expected = 'Text before\n\ncode line 1\n\ncode line 2\n\nText after';
|
|
75
|
+
expect(removeMd(string)).to.equal(expected);
|
|
76
|
+
});
|
|
77
|
+
|
|
60
78
|
it('should leave hashtags in headings', function () {
|
|
61
79
|
const string = '## This #heading contains #hashtags';
|
|
62
80
|
const expected = 'This #heading contains #hashtags';
|