How do you wrap a code snippet in a code block macro?

Aravind Jayaraman
Contributor
May 2, 2018

Every time I add a code snippet into a code block macro, the code snippet remains in a single line without wrapping itself into multiple lines, unless I manually break the code snippet and bring the command into multiple, separate lines.

Is there a setting or property within the code block macro that I can set to wrap itself?

3 answers

10 votes
Giovanni Tirloni
Contributor
September 8, 2022

I can't believe I'm looking for how to wrap lines in 2022.

Deleted user September 16, 2022

Same here.

Although in the old confluence editor code snippets were wrapped by default. So frustrating if new releases set you back.

Like # people like this
Hagai Barel
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!
March 1, 2023

Still looking for this in 2023

Like # people like this
-
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!
March 1, 2023

See this - https://confluence.atlassian.com/doc/code-block-macro-139390.html and help us convince Atlassian guys to simply add a parameter.

Like # people like this
Randy Neumaier
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 18, 2024

According to the above documentation, in version 9.1, Atlassian introduced a user side code wrap option:

2024-11-18_12-58-49.png

Like Russell Vinegar likes this
7 votes
Stephen Cheesley _Adaptavist_
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 3, 2018

There is actually a suggestion open for this with Atlassian (CONFSERVER-31476)

There is currently a workaround which is to add the following CSS to the global stylesheet (see the bug for more details)

.codeContent .syntaxhighlighter table td.code .container .line {
    white-space: normal!important;
}

I've tested it in the latest version of Confluence and you can add this to the Space CSS (Space Tools > Look and Feel > Stylesheet). This might be better approach as it will only apply for the given space. Remember, though, this will apply the style to all pages in the space with that macro, not just one.

I hope this helps!

joseph.rubenstein
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!
March 7, 2019

Worked like a charm.

Thank you so much.

Daniel Alonso
Contributor
September 18, 2020

I tried on my own and the code still looks non-wrapped:

Code is inside the code block:

code-1.pngconde2.pngWhat am I missing?

Daniel Sputa
Contributor
October 21, 2020

Hi,

 

I would point out that cloud users have no option to modify the global stylesheet to add this workaround. Unless someone has an idea how to implement this?

is there a different app or plugin that would help us to achieve the code wrapping?

 

thx.

Like # people like this
2 votes
-
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!
March 1, 2023

Dear Atlassian,

To be able control whether to line-wrap or not, you can add to a parameter to the Code Block Macro, which already has lots of interesting parameters:

https://confluence.atlassian.com/doc/code-block-macro-139390.html

Please do this improvement in the macro.

Thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events