remove-markdown 0.5.2 → 0.5.3

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.
Files changed (3) hide show
  1. package/index.d.ts +13 -0
  2. package/index.js +7 -6
  3. package/package.json +1 -1
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ declare module "remove-markdown" {
2
+ export function removeMd(md: string, options?: {
3
+ stripListLeaders?: boolean;
4
+ listUnicodeChar?: string;
5
+ gfm?: boolean;
6
+ useImgAltText: boolean;
7
+ abbr?: boolean;
8
+ replaceLinksWithURL?: boolean;
9
+ htmlTagsToSkip?: string[];
10
+ }): string;
11
+
12
+ export = removeMd;
13
+ }
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.3",
4
4
  "description": "Remove Markdown formatting from text",
5
5
  "main": "index.js",
6
6
  "scripts": {