From 60c2dc4f2cfdeb61abe96b65edc5baf3d015de67 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 28 Mar 2018 00:31:14 -0500 Subject: [PATCH 1/3] fix inline.em --- lib/marked.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index 9e8c5d7e73..1a948ce967 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -469,7 +469,7 @@ var inline = { reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/, strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, - em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/, + em: /^_([^\s_](?:[^_]|__)*?[^\s_]?)_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/, code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/, br: /^ {2,}\n(?!\s*$)/, del: noop, From 6ce9c099e0866f6ec4dd3c1c8ef9caa24a04c079 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 28 Mar 2018 00:31:57 -0500 Subject: [PATCH 2/3] add tests --- test/new/em_2char.html | 15 +++++++++++++++ test/new/em_2char.md | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/new/em_2char.html create mode 100644 test/new/em_2char.md diff --git a/test/new/em_2char.html b/test/new/em_2char.html new file mode 100644 index 0000000000..ea199f7ebf --- /dev/null +++ b/test/new/em_2char.html @@ -0,0 +1,15 @@ +

123

+ +

123

+ +

12

+ +

12

+ +

1

+ +

1

+ +

__

+ +

**

diff --git a/test/new/em_2char.md b/test/new/em_2char.md new file mode 100644 index 0000000000..b882af01fb --- /dev/null +++ b/test/new/em_2char.md @@ -0,0 +1,15 @@ +_123_ + +*123* + +_12_ + +*12* + +_1_ + +*1* + +__ + +** From 81e01d4faf64049a0af1ca1c922f7f8b1f05034e Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 28 Mar 2018 09:55:27 -0500 Subject: [PATCH 3/3] 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**