diff --git a/index.js b/index.js index 6d11ad0..256acc5 100644 --- a/index.js +++ b/index.js @@ -17,9 +17,9 @@ module.exports = function(md, options) { try { if (options.stripListLeaders) { if (options.listUnicodeChar) - output = output.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, options.listUnicodeChar + ' $1'); + output = output.replace(/^([\s\t]*)([*\-+]|\d+\.)\s+/gm, options.listUnicodeChar + ' $1'); else - output = output.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, '$1'); + output = output.replace(/^([\s\t]*)([*\-+]|\d+\.)\s+/gm, '$1'); } if (options.gfm) { output = output @@ -58,14 +58,14 @@ module.exports = function(md, options) { // Remove HTML tags .replace(htmlReplaceRegex, '') // Remove setext-style headers - .replace(/^[=\-]{2,}\s*$/g, '') + .replace(/^[=-]{2,}\s*$/g, '') // Remove footnotes? - .replace(/\[\^.+?\](\: .*?$)?/g, '') + .replace(/\[\^.+?\](: .*?$)?/g, '') .replace(/\s{0,2}\[.*?\]: .*?$/g, '') // Remove images - .replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, options.useImgAltText ? '$1' : '') + .replace(/!\[(.*?)\][[(].*?[\])]/g, options.useImgAltText ? '$1' : '') // Remove inline links - .replace(/\[([^\]]*?)\][\[\(].*?[\]\)]/g, options.replaceLinksWithURL ? '$2' : '$1') + .replace(/\[([^\]]*?)\][[(].*?[\])]/g, options.replaceLinksWithURL ? '$2' : '$1') // Remove blockquotes .replace(/^(\n)?\s{0,3}>\s?/gm, '$1') // .replace(/(^|\n)\s{0,3}>\s?/g, '\n\n') @@ -74,9 +74,11 @@ module.exports = function(md, options) { // Remove atx-style headers .replace(/^(\n)?\s{0,}#{1,6}\s*( (.+))? +#+$|^(\n)?\s{0,}#{1,6}\s*( (.+))?$/gm, '$1$3$4$6') // Remove * emphasis - .replace(/([\*]+)(\S)(.*?\S)??\1/g, '$2$3') - // Remove _ emphasis - .replace(/(_+)(.*?\S)(_+)/g, '$1$3$4$5') + .replace(/([*]+)(\S)(.*?\S)??\1/g, '$2$3') + // Remove _ emphasis. Unlike *, _ emphasis gets rendered only if + // 1. Either there is a whitespace character before opening _ and after closing _. + // 2. Or _ is at the start/end of the string. + .replace(/(^|\W)([_]+)(\S)(.*?\S)??\2($|\W)/g, '$1$3$4$5') // Remove code blocks .replace(/(`{3,})(.*?)\1/gm, '$2') // Remove inline code