Freigeben über


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

  • Anonymous
    February 17, 2014
    Wow, interesting stuff! And a pretty important guidance for creating good Wiki articles.
  • Anonymous
    February 19, 2014
    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!
  • Anonymous
    February 19, 2014
    Great article Matthew!
  • Anonymous
    February 19, 2014
    This is really interesting! What are the text editors you recommend, Matthew?
  • Anonymous
    February 19, 2014
    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?
  • Anonymous
    February 20, 2014
    You make some great points here. I've always used Notepad myself.
  • Anonymous
    February 23, 2014
    Good Tips. Thank you
  • Anonymous
    March 05, 2014
    There is a saying, "A picture is worth a 1000 words". I'm sure you've heard the idea
  • Anonymous
    April 02, 2014
    You just finished witting an awesome article, what should you do next? Get up from your desk and stretch
  • Anonymous
    April 25, 2014
    congratulations
  • Anonymous
    August 20, 2014
    Earlier this year I wrote a series of posts about writing good articles. It's been a while since
  • Anonymous
    March 19, 2015
    Due to some practical issues while switching screens during presentation, the recording of the screen
  • Anonymous
    March 19, 2015
    Due to some practical issues while switching screens during presentation, the recording of the screen
  • Anonymous
    September 09, 2017
    Great article