Well Formatted Blog, Can't Directly Copy from MS Word
Wow! Well I just had to go back through all my posts and repost them all. It seams that one can not directly copy and paste from a Microsoft Word document to achieve a nicely formatted blog.
Invalid XML code is the end result causing the RSS feed to break. This not only affects my blog’s feed, but also the main MSMVPS.org feed.
Thanks to Miha Markic for pointing this out quickly before I had posted much more than the first 10 initial posts!!
http://www.rthand.com/
I’ve spent much time checking and rechecking the RSS feed and it is now verifiable XML. Thank goodness! BUT it can’t currently be validated by the most common online RSS validator because it BOMBS (see next post)! You can however validate it is a valid XML file with a simple XML parse like my previous post shows.
Much thanks to Roy Osherove's blog on “Pasting nicely formatted code into your blog” which explains the correct steps to use.
http://weblogs.asp.net/rosherove/archive/2004/02/05/67957.aspx
Here are the steps from Roy’s blog that work well:
- Write the code in VS.NET
- Paste it into a new Word document
- Save the document as HTML (filtered) (or .Text will have trouble with it)
- Close the doc, then re-open it without changing any text after that (this is an important step)
- Copy the code from the doc into your blog post
Word is a great way to compose the post. I use a single celled table with a white background for the code window and set the tabs to .25”. This allows me to just copy and paste from Visual Studio.
Here is a VB Script that is based off of the script by Roy. I recommend making a Blog.dot Word Template, putting this in the module, and putting a button on a toolbar to access the code. Then base blog posts off of the template.
|
Sub FormatCodeForBlog()
ActiveDocument.Save
ActiveDocument.SaveAs FileName:="Blog-Temp.htm", FileFormat:=wdFormatFilteredHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
ActiveDocument.SaveAs FileName:="Blog-Temp2.htm", FileFormat:=wdFormatFilteredHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=False, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
RecentFiles(1).Open
Selection.WholeStory
Selection.Copy
RecentFiles(2).Open
Dim doc As Document
For Each doc In Documents
If doc.Name = "Blog-Temp.htm" Or doc.Name = "Blog-Temp2.htm" Then doc.Close
Next doc
MsgBox "Proper blog compatible XHTML has been copied to the clipboard."
End Sub
|
The code may seam strange with the two files going on but I found that if you close the active document, the macro stops. Since the file must be reloaded, a second file is created then the first opened. This macro also returns you back to your original document.