[#1334] turn off typographic substitution in certain blocks

This commit is contained in:
rich 2018-09-15 11:22:47 +01:00
parent 7f2a917b36
commit 4ba30dba6b
3 changed files with 26 additions and 1 deletions

View File

@ -730,6 +730,14 @@ 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])) {
this.inRawBlock = true;
} else if (this.inRawBlock
&& /^<\/pre>|^<\/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);
if (this.inRawBlock) {
out += this.renderer.text(cap[0]);
} else {
out += this.renderer.text(escape(this.smartypants(cap[0])));
}
continue;
}

View File

@ -0,0 +1,4 @@
<pre>&amp;</pre>
<p><code>--foo</code>
<kbd>---foo</kbd></p>
<script>--foo</script>

View File

@ -0,0 +1,9 @@
---
smartypants: true
description: SmartyPants does not modify characters within <pre>, <code>, <kbd>, or <script> tag blocks.
spec: https://daringfireball.net/projects/smartypants/
---
<pre>&amp;</pre>
<code>--foo</code>
<kbd>---foo</kbd>
<script>--foo</script>