Highlighting code within a code block?

John Malone
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 25, 2011

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

16 answers

1 accepted

4 votes
Answer accepted
justindowning
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2011

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.

Wim Deblauwe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2011

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.

Avdhesh Chauhan July 15, 2014

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

40 votes
Deleted user August 1, 2017

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?

Juan Vasquez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 9, 2017

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

Like # people like this
17 votes
Juan Vasquez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 9, 2017

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.

schapsl October 25, 2017

Agree.

ashutosh joglekar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 9, 2018

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! 

Thanks, 

Ash.

Like # people like this
13 votes
Eugen Labun
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 28, 2018

Hello Atlassian's people! The problem is still not solved. Since 2011...
Please note: it's not about general-syntax highlighting, it's about *additional* highlighting for a piece of otherwise already syntax-highlighted code.

The "accepted" solution from May 30, 2011 doesn't solve the problem, because the general syntax highlighting (e.g. Java, XML) gets lost.

We need highlighting of code lines, like this:
Sharing Line Highlights in GitHub Files (see screenshots there!)

12 votes
Prakash Nadar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 16, 2018

Its so frustrating that this can't be done. Please add support to highlight code lines inside the code block 

6 votes
Patrick Henry Costello
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 30, 2019

Agree - I would really like to be able to highlight parts of codeblock yellow

6 votes
John Malone
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 25, 2011

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.

3 votes
Rene Minder
Contributor
December 18, 2019

Just got Atlassian support to open https://jira.atlassian.com/browse/CONFSERVER-59278 for us. Please vote for it.

1 vote
trung
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 29, 2017

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

<script>
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);
</script>

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.

0 votes
weweave UG
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 7, 2020

Even though this question is quite old, for Confluence Cloud you can give our app Prism Syntax Highlighter for Confluence (see https://marketplace.atlassian.com/apps/1222532/prism-syntax-highlighter-for-confluence) a try. Our app includes an option to highlight single lines or sections (like line 3-7). You can even highlight multiple lines and/or section. A live demo is available here https://weweave.atlassian.net/wiki/spaces/CONFPRISM/pages/932905118/Live+Demo.

0 votes
Matthew Grover May 1, 2020

Hi all,

I've created a plugin that lets you highlight parts of code or pre-formatted text which you want to highlight which should solve the problem discussed here. It is available here: https://marketplace.atlassian.com/apps/1222433/custom-code-highlight-for-confluence. Please let me know if this helps solve your issue or if there are features missing which you'd like,

thanks,

Matt 

0 votes
Stephen Kairys
Contributor
January 30, 2017

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

Marcel Nick July 14, 2017

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

0 votes
Avdhesh Chauhan July 15, 2014

Hi Pro,

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

0 votes
TylerA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2011

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.

Brett Ryan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2017

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?

0 votes
Matt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 25, 2011

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

0 votes
Matt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 25, 2011
 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events