Highlighting code within a code block?

Is there a way to visually highlight a piece of code inside a {code} block in Confluence?

10 answers

1 accepted

This widget could not be displayed.

No, but you could 'make' your own macro of sorts to do this. Use something like:

{panel}{html}<pre> <insert_content_with_html_formatting> </pre>{html}{panel}

This way, the content inside is uses monospace formatting and allows you to use HTML markup (bold, italics, text and bg colors, etc) to distinguish pieces of code.

Interesting. I have a lot that I want to use {code} or {noformat} but put some lines or words in bold inside of that. Will try this.

Hi , Justin we also want the same functionlity , so you any written macro for the same. please do let us know.

This widget could not be displayed.

This issue should not be marked as solved.

If Github can do this, including providing an HTML anchor point for bookmarks and sharing URLs, why can't Atlassian? People pay money to use Atlassian but you can't provide equivalent service to a free competitor?

agree with you, this is really easy feature to implement, and really useful

This widget could not be displayed.

this is not solved, again: we need a way to highlight a new entry within a given piece of code to point new lines added.

Team Confluence, we really need a way to highlight the new lines of code. 

While creating a tutorial we need to tell developers what has to be done next in the code and which lines to be added in the code. 

So for this reason please develop a macro or configure the existing macro where we can highlight content within the code. 

OR at least provide a temporary solution in this forum. Looking forward to hearing from you guys! 



This widget could not be displayed.

I am able to do it with HTML block below on Confluence 5.8.17. 

function highlight(codeBlockName, lineNumber) {
  setTimeout(function() {
    $("div.codeHeader:has(b:contains(" + codeBlockName + "))").siblings(".codeContent").first().find(".code .line.number" + lineNumber).first().attr("style", "background-color: #ccc !important");
  }, 200);

highlight('MyCodeBlockTitle', 3);

Assumption is code block must have a title. It won't be hard to modify JQuery to reflect HTML structure changes.

You can put the function into a footer page and reuse it across your space.

This widget could not be displayed.
This widget could not be displayed.

Are you looking to highlight synatx based on the language? The ability to do this was shipped in Confluence 3.5. See here

This widget could not be displayed.

I'm not looking for general syntax highlighting. I'm looking more for a way to denote a specific piece of code within a block. Like, to actually highlight lines of code a all yellow, so they stand out.

This widget could not be displayed.

As of Confluence 3.5.X, I don't think this is an option. The idea behind the {code} blocks is that you'd include the important code as needed. I think that's also a reason for having Fisheye/Crucible, as they do real code reviews rather than what's "thrown together" under JIRA or Confluence.

As a work around, we in Support tend to put "<-- blurb" near the relevant parts we want to point out in bad config files or code.

That might be the idea behind it, but sometimes context within a code block is necessary, like context within a patch file so you can identify the area where someone might be needing attention.

Take the case of a tutorial where one might need to add lines to a piece of code, how would you achieve this?

This widget could not be displayed.

Hi Pro,

Did you get any solution for this, Please let me knoow.

This widget could not be displayed.

Does anyone know if this suggestion is an official feature request in Atlassian's JIRA? Thanks.

If you need one for JSON we have a macro for highlighting JSON syntax

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

496 views 7 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you