Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I paste code in comments and maintain indentation?

Stephen Wilson
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 13, 2022

I'm at my wits end with this. Its not just Jira, but code snippets are generally terrible replacements in HTML based windows. I get how HTML playsd with whitespace, but I feel like this has all gone back to the dark ages as far as development goes.

I just want to paste code in to a ticket comments, whether it is with the code snippet short cut button "<>" and maintain a few tabbed indentations.

Other tools like MS Teams implement this, in equally bad ways where the code is unreadable.

 

I'm not expecting an IDE, but the atrocious manner for code in comment mark up is stunning.

2 answers

0 votes
David Hempy November 21, 2023

I share OP's frustration. I'm trying to copy in a chunk (20 lines) of space-indented JSON into a Jira ticket comment. No matter how I paste it, not only are indenting spaces removed, line-ends are removed, wrapping all lines of the JSON into a single line.

 

I have tried: 

  • `code` blocks
  • `preformatted` blocks
  • `preformatted` style
  • Manually typing some space-indented code before pasting, as suggested in another thread.
  • `Paste and match style`
  • I've pasted into a text editor (VSCode) and re-copied to clear formatting.

All fail identically. 

I'm using Chrome on a Mac.

David Hempy November 21, 2023

SOLVED?

I just tried pasting and re-copying to vi, and THIS WORKED! Formatting was preserved to the Jira comment. 

I then went back to VSCode and changed the Language Mode from JSON to Plain Text, copied the text, and this also successfully pasted into the Jira comment, with indents. 

So apparently VSCode is doing something "interesting" when copying code from a JSON-language editor. I repeated this experiment from Sublime editor in Plain Text and JSON language modes, and it always pasted correctly into Jira, preserving the indents and line feeds. 

I suspect many of the threads complaining of this problem, that get "not reproducible" responses are reflections of the application copying the text in the first place, not how Jira pastes the text. 

David Hempy November 21, 2023

SOLVED for VSCode

Go into Settings and search for `copyWithSyntaxHighlighting`, which is ON by default. Turn that crap OFF and resume a happy life. 

Like bwelch likes this
0 votes
Ivan Lima
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 14, 2022

Hi @Stephen Wilson, welcome to the Atlassian Community.

I've been using the code snippet, and it works fine for me. It gets a bit messy if it's a large snippet, but I'd say it probably shouldn't be there if it's a large one.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events