diff --git a/lib/marked.js b/lib/marked.js index 9e8c5d7e73..b56ad176e7 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -468,8 +468,8 @@ var inline = { link: /^!?\[(inside)\]\(href\)/, reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/, - strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, - em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/, + strong: /^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)|^__([^\s])__(?!_)|^\*\*([^\s])\*\*(?!\*)/, + em: /^_([^\s][\s\S]*?[^\s_])_(?!_)|^_([^\s_][\s\S]*?[^\s])_(?!_)|^\*([^\s][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*][\s\S]*?[^\s])\*(?!\*)|^_([^\s_])_(?!_)|^\*([^\s*])\*(?!\*)/, code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/, br: /^ {2,}\n(?!\s*$)/, del: noop, @@ -678,14 +678,14 @@ InlineLexer.prototype.output = function(src) { // strong if (cap = this.rules.strong.exec(src)) { src = src.substring(cap[0].length); - out += this.renderer.strong(this.output(cap[2] || cap[1])); + out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1])); continue; } // em if (cap = this.rules.em.exec(src)) { src = src.substring(cap[0].length); - out += this.renderer.em(this.output(cap[2] || cap[1])); + out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1])); continue; } diff --git a/test/new/em_2char.html b/test/new/em_2char.html new file mode 100644 index 0000000000..81da0a0001 --- /dev/null +++ b/test/new/em_2char.html @@ -0,0 +1,25 @@ +
123
+ +123
+ +12
+ +12
+ +1
+ +1
+ +__
+ +**
+ +_123 _
+ +*123 *
+ +_ 123_
+ +1_
+ +1*
diff --git a/test/new/em_2char.md b/test/new/em_2char.md new file mode 100644 index 0000000000..ca8689aaba --- /dev/null +++ b/test/new/em_2char.md @@ -0,0 +1,25 @@ +_123_ + +*123* + +_12_ + +*12* + +_1_ + +*1* + +__ + +** + +_123 _ + +*123 * + +_ 123_ + +_1__ + +*1**