Wiki Life: Cut'N'Paste


Ctrl+C and Ctrl-X are one of the most used key combinations on my keyboard (only just out ranked by Ctrl-Z)! But there's more to Crtl-C / Ctrl-X than meets the eye!

The clipboard supports multiple formats of the data stored in it. So what does that mean? These quotes from Clipboard Formats best explain this:

"A window can place more than one clipboard object on the clipboard, each representing the same information in a different clipboard format."

"For example, suppose a user copies styled text from a word-processing document. The window containing the document might first place data on the clipboard in a registered format, such as RTF. Subsequently, the window would place data on the clipboard in a less descriptive format, such as text (CF_TEXT). When the content of the clipboard is pasted into another window, the window retrieves data in the most descriptive format it recognizes. If the window recognizes RTF, the corresponding data is pasted into the document."

Herein lies the problem; you think you're pasting just the text, but you're actually pasting in additional formatting. The additional formatting often overrides the styles used on the wiki. This can lead to inconsistent formatting of text (fonts, font-sizes, font-colors), strange indenting (tabs), and hard to read html (if you ever need to use the HTML view of the Wiki editor)!

The best approach for copying content from other sources is:

1. Copy the text from the source
2. Paste the text into a text editor (like notepad or notepad++). This will strip out all the formatting (as notepad/text editors generally only support pasting text, without advanced formatting)
3. Format the text in the text editor (add/remove tabs, fix line spacing, add/remove carriage returns, etc)
4. Copy the text from the text editor into the Wiki text editor

Just for fun, here is a comparison of HTML created from copying code out of Word. The first example demonstrates the HTML generated when the text is copied directly from Word to the Wiki editor. The second example uses the technique described above.

*Note: While creating this example, I noticed that the Wiki editor now prompts you to clean up the formatting of the content being pasted from Word. When I tested this in different browsers, I got different HTML results from both browsers (IE10 and Chrome). 

Original text from a Word 2013 document:

HTML Produced from Word text copied directly into the Wiki Editor

HTML produced by copying the text to a text editor first, then formatting the text in the Wiki editor

HTML produced by copying the text from Word into the Wiki editor, and selecting to clean up the formatting (Internet Explorer)

HTML produced by copying the text from Word into the Wiki editor, and selecting to clean up the formatting (Chrome)

See Also

Other Posts in this series:

Comments (13)

  1. Peter Geelen - MSFT says:

    Wow, interesting stuff! And a pretty important guidance for creating good Wiki articles.

  2. Durval Ramos says:

    Good tip. To keep my examples colorful code (as in the Visual Studio editor) I use the MS Word and really appears much unnecessary HTML code. I will use your example and compare the best solution. Thanks!

  3. Alan Nascimento Carlos says:

    Great article Matthew!

  4. Ed Price - MSFT says:

    This is really interesting! What are the text editors you recommend, Matthew?

  5. Matthew Yarlett says:

    Thanks Ed! I love Notepad++. It has a number of handy plugins (like the XML tools and source control plugins), and handy formatting functionality (like being able to highlight text vertically and split views). What text editors do other people recommend?

  6. Richard Mueller says:

    You make some great points here. I’ve always used Notepad myself.

  7. Davut EREN - TAT says:

    Good Tips. Thank you

  8. Anonymous says:

    There is a saying, "A picture is worth a 1000 words". I'm sure you've heard the idea

  9. Anonymous says:

    You just finished witting an awesome article, what should you do next? Get up from your desk and stretch

  10. hassan sayed issa20014 says:

    congratulations

  11. Anonymous says:

    Earlier this year I wrote a series of posts about writing good articles. It’s been a while since

  12. Anonymous says:

    Due to some practical issues while switching screens during presentation, the recording of the screen

  13. Anonymous says:

    Due to some practical issues while switching screens during presentation, the recording of the screen