Use syntax highlighting in a wiki

You can highlight snippets of text on your Bitbucket wiki pages. We use the excellent Pygments library to style our code. Here is an example of some Python code, formatted in a Bitbucket wiki:

The syntax you use to format the code block depends on which language you choose for your wiki. Make sure you know which language you are using.  You can see the current language when the Wiki is in Edit mode.

Then use the appropriate syntax to format the code as shown above:

Markdown Creole
```
#!python

def wiki_rocks(text):
	formatter = lambda t: "funky"+t
	return formatter(text)
```
{{{
#!python

def wiki_rocks(text):
	formatter = lambda t: "funky"+t
	return formatter(text)
}}}
Textile reStructuredText
bc. #!python
def wiki_rocks(text):
	formatter = lambda t: "funky"+t
	return formatter(text)

.. sourcecode :: python
 
 def wiki_rocks(text):
    formatter = lambda t: "funky"+t
    return formatter(text)

For details on the various languages, see their corresponding documentation on the web. See the library of Pygment lexers. Bitbucket supports the short name or the mimetype of anything in that library.

Was this helpful?

Thanks for your feedback!

23 Archived comments

  1. User avatar

    Anonymous

    Which pygments version is currrently used ?

    30 Dec 2011
    1. User avatar

      manthony

      Currently, we use 1.5 but we are planning on upgrading so this could change.

      02 Jan 2013
  2. User avatar

    Anonymous

    Is inline markup supported?  I'm trying to highlight syntax for use inside a table on a bitbucket wiki, but it doesn't seem to want to parse it.  I'm using Creole as the markup language.

    14 Feb 2013
    1. User avatar

      manthony

      This is inline text: {{{<<file index.html>>}}} followed by more.

      Renders like this:

      06 Mar 2013
      1. User avatar

        Юрий Занин

        Mary, how I can use inline highlighting in Markdown markup?

        31 May 2013
        1. User avatar

          manthony

          You use a backtick.  Like so:

          31 May 2013
          1. User avatar

            Юрий Занин

            Thank you, Mary!

            31 May 2013
  3. User avatar

    Anonymous

    How to disable highlighting for one particular code block?

    06 Jun 2013
    1. User avatar

      manthony

      You don't say which mark up language you are using.  You could use a general performatted content mark up and omit reference to a particular language.

      06 Jun 2013
    1. User avatar

      Anonymous

      I managed to avoid syntax highlighting by using the Pygments "text" lexer (see http://pygments.org/docs/lexers/#special-lexers). For this, I add this line at the beginning of the code block:

          :::text
      15 Mar 2014
  4. User avatar

    Parag Patel

    How can I change the style of the code snippet?  If I wanted to use a fruity style as in this demo.

    http://pygments.org/demo/85984/?style=fruity

    25 Jun 2013
    1. User avatar

      manthony

      You would need to use CSS for that. We don't have a way of attaching a repo-specific CSS to a Wiki page. 

      26 Jun 2013
  5. User avatar

    Anonymous

    If your code block is an executable script, the first line (e.g. #!/usr/bin/sh) will be hidden. My solution was to insert a new first line with just "#!", but I believe a better workaround should be documented.

    20 Jul 2013
  6. User avatar

    Anonymous

    Hi,

    I cannot generate locally on my computer the same html files that I can see on my bitbucket wiki.

    That is, I run markdown on my machine on the same source files, but I don't get the same output I can see in the wiki. Specifically, the syntax colouring does not work. I am running python-markdown loading the codehilite extension, but I don't get any colours, it does not even recognize that the text between ``` ``` is code. I am using ubuntu, and I have installed the pygments library.

    How can I setup locally on my computer the same markdow setup that is running on bitbucket?

    Thanks

    29 Jul 2013
  7. User avatar

    Anonymous

    It seems that the python markdown running on bitbucket is slightly modified with respect to the original distribution. For instance, the original markdown does not support code blocks within three backticks.

    If I am correct, is it possible to download the bitbucket version of markdown? Thanks

    09 Sep 2013
    1. User avatar

      manthony

      We don't provide this for download.  You can file an enhancement request for this.

      09 Sep 2013
  8. User avatar

    Jason Patel

    Is there a way allow code blocks with syntax highlighting in ordered lists? The only way I have been able to do this is following the markdown documentation you link to here http://daringfireball.net/projects/markdown/syntax#code,  but that takes away syntax highlighting

    25 Feb 2014
  9. User avatar

    Anonymous

    Is there any way to add languages? Specifically, SPARQL, for which there already exists a Pygments lexer called n3pygments.

    05 Mar 2014
  10. User avatar

    Alen Pelin

    Is there a list of supported languages? Is C# (csharp) is supported? If not then is there any plans to add support of it?

    15 Jan 2015
    1. User avatar

      Erik van Zijst [Atlassian]

      Yes, as stated in the documentation above, everything in Pygments is supported (http://pygments.org/docs/lexers/), which includes C-Sharp. Did this not work for you?

      For Markdown, that would look like:

      15 Jan 2015
      1. User avatar

        Alen Pelin

        Thanks, it works. I should have better read the article (smile) 

        I'd suggest copy-paste here to another doc page the list of all supported languages as googling returns nothing for "Bitbucket wiki C# support" and similar things. 

        27 Jan 2015
  11. User avatar

    Jerry Lin

    Would we be able to add our own custom lexers? I paste Slf4j logger output often and it would be easier for colleagues to parse if it were colorized. I can write a custom parser for our needs, but would need to integrate it into bitbucket's pygments somehow.

    21 Aug 2015
    1. User avatar

      Erik van Zijst [Atlassian]

      At this time there are no plans to offer this. Since we are running vanilla Pygments, we have historically relied on people contributing directly to that project. Anything that gets accepted there will automatically become available on Bitbucket.

      25 Aug 2015
Powered by Confluence and Scroll Viewport