A personal repository of technical notes. - CSC

Copy Formatted Source Code Into Blog Entry

Problem
Need to be able to display copied source code from editing tools with original formatting in a blog entry.

Solution
Use a combination of Microsoft Word and manual editing to generate the necessary markup.

Note: These steps were tested with blogspot.com and Word 2010.
  • Copy code to clipboard from editor such as Visual Studio, MS SQL Server Management Studio query, etc.
  • Paste into Word.
  • Replace all < with &lt;
  • Replace all > with &gt;
  • Copy code from Word.
  • Paste into blog post in "Compose" mode.
  • Publish.

Note: These steps were tested with blogspot.com and Word 2003.
  • Copy code to clipboard from editor such as Visual Studio, MS SQL Server Management Studio query, etc.
  • Paste into Word.
  • Replace all < with &lt;
  • Replace all > with &gt;
  • Copy code from Word.
  • Paste into blog post in "Compose" mode.
  • Switch to "Edit Html" mode.
  • Copy entire content from blog post.
  • Paste into text editor.
  • Delete all content before the first "<style>" tag.
  • Replace all occurrences of "</p>  <p" with "</p><p".
  • Put tag at beginning: "<pre>".
  • Put tag at end: "</pre>".
  • Copy code from text editor.
  • Paste into blog post in "Edit Html" mode.
  • Publish.

No comments:

Post a Comment