showdown.subParser('italicsAndBold', function (text, options) { 'use strict'; if (options.literalMidWordUnderscores) { //underscores // Since we are consuming a \s character, we need to add it text = text.replace(/(\s)__(?=\S)([^]+?)__(?=\s)/g, '$1$2'); text = text.replace(/(\s)_(?=\S)([^]+?)_(?=\s)/g, '$1$2'); //asterisks text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '$1'); text = text.replace(/\*(?=\S)([^]+?)\*/g, '$1'); } else { // must go first: text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '$2'); text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '$2'); } return text; });