showdown.subParser('underline', function (text, options, globals) {
'use strict';
if (!options.underline) {
return text;
}
text = globals.converter._dispatch('underline.before', text, options, globals);
if (options.literalMidWordUnderscores) {
text = text.replace(/\b_?__(\S[\s\S]*)___?\b/g, function (wm, txt) {
return '' + txt + '';
});
} else {
text = text.replace(/_?__(\S[\s\S]*?)___?/g, function (wm, m) {
return (/\S$/.test(m)) ? '' + m + '' : wm;
});
}
// escape remaining underscores to prevent them being parsed by italic and bold
text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback);
text = globals.converter._dispatch('underline.after', text, options, globals);
return text;
});