remove-markdown 0.5.2 → 0.5.4
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 +0 -2
- package/index.d.ts +11 -0
- package/index.js +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
1
|
## What is it?
|
|
4
2
|
**remove-markdown** is a node.js module that will remove (strip) Markdown formatting from text.
|
|
5
3
|
*Markdown formatting* means pretty much anything that doesn’t look like regular text, like square brackets, asterisks etc.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function removeMd(md: string, options?: {
|
|
2
|
+
stripListLeaders?: boolean;
|
|
3
|
+
listUnicodeChar?: string;
|
|
4
|
+
gfm?: boolean;
|
|
5
|
+
useImgAltText: boolean;
|
|
6
|
+
abbr?: boolean;
|
|
7
|
+
replaceLinksWithURL?: boolean;
|
|
8
|
+
htmlTagsToSkip?: string[];
|
|
9
|
+
}): string;
|
|
10
|
+
|
|
11
|
+
export = removeMd;
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ module.exports = function(md, options) {
|
|
|
7
7
|
options.abbr = options.hasOwnProperty('abbr') ? options.abbr : false;
|
|
8
8
|
options.replaceLinksWithURL = options.hasOwnProperty('replaceLinksWithURL') ? options.replaceLinksWithURL : false;
|
|
9
9
|
options.htmlTagsToSkip = options.hasOwnProperty('htmlTagsToSkip') ? options.htmlTagsToSkip : [];
|
|
10
|
+
options.throwError = options.hasOwnProperty('throwError') ? options.throwError : false;
|
|
10
11
|
|
|
11
12
|
var output = md || '';
|
|
12
13
|
|
|
@@ -48,7 +49,7 @@ module.exports = function(md, options) {
|
|
|
48
49
|
htmlReplaceRegex = new RegExp(
|
|
49
50
|
'<' +
|
|
50
51
|
joinedHtmlTagsToSkip +
|
|
51
|
-
'[^>]*>',
|
|
52
|
+
'[^>]*>',
|
|
52
53
|
'ig'
|
|
53
54
|
);
|
|
54
55
|
}
|
|
@@ -74,10 +75,8 @@ module.exports = function(md, options) {
|
|
|
74
75
|
.replace(/^(\n)?\s{0,}#{1,6}\s*( (.+))? +#+$|^(\n)?\s{0,}#{1,6}\s*( (.+))?$/gm, '$1$3$4$6')
|
|
75
76
|
// Remove * emphasis
|
|
76
77
|
.replace(/([\*]+)(\S)(.*?\S)??\1/g, '$2$3')
|
|
77
|
-
// Remove _ emphasis
|
|
78
|
-
|
|
79
|
-
// 2. Or _ is at the start/end of the string.
|
|
80
|
-
.replace(/(^|\W)([_]+)(\S)(.*?\S)??\2($|\W)/g, '$1$3$4$5')
|
|
78
|
+
// Remove _ emphasis
|
|
79
|
+
.replace(/(_+)(.*?\S)(_+)/g, '$1$3$4$5')
|
|
81
80
|
// Remove code blocks
|
|
82
81
|
.replace(/(`{3,})(.*?)\1/gm, '$2')
|
|
83
82
|
// Remove inline code
|
|
@@ -89,7 +88,9 @@ module.exports = function(md, options) {
|
|
|
89
88
|
// Replace strike through
|
|
90
89
|
.replace(/~(.*?)~/g, '$1');
|
|
91
90
|
} catch(e) {
|
|
92
|
-
|
|
91
|
+
if (options.throwError) throw e;
|
|
92
|
+
|
|
93
|
+
console.error("remove-markdown encountered error: %s", e);
|
|
93
94
|
return md;
|
|
94
95
|
}
|
|
95
96
|
return output;
|