Copy and Paste

Image of author

Wayne Hanley

Senior Web Developer

“[Luke:] I can’t believe it. [Yoda:] That is why you fail.” – Yoda

We all do it, probably many times over the course of a day. The usual muscle memory shortcut combo of 'Ctrl + c' followed by 'Ctrl + v' (or 'Cmd + c/v' for you Mac users) to copy and usually shortly afterwards paste some text.

Using an office suite such as Microsoft Office or similar you have likely not given a second thought to copy and paste. Rightly so why should you? You want to copy something from one place and put it in another in your document? Simple!

At the highest level yes it is. We, however, need to take a step back from that higher level understanding and take a closer look. For example when we are taking what is copied and used in another application. An excellent, relevant example of this is taking some content written in Word and then using it on a page in T4.

Let's break it down a little and understand more about this process.

All about Word

Firstly let's discuss Microsoft Word specific to this example. To be more precise the document format Word uses to save a file is what we need to understand.

When you create a Word document behind the scenes what is happening without you knowing is you are creating what is, in essence, a webpage. As an example, let us consider adding a title to your document. One way to do this, you might either change the font size to be bigger, and we also make it bold and underlined. Next, you add a few paragraphs of text. Let's dissect what happened in the background has Word created your document in a manner much like a webpage would be created. When you make some text bold what is happening behind the scenes is the selected text in question is wrapped in tags. These tags are the same sort of tag as those used in HTML to create web pages.

Understanding this is as much as we need to know in discussing the Microsoft Words document format and how formatting applied.

Copy and paste

Bearing in mind what we have learned about Microsoft Words file format we continue to Copy and Paste in more detail.

When using the Copy and Paste function in Word (for example) using either the menu or the keyboard shortcut 'Ctrl + c' what we are asking the computer to do by default is duplicate the selected text verbatim this includes the formatting. It is this copy of formatting by default that causes issues. Referring back to our earlier example of the title of our document, we have some text this is a larger font, bold and underlined. The copy of the title also contains this formatting.

Let us then assume we go and paste that text using the menu or the shortcut 'Ctrl + v', what is placed into T4 would be something similar to the following;

<font size='20'><b><u>Title of document here</u></b></font>

Here we can see the tags we discussed earlier. As we used the default Copy and Paste function, the selected title text but also the formatting is duplicated.

Doing it the right way

Since these tags override those used in the templates that are used to create pages in T4 errors occur. Avoiding these errors is trivial doing so requires a simple change in how you Copy and Paste.

Copy as you usually would and use then use the Paste from Word button in T4 Menu. See Fig 1. This strips out the formatting tags Word inserts and copies just the text

The inserted text can now be given the approved heading style within T4 as usual. 

Copy from Word
Fig 1: Paste from Word button

TL;DR:

Too much info, your takeaways from this post are;