How to escape backslash bracket (\[) in Markdown?

前端 未结 5 1440
心在旅途
心在旅途 2021-01-03 17:14

How does one escape the \"backslash square brackets\" \\[ \\] sequence in Markdown for GitHub? The sequence produces a

...

        
相关标签:
5条回答
  • 2021-01-03 17:51

    just write:

    This is a __backslash with a square bracket__: \\\[.  
    

    It works on github for me.


    Edit

    Now that the question has been updated, here is an updated answer.
    Just escape all characters, at the beginning and at the end:

    foo \\\[something\\\] bar will produce => foo \[something\] bar

    Works normally on github: http://tinypic.com/view.php?pic=oh2xyp&s=6


    Edit 2

    Just tried on a wiki... you're right, it doesn't work there. I guess it's because of the special meaning that constructs like [[foobar]] have in the wiki syntax.
    I'd say your best shot is this: __\__ __[__ __something__ __\__ __]__ (without code backsticks).
    Weirdly it doesn't work here, but it works on github wikis.

    Still, if you think it's a bug, you should report it as they say here.

    0 讨论(0)
  • 2021-01-03 17:52

    I have resorted to surrounding my bracketed string with backticks: `[[320,50],[300,250]]`

    Which turns it into: [[320,50],[300,250]] So now my array doesn't turn into a link.

    0 讨论(0)
  • 2021-01-03 17:54

    There doesn't appear to be a way to do it. A workaround is to use a Gist to store such files (in my case a Bash script).

    I will reassign to a better answer if someone comes up with a real solution.

    Update: Use backticks to escape the escape char. See the new accepted answer.

    0 讨论(0)
  • 2021-01-03 17:56

    This is now fixed on GitHub. So there is no need to escape square brackets anymore. To type [some text], you could just type:

    // your markdown
    [some text]
    

    This is good for two reasons:

    1. square brackets are no longer parsed separately from figure and hyper-links.
    2. This means that we could use \] and \[ for display latex math, which is the correct way to write LaTeX. ($$ is not a LaTeX command and should never be used.)

    You can check this by editing the README.md of a GitHub project.

    0 讨论(0)
  • 2021-01-03 18:06

    This has been fixed on github.com. I'm not sure when, but you can now escape square brackets with a single backlash. EG

    \[Hello\]
    

    is rendered as

    [Hello]

    0 讨论(0)
提交回复
热议问题