Wednesday, April 01, 2009

Pasting RTF to HTML in blogs using Insert Formatted Clipboard plugin for Windows Live Writer

 

I’ve played with a few tools to post code to my blog and for sharing documentation.  I’m mostly interested in pasting T-SQL from SQL Server Management Studio(pasting RTF), but I also paste PowerShell scripts and batch files.

Now I’m trying the Insert Formatted Clipboard plugin from Noah Coad along with Windows Live Writer – both new to me with this post.  There was a painful install process(see comments by ITSOLVE) under Vista that involved renaming an .MSI file, executing msiexec from the command prompt, and manually copying a DLL file.  In XP I had no problems with the install.

On to usage.  I copied the T-SQL from SSMS

0054

to the clipboard, and then, in Windows Live Writer clicked
Insert >> Formatted Clipboard…
0055
Here’s what pasted:

SELECT '-- ' + cast(@@SERVERNAME as char(16)), cast(db_name() as char(20)), getdate()

Ahh.  Cleanly converted HTML from an RTF paste – with inline styles.  Hallelujah!  You may notice that the pasted text does not contain the proper monospaced typeface.  I’m ok with that, as I would normally wrap that text in a border with a monospaced font.  Read on.

Sometimes I just want to wrap the code with a border following the styles created at Format My Source Code for Blogging.

<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> 



</code></pre>



So, using the above html I can paste inside the <code> </code> tag and it comes out like so:

SELECT '-- ' + cast(@@SERVERNAME as char(16)), cast(db_name() as char(20)), getdate() 

Nice, eh?


Additional notes:


If I’m careful within Windows Live Writer I can highlight & copy the text that was created from the Insert >> Formatted Clipboard… step, then double-click on the newly created empty border and paste right into the border style without using the Source Tab.


The other Windows Live Writer plugin used above to display the <pre> style from Format My Source Code for Blogging was Code Snippet by Leo Vildosola.

If you’d like to dive even further into RTF, HTML, and related macros for Visual Studio, see Steve Nyholm’s blog.

No comments: