THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Merrill Aldrich

Technical content about Microsoft data technologies. All opinions expressed are purely my own and do not reflect positions of my employer or associates.

Getting Less Stupid about HTML Code Formatting

This is probably old news to many people, but sometimes I'm a slow learner.

So far, getting neat, color-coded code from Management Studio or Visual Studio into passable Blog-ready HTML has ... well ... mostly made me go, "Aaarrrrrggghh grrrr @*%$^#&! grrrr aaarrrgg <repeat>." I've tried several online code prettifiers, and even Word (yech) but it's painful to take code from one tool, paste it into a formatter, format it, take source out again, correct it with elaborate regex find/replace, repeat. Redgate has a nice tool for T-SQL code formatting inside Management Studio, but it doesn't, in my version at least, help with the HTML bit at all.

I know many people are very, very careful to meticulously hand format their code, and while I completely appreciate the desire for neat code and try to write neatly myself, I can't quite stomach all the extra hours spent pressing the spacebar, when a tool could do a very nice job. In C# I'm the first to admit I am completely spoiled by Ctrl+K Ctrl+D. High formatting value from minimum biological effort.

After my last post, which was long on code and very frustrating to format, I am onto this tool: which looks more like it. Visual Studio > Highlight > Copy > HTML Editor or Browser > Paste > Aah. What computers are supposed to do.

We'll see if this lessens my pain on the next post.

[Edit 4/23/2010]

I took ALL the commenters' advice to heart, and after spending way too much money I have a great solution: I got a MacBook Pro (Aaron) plus vmware Fusion and Windows 7 back in January. Then I was able to start using Windows Live Writer (Adam), and add the vspaste plug-in (Dave). Lastly, Red Gate SQL Prompt Pro has a really nice pretefier that works inside SSMS, and while it doesn't make HTML directly it does neatly format the code. I can finally write something sloppy, then go Ctrl-K Ctrl-Y Ctrl-A Ctrl-C <click Live Writer> Paste, Post. Sweet!

Published Tuesday, November 24, 2009 12:04 AM by merrillaldrich

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



jamiet said:

Hi Merrill,

Digressing slightly.... on the subject of CTRL+K, CTRL+D feel free to vote for this up on Connect:

"Format Document" in SSMS


On CopySourceAsHtml - I used to use it back in VS2005 days but it stopped working for me (I know not why) and I've ignored it since then. Maybe its time to give it another try - thanks for this!



November 24, 2009 3:58 AM

merrillaldrich said:

Will do

November 24, 2009 11:23 AM

AaronBertrand said:

I use simple-talk's prettifier ( with the HTML style of "Forums - Use FONTs and PRE".  To make it work with community server (which ignores just about every CSS attribute I've tried) and to meet my own anal retentiveness, I do these things:

- remove extra carriage returns

- change the font colors for keywords simple-talk doesn't understand

- in the HTML editor, replace the opening <pre> tag with this:


<table background="#eeeeee" bgcolor="#eeeeee" cellpadding="0" cellspacing="0"><tbody>

<tr bgcolor="#eeeeee">

<td bgcolor="#eeeeee">

<pre style="padding: 10px 20px; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; font-size: 12px; font-family: consolas,lucida console,courier new,courier; -moz-background-inline-policy: continuous;">

- still in the HTML editor, place this after the ending </pre> tag:


November 24, 2009 11:53 AM

merrillaldrich said:

Hi Aaron - Good tip. I have been doing something like that - from SSMS to SimpleTalk, format, back into a text editor for an HTML massage. It does work, and their prettifier is the best browser-based one I've tried. I just fantasize about cutting this process down to write code / write post / click Submit :-)

November 24, 2009 12:52 PM

AaronBertrand said:

Yep, click click boom would be much better, I agree.  :-)

November 24, 2009 10:50 PM

daveballantyne said:

Live Writer with this  ( ) plug-in works fine.

November 25, 2009 7:49 AM

AaronBertrand said:

Dave, while it seems odd, I write 95% of my blog content from a Mac, where Live Writer is obviously not an option.  But hopefully that plug-in will be useful for anyone else, since I would imagine that most SQL bloggers write from Windows.  :-)

November 25, 2009 10:14 AM

SSIS Junkie said:

I found out about a tiny feature in SQL Server today that I never knew about and Mladen Prajdic persuaded

November 25, 2009 3:21 PM

SSIS Junkie said:

The new T-SQL MERGE statement in SQL Server 2008 seems to be finding many uses over and above its de

January 6, 2010 1:46 PM

Valentino Vranken said:

@Dave: thanks for the link to vspaste!!  I'm also a big fan of WLW and had tried about 4 different code plug-ins so far.  And I must say, vspaste is really the best one as far as I'm concerned! It supports both VS and SSMS, which covers most of my code snippets so, well, I don't think I need to say more.



February 7, 2010 5:11 PM

silk said:^Eescort.html^Eescort.html^Eescort.html^Eescort.html

February 9, 2019 8:30 AM

Leave a Comment


This Blog


Privacy Statement