From 81e01d4faf64049a0af1ca1c922f7f8b1f05034e Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 28 Mar 2018 09:55:27 -0500 Subject: [PATCH] add more edge cases --- lib/marked.js | 8 ++++---- test/new/em_2char.html | 10 ++++++++++ test/new/em_2char.md | 10 ++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 1a948ce967..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 index ea199f7ebf..81da0a0001 100644 --- a/test/new/em_2char.html +++ b/test/new/em_2char.html @@ -13,3 +13,13 @@

__

**

+ +

_123 _

+ +

*123 *

+ +

_ 123_

+ +

1_

+ +

1*

diff --git a/test/new/em_2char.md b/test/new/em_2char.md index b882af01fb..ca8689aaba 100644 --- a/test/new/em_2char.md +++ b/test/new/em_2char.md @@ -13,3 +13,13 @@ _1_ __ ** + +_123 _ + +*123 * + +_ 123_ + +_1__ + +*1**