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 CHANGED
@@ -1,5 +1,3 @@
1
- ![default workflow](https://github.com/stiang/remove-markdown/actions/workflows/default.yaml/badge.svg)
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. Unlike *, _ emphasis gets rendered only if
78
- // 1. Either there is a whitespace character before opening _ and after closing _.
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
- console.error(e);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remove-markdown",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Remove Markdown formatting from text",
5
5
  "main": "index.js",
6
6
  "scripts": {