SOLVED

Why does Teams always strip indentation when pasting text?

Brass Contributor

It's fairly common to want to post code in teams (without using the special formatting for code snippets).

The markdown like syntax for code works pretty well when typing code and it preserves indentation. But when you paste XML or JSON all the indentation is removed. Why?

Here's an example:

my-kl_0-1620853640676.png
That XML was indented in the source. But whenever we paste JSON or XML we lose indentation. Unless we take the extra effort to use a code snippet. Or manually type it for small examples.

57 Replies
This is on macOS, colleagues tell me they don't have an issue on Windows.
Ok some more sleuthing:

If I copy from Visual Studio Code and paste into Teams (on macOS) this problem happens.

If I copy from TextEdit or Visual Studio and paste into Teams, the indentation is fine.

So this is weird interaction between Teams, the clipboard and Visual Studio Code.

But, I can copy from Visual Studio Code into TextEdit and everything is fine. Then I can copy from TextEdit and paste into Teams and everything is fine.

Anyone have a firm understanding of how the clipboard works and what app might be working incorrectly? Seems perhaps Teams is confused by meta data from Visual Studio Code?
Using this website I was able to examine the clipboard data from TextEdit and Visual Studio code.

The text/plain entries look identical, but the text/html entries are radically different. That seems to be a clue.
best response confirmed by ThereseSolimeno (Microsoft)
Solution

@my-kl 

So I got to the heart of the matter. I used the Clipboard Inspector to inspect the contents of clipboard when copying the same text from two different apps. Both have two entries. One of the entries is text/html and one is text/plain. The text/plain as you might guess is identical. The html is quite different. I then copied the html and rendered.

This is what I see from TextEdit

 

my-kl_1-1621015953588.png

This is what I see from Visual Studio Code

 

my-kl_0-1621015929280.png

So this would appear to be an issue with my environment in Visual Studio Code (or even a defect in Code, I"m not sure)

 

This can probably be closed. I've added details to an already opened issue on GitHub: https://github.com/microsoft/vscode/issues/122050#issuecomment-841814182

@my-kl This definitely should not be closed, I do not use vscode and I still have the following issues on OSX\MSTeams:

1. no markdown support (some garbage WYSIWYG constantly interfering with my typing).
2. ``` no longer creates code blocks 90% of the time. In fact, the closing ``` becomes a weird empty code block more often than the opening code block ever works.
3. pretty much everything I paste into MSTeams has it's formatting removed, so nobody can read it.

@michaelfs 

 

3. pretty much everything I paste into MSTeams has it's formatting removed, so nobody can read it.

Good to know. Could you list some of the programs you've tested with. As I've learned, I can copy from TextEdit into Teams without issue. So my work around is copy/paste from VS Code into TextEdit and then copy/paste from there into Teams. With respect to VS Code it seems to be a VS Code issue. I also can copy/paste from Visual Studio without problem.

 

What programs are you having trouble with. I'd be interested in trying to reproduce.

@michaelfs 

 


1. no markdown support (some garbage WYSIWYG constantly interfering with my typing).
2. ``` no longer creates code blocks 90% of the time. In fact, the closing ``` becomes a weird empty code block more often than the opening code block ever works.


Seems like a different issue. I have found that markdown for code blocks doesn't work for me in "Chat" but works just fine in "Channels". I would have expected it to work everywhere.

Yop,
I had the habit of pasting using CTRL+SHIFT+v inside a monospaced block created with triple backquotes.
Indent was OK.
Since few weeks, it doesn't work anymore.
Indent is lost.
Not sure why
You're right.
I didn't pay attention.
It only works now on channels
Another thing which doesn't work too on chats: CTRL+A to select all when you write a message.
It worked by the past.
Now, it only works on channels' conversations
Yes - definitely still an issue. A couple of weeks ago, the regular ``` stopped switching immediately to a code box. Now it requires a space after it, and then it does not retain formatting. As noted elsewhere, this is only broken in Chats. The original (functional) behavior is still present in channels.

@pedorro Thanks for that tip. I didn't realize you could force code blocks by typing a space after ``` . I've resorted to using quote mode for code. This is nice to know.

As mentioned by a colleague, it's probably related to the following new functionality:
- Respond to a specific message in chat whith quoted replies
I'm using PyCharm and have the same problem.

I can paste into a code block in a channel just fine, but if I paste into a conversation I lose indenting.
In fact, it's not just indenting.
Multiple spaces in a middle of a string are replaced by only one.
I guess it's because monospaced paragraphs uses html formating instead of having "pre" block behavior.
For the past few weeks I have this problem on Windows 10 and VS Code

I started to observe the issue with stripped spaces and tabs for preformatted text pasted may be month ago (Windows 10).
The most annoying thing is inserting the code parts (even from Notepad or Notepad++).
Is there any workaround for this?

Turns out you can paste into a monospace block in a channel, copy the text back out and then paste into a monospace block in a chat and it works. You don't need to actually send the message to the channel.

It's a pain but it works.
1 best response

Accepted Solutions
best response confirmed by ThereseSolimeno (Microsoft)
Solution

@my-kl 

So I got to the heart of the matter. I used the Clipboard Inspector to inspect the contents of clipboard when copying the same text from two different apps. Both have two entries. One of the entries is text/html and one is text/plain. The text/plain as you might guess is identical. The html is quite different. I then copied the html and rendered.

This is what I see from TextEdit

 

my-kl_1-1621015953588.png

This is what I see from Visual Studio Code

 

my-kl_0-1621015929280.png

So this would appear to be an issue with my environment in Visual Studio Code (or even a defect in Code, I"m not sure)

 

View solution in original post