Skip to content

Commit a98bad2

Browse files
authored
Merge pull request #1013 from Feder1co5oave/fix-backticks2
fix backticks in inline code (replaces #503, fixes #312)
2 parents a78d51f + 4bc3126 commit a98bad2

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/marked.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ var inline = {
469469
nolink: /^!?\[((?:\[[^\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
470470
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
471471
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
472-
code: /^(`+)([\s\S]*?[^`])\1(?!`)/,
472+
code: /^(`+)(\s*)([\s\S]*?[^`]?)\2\1(?!`)/,
473473
br: /^ {2,}\n(?!\s*$)/,
474474
del: noop,
475475
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
@@ -675,7 +675,7 @@ InlineLexer.prototype.output = function(src) {
675675
// code
676676
if (cap = this.rules.code.exec(src)) {
677677
src = src.substring(cap[0].length);
678-
out += this.renderer.codespan(escape(cap[2].trim(), true));
678+
out += this.renderer.codespan(escape(cap[3].trim(), true));
679679
continue;
680680
}
681681

test/new/nested_code.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
<p><code>hi ther `` ok ```</code></p>
2+
3+
<p><code>`</code></p>
4+
5+
<p><code>There is a literal backtick (`) here.</code></p>
6+
7+
<p>A backtick-delimited string in a code span: <code>`foo`</code></p>
8+
9+
<p>Please don&#39;t use any <code>&lt;blink&gt;</code> tags.</p>

test/new/nested_code.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
````` hi ther `` ok ``` `````
2+
3+
`` ` ``
4+
5+
``There is a literal backtick (`) here.``
6+
7+
A backtick-delimited string in a code span: `` `foo` ``
8+
9+
Please don't use any `<blink>` tags.

0 commit comments

Comments
 (0)