Display ANSI color text in Confluence

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2017

Hello,

I have a file generated by *git diff* which basically shows different in commits for a specific file with nice color on the terminal windowt. The file has ANSI color codes - http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html

Basically I want to display the contents of the file inside confluence while retaining the color ( i.e. ansi color code red for text means text is displayed as red in confluence) . I know I can do it by converting ansi to html and then pasting the html in confluence but html macro is disabled in confluence due to security reasons thus, how to retain color while displaying ansi file 

A sample line is 

-As part of the script listener, the only change which is required is

 

Here <-31m means RED color and the whole statement should be displayed as red in confluence. And the arrow sign in the beginning is for the escape. 

 

I am using Confluence server 6.3.4

 

 

2 answers

1 accepted

1 vote
Answer accepted
Davin Studer
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.
December 20, 2017

There are some javascript libraries that can convert it for you ... links below. You could create a user macro that passes the $body into a javascript variable. At that point it is just straight javascript and html and you could render it out the page without needing to enable the html macro.

https://github.com/drudru/ansi_up

https://github.com/rburns/ansi-to-html

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2017

Thanks will give this approach a try!

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 21, 2017

Works well!

0 votes
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2017

Tarun,

I'm not sure if you were aware but you can enable the HTML macro if you did want to use it. See HTML Macro > Enabling the HTML Macro for more info.

Regards,

Shannon

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2017

Hi @Shannon S

Ofcourse, I know about this, as I have shared in my description

 html macro is disabled in confluence due to security reasons (due malicious JS)

Thus, I will try the user macro approach with "Rendered html" option rather than letting users use the html macro.

Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2017

Tarun,

I did indeed understand that you were aware it was disabled, I wasn't sure if you knew it was possible to enable.

Thank you for confirming you will be able to edit using the User Macro option.

Kind regards,

Shannon

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events