UNPKG

showdown

Version:

A Markdown to HTML converter written in Javascript

24 lines (19 loc) 968 B
showdown.subParser('italicsAndBold', function (text, options, globals) { 'use strict'; text = globals.converter._dispatch('italicsAndBold.before', text, options, globals); if (options.literalMidWordUnderscores) { //underscores // Since we are consuming a \s character, we need to add it text = text.replace(/(^|\s|>|\b)__(?=\S)([\s\S]+?)__(?=\b|<|\s|$)/gm, '$1<strong>$2</strong>'); text = text.replace(/(^|\s|>|\b)_(?=\S)([\s\S]+?)_(?=\b|<|\s|$)/gm, '$1<em>$2</em>'); //asterisks text = text.replace(/(\*\*)(?=\S)([^\r]*?\S[*]*)\1/g, '<strong>$2</strong>'); text = text.replace(/(\*)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>'); } else { // <strong> must go first: text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '<strong>$2</strong>'); text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>'); } text = globals.converter._dispatch('italicsAndBold.after', text, options, globals); return text; });