When code is inserted to Medium, all the spaces or indentation is lost

medium

I wonder why when I typed 3 back ticks (`) and then use CMD v (on the Mac) to paste some code into Medium, all the indentation / spaces are lost. I have to manually add the spaces back and indent every line.

The same issue with CMD Option 6 on the Mac.

Is there a way to make it work?

Usually, we have the code in the programmer's text editor such as Sublime Text, Atom, or Visual Studio Code, and we copy the code there and paste it to Medium. To make it better, we usually press CMD [ (open square bracket) to reduce the indentation level so that the first line is not indented at all. And then we copy and paste to Medium. But Medium doesn't take the spaces.

Best Answer

I'm using Windows and following trick helps me:

I copy text from IDE/editor and paste it into standard Notepad application, then copy it from Notepad and paste it into Medium.

Probably using TextEdit on Mac could help with disappearing spaces on a Mac.

However, I would suggest using GitHub's gists because it looks much more stylish than standard Medium's code styling:

Standard code block: standard code block:

Embedded gist: Embedded gist: