showdown/src/subParsers/italicsAndBold.js

20 lines
734 B
JavaScript
Raw Normal View History

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