How do I paste code into Code Block with preserved indentation?
Asked by Jiri Pik:

In the past, when I pasted indented source code into a Code Block, it preserved the indentation.

Now, whenever I paste any source code, any leading spaces are removed, no matter how I paste - Paste as Plain Text or pure Paste.

How to fix?


Answers:
author: Diego
body: Hello [@Jiri Pik](/t5/user/viewprofilepage/user-id/1105340) !

As I understand, the Code Block macro is not respecting the indentation after copying code and then pasting it inside the macro.

I tried it first in our Cloud Platform with the new editor (Fabric). It behaved as expected. Here is what the original code looks like:
> ![Screen Shot 2020-09-08 at 16.55.23.png](https://community.atlassian.com/t5/image/serverpage/image-id/109586i16576829EF354690/image-dimensions/505x194?v=v2 "Screen Shot 2020-09-08 at 16.55.23.png")

Here is what the code looks in Confluence in edit mode:
> ![Screen Shot 2020-09-08 at 16.56.49.png](https://community.atlassian.com/t5/image/serverpage/image-id/109590i46B91E647F48A8C5/image-dimensions/447x274?v=v2 "Screen Shot 2020-09-08 at 16.56.49.png")
>
And in View Mode:
> ![Screen Shot 2020-09-08 at 16.57.03.png](https://community.atlassian.com/t5/image/serverpage/image-id/109589i8289E7A1448A3A3D/image-dimensions/425x229?v=v2 "Screen Shot 2020-09-08 at 16.57.03.png")

Now, I did the setup of a Confluence Server version 7.6.1 and the results were the correct ones too:

Edit Mode
> ![Screen Shot 2020-09-08 at 16.55.33.png](https://community.atlassian.com/t5/image/serverpage/image-id/109587i50F0A662248E173A/image-dimensions/511x117?v=v2 "Screen Shot 2020-09-08 at 16.55.33.png")

View Mode
> ![Screen Shot 2020-09-08 at 16.55.52.png](https://community.atlassian.com/t5/image/serverpage/image-id/109592iA9FC60EC7456ADDA/image-dimensions/489x161?v=v2 "Screen Shot 2020-09-08 at 16.55.52.png")

With these results, I would like to ask you a few questions:
> 1. *What version of Confluence are you using?*
> 2. *Is this happening regardless of the browser being used?*
> 3. *Would it be possible for you to share screenshots of a "dummy" code as an example?*

Keep in mind that our community is an open space and everyone can see everything posted here. So take extra care not to disclose any sensitive information within the screenshots.

Let us hear from you!

comments: author: Jiri Pik
body: Hello:

Check this <https://www.screencast.com/t/wirC0mJvE6>

The server is Confluence 7.7.3. It actually did work until a month or two ago.

The problem does exhibit itself in Chrome and Edge.


author: Diego
body: Hello there [@Jiri Pik](/t5/user/viewprofilepage/user-id/1105340) !

I was able to replicate this behavior consistently in both Confluence 7.7.2 and 7.7.3. Here is the bug report I filed:
> * ++***[\[Confluence Server\] Pasting text on the Code block macro removes leading white spaces](https://jira.atlassian.com/browse/CONFSERVER-60296)***++

The best course of action would be to vote and watch the report. The only workaround I found was to manually indent the code.

Let us hear from you!


author: Jiri Pik
body: THANK YOU.


author: Eetu Salpaharju
body: Found workaround for this problem:

1. Paste your code outside of CodeBlock macro
2. Format pasted text to preformatted
3. Cut\&paste formatted block inside of CodeBlock macro.


author: Aliaksei Prybytkouski
body: Workaroung for me:

1. Paste text to CodeBlock and add few spaces manually

2. Copy your code from the block and paste to Notepad++ (I shwithed on "View-\>Show Symbol-\>Show White Space and TAB)"

3. Select "space" symbosl combination from the Notepad++ editor

4. Replace all double spaces \\ tabs in your original code to "space" symbol from p3


author: MS
body: Similarly, it also removes the _existing_ linebreaks before and after your paste location. To be clear: if I paste a single line (or word) in between 2 lines that are separated by two or more linebreaks, those all get removed and it becomes one line, with the pasted content in the middle.

How does this happen..

comments: author: Arad Bar Sadeh
body: Solved it for me. thanks!


author: David Hempy
body: SOLVED for VSCode: {#toc-hId--411401583}
----------------------------------------

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


author: Jesilyn Barnes
body: Try to paste the code lines from Postman...does that work?


Tags: confluence-server

server