Skip to content

Single backtick in inline code #312

Closed

Description

@valeriangalliat
$ marked
`` ` ``
^D
<p><code>` </code></p>

There is a remaining white space after the backtick that shouldn't be there !

http://daringfireball.net/projects/markdown/syntax#code
At the "A single backtick in a code span" part, the output doesn't have that trailing space.

Activity

  1. Feder1co5oave commented on Dec 30, 2013

    @Feder1co5oave
    Contributor

    this seems to solve

    diff --git a/lib/marked.js b/lib/marked.js
    index 2b8309b..51fff0b 100644
    --- a/lib/marked.js
    +++ b/lib/marked.js
    @@ -450,7 +450,7 @@ var inline = {
       nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
       strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
       em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
    -  code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
    +  code: /^(`+)(\s*)([\s\S]*?[^`]?)\2\1(?!`)/,
       br: /^ {2,}\n(?!\s*$)/,
       del: noop,
       text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
    @@ -642,7 +642,7 @@ InlineLexer.prototype.output = function(src) {
         // code
         if (cap = this.rules.code.exec(src)) {
           src = src.substring(cap[0].length);
    -      out += this.renderer.codespan(escape(cap[2], true));
    +      out += this.renderer.codespan(escape(cap[3], true));
           continue;
         }
    > marked('`` ` ``');
    '<p><code>`</code></p>\n'
    > marked('``There is a literal backtick (`) here.``')
    '<p><code>There is a literal backtick (`) here.</code></p>\n'
    > marked('A backtick-delimited string in a code span: `` `foo` ``')
    '<p>A backtick-delimited string in a code span: <code>`foo`</code></p>\n'
    > marked("Please don't use any `<blink>` tags.")
    '<p>Please don&#39;t use any <code>&lt;blink&gt;</code> tags.</p>\n'

    maybe add a test for this?

  2. valeriangalliat commented on Oct 18, 2014

    @valeriangalliat
    Author

    Hi,

    Sorry I totally forgot about this issue.

    To begin, many thanks @Feder1co5oave, your diff totally solves the issue.

    I was now looking to add a test for this like you were suggesting but it's not actually possible since all the whitespaces are removed. Anyway, do you think it worths merging your patch in master? Do you want me to make a PR or something?

    Otherwise I think we can close. :)

  3. added a commit that references this issue on Oct 18, 2014
    f2f29ed
  4. Feder1co5oave commented on Oct 18, 2014

    @Feder1co5oave
    Contributor

    Thanks for bringing this up again, I think it's worth merging.

  5. added a commit that references this issue on Mar 10, 2015
    68d86d9
  6. xovel commented on Jun 16, 2016

    @xovel

    Oh, great, THX!

    But it seems that this bug has not been fixed yet.

  7. added
    has PR
    on Dec 6, 2017
  8. added a commit that references this issue on Jan 14, 2018
    b2a0760
  9. added a commit that references this issue on Jan 20, 2018
    a98bad2
  10. added a commit that references this issue on Feb 17, 2018
  11. added 2 commits that reference this issue on Nov 8, 2021
    bc620a1
    7a55127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    has PR

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions