From 4ba30dba6b9d6c4c2598ee0f72cd90556ce34a1c Mon Sep 17 00:00:00 2001 From: rich Date: Sat, 15 Sep 2018 11:22:47 +0100 Subject: [PATCH 1/3] [#1334] turn off typographic substitution in certain blocks --- lib/marked.js | 14 +++++++++++++- test/new/smartypants_code.html | 4 ++++ test/new/smartypants_code.md | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/new/smartypants_code.html create mode 100644 test/new/smartypants_code.md diff --git a/lib/marked.js b/lib/marked.js index c85f74ac95..635d9ba496 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -730,6 +730,14 @@ InlineLexer.prototype.output = function(src) { } else if (this.inLink && /^<\/a>/i.test(cap[0])) { this.inLink = false; } + if (!this.inRawBlock + && /^|^<\/code>|^<\/kbd>|^<\/script>/i.test(cap[0])) { + this.inRawBlock = false; + } + src = src.substring(cap[0].length); out += this.options.sanitize ? this.options.sanitizer @@ -820,7 +828,11 @@ InlineLexer.prototype.output = function(src) { // text if (cap = this.rules.text.exec(src)) { src = src.substring(cap[0].length); - out += this.renderer.text(escape(this.smartypants(cap[0]))); + if (this.inRawBlock) { + out += this.renderer.text(cap[0]); + } else { + out += this.renderer.text(escape(this.smartypants(cap[0]))); + } continue; } diff --git a/test/new/smartypants_code.html b/test/new/smartypants_code.html new file mode 100644 index 0000000000..db9bf4b1c8 --- /dev/null +++ b/test/new/smartypants_code.html @@ -0,0 +1,4 @@ +
&
+

--foo +---foo

+ diff --git a/test/new/smartypants_code.md b/test/new/smartypants_code.md new file mode 100644 index 0000000000..5ad8f6ee2f --- /dev/null +++ b/test/new/smartypants_code.md @@ -0,0 +1,9 @@ +--- +smartypants: true +description: SmartyPants does not modify characters within
, , , or 

From f09095ef0eaccd2d4bff98a244835c266acba84c Mon Sep 17 00:00:00 2001
From: rich 
Date: Sun, 16 Sep 2018 08:15:00 +0100
Subject: [PATCH 2/3] Use neater alternation in regexes for improved
 readability

---
 lib/marked.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/marked.js b/lib/marked.js
index 635d9ba496..6b940b5e2e 100644
--- a/lib/marked.js
+++ b/lib/marked.js
@@ -731,10 +731,10 @@ InlineLexer.prototype.output = function(src) {
         this.inLink = false;
       }
       if (!this.inRawBlock
-          && /^|^<\/code>|^<\/kbd>|^<\/script>/i.test(cap[0])) {
+          && /^<\/(pre|code|kbd|script)>/i.test(cap[0])) {
         this.inRawBlock = false;
       }
 

From d604680a6afa47ad2d3453bb125f6e5946e09264 Mon Sep 17 00:00:00 2001
From: rich 
Date: Sun, 16 Sep 2018 15:57:12 +0100
Subject: [PATCH 3/3] Prevent matching other content that starts with these
 words

---
 lib/marked.js                  | 6 ++----
 test/new/smartypants_code.html | 7 +++++++
 test/new/smartypants_code.md   | 6 ++++++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/marked.js b/lib/marked.js
index 6b940b5e2e..79478498c9 100644
--- a/lib/marked.js
+++ b/lib/marked.js
@@ -730,11 +730,9 @@ InlineLexer.prototype.output = function(src) {
       } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
         this.inLink = false;
       }
-      if (!this.inRawBlock
-          && /^<(pre|code|kbd|script)/i.test(cap[0])) {
+      if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
         this.inRawBlock = true;
-      } else if (this.inRawBlock
-          && /^<\/(pre|code|kbd|script)>/i.test(cap[0])) {
+      } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
         this.inRawBlock = false;
       }
 
diff --git a/test/new/smartypants_code.html b/test/new/smartypants_code.html
index db9bf4b1c8..3ceb5094c3 100644
--- a/test/new/smartypants_code.html
+++ b/test/new/smartypants_code.html
@@ -2,3 +2,10 @@
 

--foo ---foo

+ +

Ensure that text such as custom tags that happen to +begin with the same letters as the above tags don’t +match and thus benefit from Smartypants-ing.

+ +

–foo +--foo <codebar –foo codebar>

diff --git a/test/new/smartypants_code.md b/test/new/smartypants_code.md index 5ad8f6ee2f..6c4c52332e 100644 --- a/test/new/smartypants_code.md +++ b/test/new/smartypants_code.md @@ -7,3 +7,9 @@ spec: https://daringfireball.net/projects/smartypants/ --foo ---foo + +Ensure that text such as custom tags that happen to +begin with the same letters as the above tags don't +match and thus benefit from Smartypants-ing. +--foo +`--foo`