Code Block Macro

The Code Block macro allows you to display source code in your page with syntax highlighting, like the one below:


Add the Code Block Macro

  1. In the Confluence editor, choose Insert > Other Macros
  2. Find and select the required macro

Speeding up macro entry with autocomplete: Type { and the beginning of the macro name, to see a list of suggested macros. Details are in Autocomplete for links, files, macros and mentions.

To edit an existing macro: Click the macro placeholder and choose Edit. A macro dialog window will open, where you can edit the parameters of the macro.

You type the code block directly into the macro placeholder in the editor. Note that any white space contained in the placeholder is not manipulated in any way by the Code Block macro. This is to provide the writer with flexibility over code indentation.

Parameters

Parameters are options that you can set to control the content or format of the macro output. Where the parameter name used in Confluence storage format or wikimarkup is different to the label used in the macro browser, it will be listed below in brackets (example).

Parameter

Default

Description

Syntax highlighting
(language

java

Specifies the language (or environment) for syntax highlighting. The default language is Java but you can choose from one of the following languages/environments:

  • actionscript3
  • bash
  • csharp (C#)
  • coldfusion
  • cpp (C++)
  • css
  • delphi
  • diff
  • erlang
  • groovy
  • html/xml
  • java
  • javafx
  • javascript
  • none (no syntax highlighting)
  • perl
  • php
  • powershell
  • python
  • ruby
  • scala
  • sql
  • vb

Title

none

Adds a title to the code block. If specified, the title will be displayed in a header row at the top of the code block.

Collapsible
(collapse

false

If selected, the code macro's content will be collapsed upon visiting or refreshing the Confluence page. Clicking the expand source link allows you to view this content. If false, the code macro's content is always displayed in full.

Show line numbers
(linenumbers)

false

If selected, line numbers will be shown to the left of the lines of code.

First line number
(firstline

1

When Show line numbers is selected, this value defines the number of the first line of code.

Theme

Default

Specifies the colour scheme used for displaying your code block. Many of these themes are based on the default colour schemes of popular integrated development environments (IDEs). The default theme is Confluence (also known as Default), which is typically black and coloured text on a blank background. However, you can also choose from one of the following other popular themes:

  • DJango
  • Emacs
  • FadeToGrey
  • Midnight
  • RDark
  • Eclipse
  • Confluence

Configure the Code Block macro

You can configure the Code Block macro to use a specific language and theme by default and also upload new lanuages. You need Confluence Administrator permissions to change the default theme and language and System Administrator permissions to upload new languages.

To set the default appearance of code blocks in your site:

  1. Choose the cog icon , then choose General Configuration under Confluence Administration
  2. Choose Configure Code Macro
  3. Select a Default Theme and Default Language
  4. Choose Save

All new code blocks will use the default theme and language unless you specify otherwise. Existing code blocks will be unchanged. 

 To add an additional language:

  1. Choose the cog icon , then choose General Configuration under Confluence Administration
  2. Choose Configure Code Macro
  3. Choose Add a new language
  4. Locate your language file and enter a Name for the new language (this will appear when selecting the language)
  5. Choose Add

Language files must be correctly formatted JavaScript files and adhere to the Custom Brush syntax. You can find some examples of language files here.

To disable or remove a user-installed language:

  1. Choose the cog icon , then choose General Configuration under Confluence Administration
  2. Choose Manage Add-ons
  3. Go to User-installed Add-ons and locate the add-on for your uploaded language - it will appear like this 'Custom Code Macro Highlighting for...'
  4. Choose Uninstall or Disable

The language will no longer appear in the Code Macro. 

Code examples

The following examples are provided for advanced users who want to inspect or edit the underlying markup for a Confluence page. 

Macro name: code

Macro body: Accepts plain text.

Storage format example

The following example shows all parameters and a body:

Below are three examples of the Code Block macro with various optional parameters used.

Description

Markup What you will get
Code block macro with a body and no optional parameters
Code block macro with a body and the optional language parameter defined

Code block macro with a body and optional title, line numbers and language parameters defined

This is my title

Wiki markup example

Was this helpful?

Thanks for your feedback!

128 Archived comments

  1. User avatar

    David Soul [Atlassian]

    While neither list bash or jython, you may wish to check out the http://confluence.atlassian.com/display/CONFEXT/New+Code+Macro and http://confluence.atlassian.com/display/CONFEXT/Pygments+Code+Macro plugins which support a wider range of languages and have a more pluggable interface for new languages.

    03 Dec 2007
  2. User avatar

    Anonymous

    Why is there a scroll bar on the right hand side of the code block that doesn't even slide? Whenever I create a code block it makes a scroll bar that is just the size of the block! Thanks

    14 Feb 2008
    1. User avatar

      Choy Li Tham

      Hi,

      Did you meant to say that you would like to control the scrollbar display in the Code Block macro? If that is the case, there is an improvement request being raised at the follwoing:

      If you are keen on this improvement, please do cast your vote to increase its popularity and add yourself as a watcher for future updates. Also, feel free to add comments to reflect the importance of this improvement.

      Regards,
      Choy Li

      15 Feb 2008
    1. User avatar

      Anonymous

      try height and width parameters |height=50%|width=100%

      09 Aug 2012
  3. User avatar

    Anonymous

    Hi I noticed that python comments in the code block have python keywords highlighted (when they shouldn't) .

    29 Jul 2009
    1. User avatar

      Azwandi Aris [Atlassian]

      The Code Block Macro does not support Python out-of-the-box. The default formatting will fall to Java, hence some Java keywords in the Python script may be highlighted where it shouldn't. You can use {code:none}...{code} if you want to avoid the highlighting.

      04 Aug 2009
  4. User avatar

    Anonymous

    Is there a way to define a line in the code block to be emphasized after syntax-highlighting?

    Often there is a need to point the reader to exactly one line in the source code (e.g. that must inserted or is the clue in the code) but not missing syntax highlighting for the rest. In LaTeX there is a parameter for this in the code macro.

    11 Aug 2009
    1. User avatar

      Sashidaran Jayaraman [Atlassian]

      Hi,

      As far as I know, this feature is not currently available in Confluence. However, I have found similar feature requests:

      Please add yourself as a watcher, vote for this feature and add your own comments to this feature request. For further details on how we include new features and improvements, you might want to read this page.

      Anyway, as a quick workaround, you could accomplish this by using a user macro trick. In order to create a new user macro:

      1. Go to Dashboard > Administration > User Macros
      2. Click Create a User Macro.
      3. Name your user macro anything that you want. eg: boldcode
      4. Tick "Macro has a body" and Use unprocessed macro body
      5. Change Output to "Macro generates HTML markup"
      6. In the Template, copy and paste the following:

      Once you are done with that, you can simply use this macro anywhere in your page by specifying the following in your wiki markup:

      By specifying this, the line that starts with '^' and ends with '$' will be bolded. However, there is a limitation with this approach. It can be used only one time in a {code} macro

      I hope that would be a good start for you. Feel free to change the code to suit your needs.

      Cheers
      JSashi

      11 Aug 2009
      1. User avatar

        Tin Pham

        It has almost been a year since anybody commented on http://jira.atlassian.com/browse/CONF-1179 and only 4 votes. I think Altassian documentation itself would benefit in being able to highlight areas of code to readers.

        Any chance this could be expediated despite the low votes or do I have to campaign for it?

        Thanks,

        Tin

        07 Jul 2010
  5. User avatar

    Andreas Camenzind

    How can I have the code block macro opitmized, so that it's shown with different background colors for each line?

    Mine always look boring :(

    29 Jan 2010
    1. User avatar

      Mark Hrynczak [Atlassian]

      You might want to try the New Code Macro which provides an improved UI.

      Cheers,
      Mark

      31 Jan 2010
  6. User avatar

    J. Michael Hammond

    We want to use the code macro (or something like it) to document how to configure our system.  Two specific things that would help a lot are being able to use boldface and italics within the code block.  For example, if I say

    You can set the "foobaric" parameter on the "gronk" object like this:

    I'd really like the string "value" to be in italics. Is there any way to do this?

    --JMike

    24 Feb 2010
    1. User avatar

      Sashidaran Jayaraman [Atlassian]

      Hi Mike,

      Currently the {code} macro's purpose is to disable all formatting which will be pretty useful in some case. However, I do understand that sometimes it's important to be able to highlight some text within the {code} macro. I have actually created a user macro that allows you to do this. In order to create a new user macro:

      1. Go to Dashboard > Administration > User Macros
      2. Click Create a User Macro.
      3. Name your user macro anything that you want. eg: formatcode
      4. Tick "Macro has a body" and Use unprocessed macro body
      5. Change Output to "Macro generates HTML markup"
      6. In the Template, copy and paste the following:
      7. Once you are done with that, you can simply use this macro anywhere in your page by specifying the following in your wiki markup:

      The first parameter in the {formatcode} is to specify the first position where the text should be formatted and the second parameter will indicate the last character position. The last parameter signifies the format. You can select any HTML text formatting here. For example: i,b,u

      Hope this helps.

      Cheers
      JSashi

      05 Mar 2010
  7. User avatar

    Anonymous

    Is it possible to make a wiki link insdie a code block ?

    For example, I would love to do something link

    20 May 2010
    1. User avatar

      Sashidaran Jayaraman [Atlassian]

      Hi,

      There's currently no direct way of doing this. However, by modifying my code above, I managed to come up with the following:

      The instructions for creating the user macro is same as above. In order to use this user macro, just type the following:

      The first parameter in the {mycode} is to specify the first position where the link should appear and the second parameter will indicate the last character position. The other two parameters are for the link (url) itself and the alias.

      Hope this helps.

      Cheers
      JSashi

      03 Jun 2010
  8. User avatar

    Anonymous

    All I see is a swirly line under "What you will get". Why is that???

    20 May 2011
    1. User avatar

      Mark Hrynczak [Atlassian]

      You probably have JavaScript disabled in your browser. Enable it, and you should see the code content with appropriate highlighting.

      23 May 2011
  9. User avatar

    Steve Goldberg

    Our developers prefer to have the code macro wrap rather than scroll. It is possible to edit the CSS to easily achieve this by putting in something like the following in the custom CSS:

    The downside of this is that it does not update the line numbers to reflect the wrapping. Is there a way to do this or is there a simpler way to achieve what I want without having to edit the CSS?

    23 May 2011
  10. User avatar

    Alexey Rashevskiy

    Hi!
    Is there is any way to customize text inside ? E.g. make some parts bold, to highlight them? Or make manually coloring for formats you don't support? For example you can create "custom" highlighting type where tag {color} will work. I want e.g. something like that:

    25 Jul 2011
  11. User avatar

    Anonymous

    the code macro in my experimenting displays tabs as 4 spaces in the viewer, but in the editor, displays them as 8 spaces. This needs to be configurable, both in the view (as a system preference, and maybe a code block option), and in the editor (as a personal preference)

    23 Sep 2011
  12. User avatar

    Jong Pyo Kwon

    Hi~

    Hangul(Korean language) in code block seem to be broken..

    input) 한글

    27 Sep 2011
    1. User avatar

      Anna Mikhaylova

      Hi,

      we have the same problem with russian language.
      This problem occurs with "Java" Syntax highlighting (Syntax highlighting by default).
      But Russian works properly with another Syntax highlighting, for example "Cpp"

      So we just change the default "Syntax highlighting".

      Anna.

      18 Oct 2011
  13. User avatar

    erockx

    I'd like to change the default "Syntax highlighting" and "Theme" values.  Is there someway to do this?  I'm comfortable hacking files if I need to.

    Thanks,
    Eric

    29 Sep 2011
    1. User avatar

      Stephan Vollmer

      You can edit the defaults in the Confluence administration section:

      • Menu Browse --> Confluence Admin
      • Configuration --> Plugins --> Manage Existing
      • Click on Show System Plugins
      • Click on Code Macro Plugin --> Configure
      • Now you can change the defaults
      29 Sep 2011
  14. User avatar

    Anonymous

    I've noticed that if i put a URL containing "http://" in an XML code block, the entire string disappears. For example, in a panel I'll put

    <test-property>http://www.google.com</test-property>

    And the same contents in a code block configured with xml as the language gives me

    Anyone else seen this?

    30 Sep 2011
    1. User avatar

      Vladimir Sorokin

      Yes, I've faced this strange behavior too, I've reported it in JIRA: https://jira.atlassian.com/browse/CONF-23378

      03 Oct 2011
  15. User avatar

    Anonymous

    hi i have made a task list with drop down options but once the page is refreshed they go back to blank, any ideas?

    11 Oct 2011
  16. User avatar

    Anonymous

    Is there any way that I can highlight my code inside of the code block?  I would like to make some of the lines red or green, any suggestions?

    19 Oct 2011
  17. User avatar

    Anonymous

    When I paste code into the Code block, the indent level is removed.  

    Try copy/pasting this:

    When I paste this into a Code block, I get this:

    Before version 4.0, I always edited the actual macros manually. Can't do this anymore, and the new Code Block widget makes copy/pasting blocks with indent levels impossible. Or maybe I'm missing something?

    Thanks

    19 Oct 2011
    1. User avatar

      Anonymous

      I have the same problem. Using google chrome or internet explorer as the browser doesn't make a difference.

      I've tried indent with: tabs, spaces, nonbreakable spaces (alt+0160) and normal space followed by nbsp, followed by normal, followed by nbsp, etc., none of these work.

       

      Kind regards, Ray

      20 Oct 2011
    1. User avatar

      Anonymous

      I also encountered this problem. It is however not limited to the code block, but appears to be a issue with the new editor itself.

      One possible workaround, which works for me, is to Insert->Wiki Markup macro, paste the code in there, pre- and suffix it with {code} and add the (pre-4.0) wiki markup macro commands (syntax highlighting, line numbers etc) or just insert it as is, click on the code block edit button and change it there.

      21 Oct 2011
      1. User avatar

        Anonymous

        Thanks for the workaround!  I was really not looking forward to having to retype all the code (including every single space, since the tab key doesn't insert a tab) in order to get the correct indentation.

        This seems like a MAJOR bug in the code block macro editor to me.  Without the workaround, it would be next to useless for anything more than a line or two of code.  Do any developers at Atlassian use Confluence internally?  If so, I can't imagine they wouldn't have fixed this.

        27 Oct 2011
        1. User avatar

          Anonymous

          I created a bug issue, please vote for it here: https://jira.atlassian.com/browse/CONF-23833

          10 Nov 2011
  18. User avatar

    Sandro Gehrig

    I don't understand why tabs are being removed, this is a very basic feature of a code-block i think. The structure of code is only with the supported syntax highlighting and the tabs.

    Thanks for any answers or suggestions

    25 Oct 2011
    1. User avatar

      Anonymous

      This has been quite annoying in confluence, also the new code editor breaks some config files we used to save as code blocks, since it always adds a space when you add a new line. I wish this would get fixed already, raw code inside code blocks should not be formatted in any way when added/changed/saved. When adding the code through the insert wiki markup plugin it works as expected, however modifying it after is impossible without another copy paste, this is hurting productivity a lot.

      28 Oct 2011
  19. User avatar

    Anonymous

    Huge problem for me also. Is there a place I can vote for a fix?

    09 Nov 2011
    1. User avatar

      Anonymous

      I created a bug issue, please vote for it here: https://jira.atlassian.com/browse/CONF-23833

      10 Nov 2011
  20. User avatar

    Kelvin Lim

    The removal of tabs when pasting code blocks is a major issue!  The "Insert Wiki Markup" workaround does work (thanks!), but it's extremely cumbersome since we have to delete the existing code block and re-insert it.  This really needs to be fixed ASAP.

    14 Nov 2011
  21. User avatar

    Anonymous

    I have the same Problem. I need the tab in my code. Fix it please!

    16 Nov 2011
  22. User avatar

    Anonymous

    This is not annoying!!!  I have tried to use the "Insert Wiki Markup" workaround as described above but this macro doesn't seem to be available for me.  Do I have to install this macro?  Is this a plugin that I need to download?

    24 Nov 2011
  23. User avatar

    Srdan

    I think I have figured out a workaround for the indentation; instead of creating a code macro and pasting the code in it (did not work), I created a wiki markup (Insert>>Wiki Markup), and added {code} to it, pasted my indented snippet, and voila - it worked. Created that way, you can later edit it with the Code edit dialog, choose syntax coloring style etc.

     

    ETA: I see now after reading all the comments, that this is a known workaround already!

    02 Dec 2011
  24. User avatar

    Ed Johnson

    Hello,

     Maintaining source code on our wiki by hand has become a burden. Instead of copy and pasting source code, I want to link to the source files from our version control system. These are available over http behind our firewall. 

    Does anyone know a way to do that AND still provide code syntax highlighting? (The iframe macro will include the source file, but does not appear to permit syntax highlighting.)

    Many thanks,

    Ed

    04 Jan 2012
  25. User avatar

    Sarah Kaye

    Even the Insert Wiki markup and pasting indented code into the code block doesn't work for me!! The indentation is immediately removed and I have to manually indent.

    What I don't understand is why it says in Jira that this issue was resolved! I'm working in 4.1

    18 Jan 2012
  26. User avatar

    Nataraj Basappa

    Hello, I am writing a length document with many code block marcos, for some reason half way through the page, border styling stops. As anyone encountered issue like this? or is there a way around to get to know which content is causing this.

     

    30 Jan 2012
    1. User avatar

      Nataraj Basappa

      Spent quite a bit of time removing parts and pasting it back and checking if it appears correctly and finally managed to find the culprit. Only if confluence had tool to validate the content before saving could have saved lot of time.

      31 Jan 2012
  27. User avatar

    Anonymous

    I want the same thing that Ed is looking for - the ability to use the Code formatting macro - but point the source to a URL (JIRA fisheye url representing the HEAD/raw source for a particular file)

    Has this been done - or is it possible?

     

    28 Feb 2012
  28. User avatar

    Laurence Vanhelsuwé

    Hi,

    We're a Jira/Confluence customer, and we're also a 100% Smalltalk shop. We're starting to have plenty of pages with Smalltalk code snippets, so we desperately want these snippets to be properly syntax highlighted. What voodoo is necessary to get Smalltalk syntax highlighting?

    21 Mar 2012
  29. User avatar

    Anonymous

    How would I put in custom syntax highlighting for my programming languange? 

    26 Mar 2012
    1. User avatar

      Anonymous

      A very strong plus 1 for being able to add own syntax highlighting definitions, or being able to import definitions from Vi etc.

      This can not be a unusual requirement considering so many other editors allow you to do this.

      13 Dec 2012
  30. User avatar

    Anonymous

    Can't paste text in on Safari?

    17 Apr 2012
  31. User avatar

    Nirdesha

    I want to add a link inside the code block. The link is to another page in the confluence space. But the code macro does not render links. Is there a fix or a workaround for this please?

     

    29 Apr 2012
  32. User avatar

    Anonymous

    "I don't understand why tabs are being removed, this is a very basic feature of a code-block i think." I quadruple this.  I can't paste into a code block w/o tabs being removed.  This is basic functionality and was reported months ago....

    31 May 2012
  33. User avatar

    Jose Sa

    When using the code macro there is a tool-tip with the hint "double-click to select code" which works as it says however the text that is copied to clipboard that way doesn't have "normal" spaces, causing problems for instance in shell executions or shell scripts.

    Selecting text only by dragging produces a different output, copying exactly the text that was written.

    For example using the following code snipt for bash execution

    {code:language=bash|title=sample code snippet in bash (try to copy/paste it)}
    if [[ "bogus" == "check" ]]; then
        echo "not suppose to see this"
    else
        echo "you should see this".
    fi || echo "something is wrong"
    {code}
    
    sample code snippet in bash (try to copy/paste it)

    Try to select the first line till the last and copy, then past in a linux bash shell.
    Then try to select all by double clicking and do the same to see the difference.

    I guess there might be some bug being introduced when doing double-click that is causing this effect. This makes very error prone to create some documentation page with code spinets (well formatted and indented) that users can copy/paste directly from it depending on "how" they select the text.

    I'm using Google Chrome.

    13 Jul 2012
    1. User avatar

      Jose Sa

      Further testing with other browsers I've noticed different behaviors:

      • Both Chrome and Opera behave similarly (work well with lines selection but not with double-click)
      • IE 8 works well with double click, but lines selection puts everything in one line (newlines are simply removed)
      • Firefox works well in either case
      16 Jul 2012
    1. User avatar

      Dan B

      I logged a bug about this, because it's really annoying (I use double click to 'select by word'). Please vote!

      CONF-28223 - Allow to disable the 'Hint: double-click to select code' 'feature' Open

      19 Mar 2013
  34. User avatar

    Anonymous

    When I try to export a page containing a code block to pdf/word. The code block isn't exported and instead an error message is shown:

    Error rendering macro 'code' : org/lobobrowser/html/gui/HtmlPanel

    Is there any way to fix this problem, since it it useful to use the codeblock in combination with the export feature

    16 Jul 2012
    1. User avatar

      Anonymous

      I have the same issue (Confluence 4.1). Any solution available?

      01 Aug 2012
    1. User avatar

      Martin Dubé

      Obviously I'm having the same issue as you guys. Sorry I did not saw this post before asking my question (below).
      I guess that your still waiting on a solution too. (sad) 

      22 Mar 2013
  35. User avatar

    Matthew Marichiba

    We need a code snippet that uses a macro to expand into a variable bit of text, but the \{code\} block stops macros from functioning inside it. Is there any way to get around this, a "pre-process this text" directive within a code block?

    For example, in the block below, we want to use redhat_url as a variable which will change from release to release.

    I'm open to different ways to do this, if a macro isn't the best way. I'd appreciate and tips. Thanks!

     

    06 Aug 2012
  36. User avatar

    Anonymous

    Is there a way to make the code macro stop using non-breaking spaces for indenting?  When I copy out of there and into SQL Server Management Studio Query Analyzer, that program thinks the non-breaking spaces are invalid and won't run the query.

    Maybe it's more of a bug in that product, I did open a ticket with them.

    09 Aug 2012
    1. User avatar

      Jose Sa

      Currently it seems to depend on which browser are you using and which copy/past method. See my post above.

      09 Aug 2012
      1. User avatar

        Bruce Krasnof

        Thanks, i didn't realize it was only related to the doubleclick action....I can work around that for now.

        09 Aug 2012
  37. User avatar

    Anita Fohrenkamm

    Is it planned to support syntax highlighting for D?

    26 Sep 2012
  38. User avatar

    Anonymous

    There seems to be an issue with language being overwritten when I Edit an existing Code Block.  Is there a way to edit Code Blocks without deleting the language setting (for syntax highlighting)?  I have tried everything I think of, but I can see no way to modify an existing Code Block without wiping the language.  It would be great if a field for language could at least be added to the Edit view.

    30 Oct 2012
    1. User avatar

      John Masson

      Not sure I fully understand the problem... Do you mean when the code block was inserted with a language that isn't in the dropdown list of languages you see when you edit the macro?

      09 Nov 2012
  39. User avatar

    Anonymous

    Its not possible to apply different themes to code blocks on the same page?

    By design or a bug?

    20 Nov 2012
  40. User avatar

    Anonymous

    Any chance we could get Objective-C syntax highlighting sometime soon?  Pretty please? (smile)

    08 Dec 2012
  41. User avatar

    Anonymous

    Any chance of better C++ syntax highlighting?  Currently Confluence seems to highlight keywords in one color, comments in another, and leaves everything else black.  How about something Emacs-like where I get one color each for method names, variables, types, comments, namespaces, and everything else?  I'd be even happier if you made the syntax highlighting customizeable so I could add some of these features myself.

    21 Dec 2012
  42. User avatar

    Martin Krischik

    It would be nice if the wiki parameter names where added to the table as well. After all the visual editor is not availabel in JIRA, FISHEYE etc. pp.

    10 Jan 2013
    1. User avatar

      John Masson

      Hi Martin, these are documented here.

      10 Jan 2013
  43. User avatar

    Anonymous

    Hi, I'm a TA and have been asked to put XML code blocks in our Confluence (we have IE 9). Ran into the same problem of loosing formatting. In the end the quickest,easiest way I found was to use Notepad:

    a) right click on the XML file and open with Notepad ...(this seems to work and maintain formatting unlike using copy/paste directly from IE)

    b) from Notepad EDIT > SELECT ALL

    c) from Notepad EDIT > COPY

    d) in Confluence, create a new entry using the CODE MACRO and select the format (HTML/XML in my case) and SAVE

    e) Place the cursor in the resulting code field on your page and from the IE toolbar select EDIT > PASTE ...(this seems to make a difference to just right-click mouse and paste)

    If I tried copy paste in IE then the formatting was lost.

    25 Jan 2013
  44. User avatar

    Pierre Hilson

    Like many other people, I would like a way to highlight some parts of the text in the Code Block to catch the eyes of the reader.

    A user macro would be fine but I still cannot find one that fits that need.

     

    01 Feb 2013
    1. User avatar

      John Masson

      Hi Pierre, in case you haven't seen it yet, there's a feature request for this. You might like to vote on and watch it - CONF-1571 - Ability to highlight "changed" part of {code} Open

      04 Feb 2013
      1. User avatar

        Pierre Hilson

        Thanks. I voted on it. In my case, I'm not just looking at a way to highlight some lines of the code block but be able to highlight easily a few discrete lines/words (and not having to give lines number in the block parameters :-/ ).

        As I see it in my case a yellow/green/red/cyan background color would be the best way to bring user attention but anything else would be OK too.

        04 Feb 2013
  45. User avatar

    Alistair Lowe

    Hi guys,

    Does anyone know how to add a new theme to the Code Block Macro? I've become quite fond of the colours and fonts used in Google's Android documentation i.e. http://developer.android.com/training/basics/activity-lifecycle/starting.html#launching-activity

    Cheers

    22 Feb 2013
  46. User avatar

    Adam Klinkosz

    It would be great to be able to distinguish some parts of code. What do you think? Simple highlight background color would be enough.

    21 Mar 2013
  47. User avatar

    Martin Dubé

    When doing and "Export to PDF" from the Tools dropdown menu in the page I get the following error message instead of the content wrapped within the Code Block Macro.

    Error rendering macro 'code' : org/lobobrowser/html/gui/HtmlPanel


    At first I thought that I had some plugins to update so I made sure that everything is up to date. But I still get this error message on EVERY browsers, from both my Mac OS X 10.6 and Windows XP sp3 computers, so it gat to be something missing from our server's set-up. Right ?

    22 Mar 2013
  48. User avatar

    Michael Wrighton

    Would you be willing to add Verilog and VHDL support to the Code Snippet widget? It would be extremely helpful for us (and anybody else who builds hardware) to have syntax highlighting for those languages.

    01 Apr 2013
    1. User avatar

      Sarah Maddox [Atlassian]

      Hallo Michael

      I've added a request to our issue tracker: CONF-28735 - Add Verilog and VHDL support to the Code Block macro Resolved

      If you like, you can watch and/or vote for the issue.

      Cheers, Sarah

      01 Apr 2013
  49. User avatar

    Steven Parsons

    Does anyone know how to adjust the default tab spacing in the macro? Currently it's set to 4 and we would like to set it to 3.

    thanks,

    I did notice within the Jar file it has a file called shCore.js that contains the tab info but when I change that and save it back to the jar, an re-upload. It does not change the tab size.

     

     

    11 Apr 2013
  50. User avatar

    Steven Parsons

    Could it be a caching issues after I made the change in the macro?

    How to clear Confluence plugins cache

     

    11 Apr 2013
  51. User avatar

    Markus Lepper

    The expand function works well...but why could one NOT collapse it again without reloading the page???

    Does someone knows if there is already a feature request (bug) which requests this collaps/expand toggle function?

    05 Jun 2013
  52. User avatar

    towolf00

    I am using the code macro to embed config files to confluence pages. so far so good. sometimes the config files are rather long and it would be good to collapse the parts of the config which is not relevant for the moment.

    is this something that maybe part of the macro sometime?

     

    Thanks

    12 Jun 2013
  53. User avatar

    froethen

    SyntaxHighlighter brush for emails which will highlight mail threads with different colours.

    Create a file shBrushEmail.js and upload to Confluence with Confluence Admin -> Configure Code Macro.

    shBrushEmail.js
    14 Aug 2013
  54. User avatar

    barnam

    I'm working on a document with lots of HTML code. There are two chunks of code near the bottom of the document that are placed in  code blocks. These two display properly in the page inside their boxes. However, any new code chunks will display, but without their box.

    Has anyone got any explanation for this? Any solution?

    Thanks

    14 Aug 2013
  55. User avatar

    Anonymous

    An example code block is breaking the page on save

     

    15 Aug 2013
    1. User avatar

      barnam

      I'm not sure I understand what it might be in this code sample that's breaking the page...

      Thanks,

      16 Aug 2013
  56. User avatar

    Anonymous

    Is there an option that makes the code macro appear inline instead of in a snippet?

    I want to be able to write small piece of code inside a regular statement, not in a dedicated box.

    20 Aug 2013
  57. User avatar

    Anonymous

    Support for R code would be nice...

    27 Sep 2013
  58. User avatar

    Anonymous

    Is there a neat way to specify optional parameters within a code block, any particular formatting that would help beautify the output?

    16 Oct 2013
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi, you might want to ask your question at Answers - users from the community may have suggestions for how you can further customise this macro, or perhaps create a user macro to achieve the results you are looking for. 

      21 Oct 2013
  59. User avatar

    Anonymous

    In our organisation, each user will have preferred defaults based upon their role. Rather than set one default for all users, It would be very useful if the defaults could be set on a per user basis. Additionally, it would be useful if this did not require admin rights, since not all our users have this right.

    24 Oct 2013
  60. User avatar

    Anonymous

    no Lua highlighting? how so?

    29 Oct 2013
  61. User avatar

    Mark

    I like the most recent changes to the code block, but now it never wraps. This causes some issues with the appearance of the content on the page. Is there an option to make it wrap and still count line numbers correctly?

    01 Nov 2013
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi Mark, there is an issue about wrapping and line numbers in the code macro here  CONF-23565 - Line wrapping throws off line numbering in code block macro Resolved . Feel free to comment or vote. 

      03 Nov 2013
  62. User avatar

    Anonymous

    Collapsible feature for code blocks is nice but would be better if the user can collapse the block after expanding it without have to reload the page.

    08 Nov 2013
    1. User avatar

      Markus Lepper

      Yes, this would be VERY helpful!!!

      08 Nov 2013
    1. User avatar

      Mark

      The latest version of the code block macro (at least in 5.1.2) now has this functionality. When you expand the source, a bar remains at the top of the code block with a link that allows you to collapse it without reloading the page.

      08 Nov 2013
  63. User avatar

    Anonymous

    It'd be great with syntax highlighting for Windows batch files.

    14 Nov 2013
  64. User avatar

    Anonymous

    Why aren't you using Markdown, this is a bit rediculous

    27 Nov 2013
  65. User avatar

    Jeremy Seely

     To add an additional language:

    1. Choose the cog icon at top right of the screen, then choose Confluence Admin.
    2. Choose Configure Code Macro.
    3. Choose Add a new language
    4. Locate your language file and enter a Name for the new language (this will appear when selecting the language).
    5. Choose Add.

     

    Is it possible to add additional languages (specifically lua) in Confluence 4.3?

    02 Dec 2013
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi Jeremy,  as far as I'm aware it is not possible to add additional languages in Confluence 4.3.  You can download later versions of the code block macro plugin  from the marketplace, but the later versions (that include this functionality) only appear to be compatible with Confluence 5 and later.  Sorry. 

      02 Dec 2013
  66. User avatar

    Natasha Pettit

    Is this macro actually supported for 5.4.2? It comes up on our list of problem-add-ons for upgrading, and its documentation states that it is functional only through 5.3.4, but the top of this page says "Documentation for Confluence 5.4." Can someone please confirm that the most updated version of this add-on plays well with 5.4.2? Thank you!

    28 Jan 2014
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      This add-on is bundled with Confluence, and is still supported in 5.4.2.    I'll investigate why it is coming up in the add-on check, it may be that the version on marketplace is listed incorrectly. 

      UPDATE: this has been updated in Marketplace now - so should no longer show incorrectly in the upgrade check. 

      28 Jan 2014
  67. User avatar

    Roberto Andrade

    Is there a way to provide multiple related blocks that will be rendered as alternatives to one another by showing say a tab selector or a drop down menu to pick which snippet you'd like displayed?

     

    This is especially useful in case providing same code in different languages but wihtou taking space on screen for all of them, showing only one at a time.

    13 Feb 2014
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi Roberto, there's nothing in the Code block macro to do that I'm afraid.  The only thing I can think of off the top of my head is to use the expand macro, and place your code block macro within it.   

      13 Feb 2014
  68. User avatar

    Hans-Hermann Hunfeld

    Hi there,

    a bit confusing that in the marketplace i cannot enter the according main page but only the version history. Was looking for any news regarding Confluence 5.6 compatibility as currently this macro is not working anymore:

    22 Sep 2014
    1. User avatar

      John Masson

      Hi Hans, we stopped showing plugins that are bundled with Confluence because people already have them so generally they just created 'clutter' on the Marketplace. They're still "there" so that UPM can update them when we release a new version, but not visible beyond what you found.

      Anyway, specific to your problem, you should definitely file a ticket with support.atlassian.com for them to take a look. 

      22 Sep 2014
  69. User avatar

    Denis Brulic

    After upgrade to Confluence 5.6.3 we are experiencing Unknown macro: 'code' Error?!

     

    26 Sep 2014
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi Denis, that doesn't sound good.  Could you please raise a support request about this?  Support will help investigate and then raise a bug if necessary. 

      26 Sep 2014
      1. User avatar

        Denis Brulic

        Hello Rachel,

        I did raise an official Support ticket for our company and took your advise too and created following ticket CONF-35094 - Unknown macro: 'code' Resolved

        This is very unusual bug.

        Best regards,
        Denis

         

        26 Sep 2014
  70. User avatar

    Zachary Buckholz

    Any updates on this problem?

     

    It's affecting several thousand sites in our confluence installation.

    Unknown macro: {pagetree}

    09 Oct 2014
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi Zachary, could you contact support directly about your problem. 

      10 Oct 2014
    1. User avatar

      Hans-Hermann Hunfeld

      Simply uninstall the macro in the addon-section and then update to latest Confluence version, this will fix the issue as the macro is bundled with Confluence itself.

      But, i don´t know why such a big issue which should impact many customers is not present at all Atlassian employees...

      10 Oct 2014
  71. User avatar

    Denis Brulic

    During Confluence installation Code Macro Plugin is disabled (System Add-on). After Enable everything is OK.

    10 Oct 2014
  72. User avatar

    Alexey E

    When it will be updated to become compatable with confluence >=5.6 ?

    04 Feb 2015
    1. User avatar

      Giles Brunning [Atlassian Technical Writer]

      Hi Alexey,

      The code macro is bundled with Confluence 5.6.x, so it should be available to you. If you can't see it I'd suggest you contact support so they can help you out, as you may be using an older (unbundled) version of the macro.

      04 Feb 2015
  73. User avatar

    Andrew Bilukha

    Most of the world runs on Windows, yet this plugin fails to provide DOS shell or batch file formatting. Pretty unuseful.

    25 Mar 2015
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi Andrew, I don't know the background on why these particular languages were included by default with this macro. But, check out the info in the page above about about configuring this macro - you can add as many syntax highlighting options as you like by uploading additional brush files.  I see this page has Batch http://www.undermyhat.org/blog/2009/09/list-of-brushes-syntaxhighligher/, plus lots of information on creating your own brush file.

      Hope this helps 

      25 Mar 2015
  74. User avatar

    Hans-Peter Geier

    we are facing a problem which may be related to the end-of-line characters (different for DOS vs Linux)  ??

    When copy/pasting multi-line text from the code macro , the result is different from the original code, and it is different by the browser in use.

    In MS-IE, an extra line feed is added after each line

    in Firefox, all line feeds are removed; the whole code block ends up in one single line.

    Both makes the code macro not useful anymore to paste code from a Confluence page into a command window (regardless whether DOS or Linux)

     

    Users tell me that it was OK in past (not sure how much "past"), and whether this problem was introduced by Confluence 5 or by a Browser update.

    Issue replicated in Confluence 5.4.4 and 5.7.3, and in MS-IE 11 (with and without compatibility mode) and current release of Firefox. (Chrome not tested)

    05 May 2015
    1. User avatar

      Hans-Hermann Hunfeld

      Hi Hans-Peter,

      we recognized the same issue as you, but please note that "CTRL + A" (or doubleclick) behaves different than simply copy & paste lines with mouse cursor. The first action is useless for re-use copied source code, the second option is working.

      A bit creapy, but this solves the issue for us at the moment...

      Best regards,
      Hans-Hermann

      05 May 2015
      1. User avatar

        Hans-Peter Geier

        hmm, I did copy the text using the mouse cursor.  <Ctrl>-A would copy the whole page, not just the content of the macro, so I didn't even try that.

        I would be happy if the 2nd option would work for me - it does not. (sad)

        05 May 2015
    1. User avatar

      Rachel Robins [Atlassian Tech Writer]

      Hi Hans-Peter, sounds very similar to these issues   CONF-34314 - Losing Line Break And Indentation When Copying from Code Macro Display Mode In IE9 to Text Editor Like WordPad and Notepad Resolved CONF-26702 - In IE8/IE9, when copying from a code macro in display mode into a code macro in edit mode, line breaks are missing Resolved ?

      If not, it would be great if you could raise a bug about this so our developers can investigate. Particularly if the behaviour has only recently started happening. 

       

      05 May 2015
      1. User avatar

        Hans-Peter Geier

        I have created CSP-146985

         

        What's concerning me, all these issues (those mentioned above and 2 more on this subject) are open for two years now with no attempt to fix them. (quote: "We have more important bugs to fix".  OK, - but I read this excuse in so many places, I wonder what they consider really important and work on? I think they work on new bugs introduced by 5.7.x, but omit all others which exist for many many years even when they are major or critical. Just look through this system and the JIRA database)

        Anyone alive at Atlassian (besides the Support team)?

        I wish Atlassian to fix all the major bugs before proceeding with developping any new functionality. Have them do a hard stop on development and do business basics. We pay for support and for bug fixes. The word "bug fix" doesn't seem to exist in the Atlassian dictionary.

        06 May 2015
        1. User avatar

          Minh Tran [Atlassian Bugmaster]

          Dear Hans-Peter,

          First of all, I would like to thank you for raising the concern about this one.
          I totally understand what you tolerated the bugs.
          I am sorry for any delay and low response in the tickets as well.

          I would like to share with you about the BugFixing team goal this year:

          • We have to assure no security bug in the backlog
          • Reduce the number of critical issues and target no critical issue till end of the year
          • Besides that, we also need to work on tickets causing the most customer friction (the JIRA issues are attached with a lot of Support tickets). We would like to solve those in order to help more people.

          I hope this will explain better about the way bugfixing team is working now.

          Best Regards,
          Minh Tran
          Confluence BugMaster
          Atlassian

          08 May 2015
  75. User avatar

    Kurt Frank

    If you put some code into a Code Block Macro and then select all of the code block and insert that into an Expand Macro it appears to look good.  When you try to expand the Expand Macro and then expand the Code Block, the Expand Macro will collapse.  You have to expand the Expand again to see the code.

    Not exactly the friendliest behavior.

    02 Jun 2015
  76. User avatar

    Alexey Kozulin

    Hello.

    Does anybody know when it will be updated to become compatable with confluence >=5.7 ?

    08 Jun 2015
  77. User avatar

    Ferdinando Villa

    The "Configure code macro" admin option seems to have disappeared after upgrading to Confluence 5.8.4. Hints on how to recover it would be greatly appreciated.

    21 Jun 2015
Powered by Confluence and Scroll Viewport