74

How does one escape the "backslash square brackets" \[ \] sequence in Markdown for GitHub? The sequence produces a <pre><code>...</code></pre> section.

This is only a problem with Markdown for GitHub. I can write it here without the problem:

\[something \]

This code in GitHub will however produce

\ something

1
  • Having the same problem with Markdown files processed through Hugo; the selected solution works, fortunately.
    – GreenMatt
    Aug 4, 2016 at 15:52

4 Answers 4

51

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]

1
37

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.

3
  • 3
    Yes, the backtick do the job. Thanks. BTW, the problem I stated was not how to escape brackets but "backslash brackets" (\[) as occurs in many bash scripts. Backticks do stop Github markdown from trying to perform any transformation.
    – Bernard
    May 4, 2015 at 3:05
  • 3
    GitHub has fixed this problem with the original Markdown definition (daringfireball.net/projects/markdown/syntax#backslash), and we can now use the standard \[ and \] (instead of switching to code mode with backticks). Feb 10, 2019 at 9:30
  • 2
    You can also use the HTML entity numbers &#91; & &#93; for [ & ] respectively. e.g. &#91;320,50&#93; but it's not very readable.
    – DJDaveMark
    Aug 8, 2019 at 11:45
8

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.

5

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.

2
  • Sorry but this code still doesn't work for me. I created a wiki page, pasted in foo \\[something\\] bar and it still shows up with a <code> block added. Note that the GitHub Gist editor doesn't do that. It is only with Wiki pages (which use the GitHub flavored Markdown).
    – Bernard
    Apr 17, 2013 at 7:03
  • I've reported the bug to GitHub. Thanks for the link. I'll give you a point for your work but the answer is unfortunately that it can't be done.
    – Bernard
    Apr 19, 2013 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.