2015-07-11 22:45:58 +08:00
|
|
|
showdown.subParser('italicsAndBold', function (text, options) {
|
2015-01-19 19:37:21 +08:00
|
|
|
'use strict';
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-07-11 22:45:58 +08:00
|
|
|
if (options.literalMidWordUnderscores) {
|
|
|
|
//underscores
|
|
|
|
// Since we are consuming a \s character, we need to add it
|
2015-07-15 03:51:22 +08:00
|
|
|
text = text.replace(/(^|\s|>|\b)__(?=\S)([^]+?)__(?=\b|<|\s|$)/gm, '$1<strong>$2</strong>');
|
|
|
|
text = text.replace(/(^|\s|>|\b)_(?=\S)([^]+?)_(?=\b|<|\s|$)/gm, '$1<em>$2</em>');
|
2015-07-11 22:45:58 +08:00
|
|
|
//asterisks
|
|
|
|
text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>');
|
|
|
|
text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>');
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-07-11 22:45:58 +08:00
|
|
|
} 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>');
|
|
|
|
}
|
2015-01-19 19:37:21 +08:00
|
|
|
return text;
|
2015-01-16 05:21:33 +08:00
|
|
|
});
|