Source Code Highlighting - In Blogger!
There are a great many posts on how to post syntax highlighted code in blogger. I can’t really understand why google doesn’t have a ready made solution in place.
I think I’ve found a solution I’m comfortable with:
- Convert the code to html (“:TOhtml” in vi)
- In the Compose tab, type:
<pre> </pre>
- Paste you code between the tags
- Publish
That’s it - no installation, not too much hassle.
For extra credit, you can modify the css for <pre>
sections.
If you want line numbers:
- “:set nu” - show line numbers in vi
- “:TOhtml” - convert to html
- “:set nonu” - remove line numbers for easy copy & paste (or, use Ctrl-V)
1 #include <stdio.h>
2
3 int main( int argc, char *argv[] ) {
4 printf("Hello World!\n");
5 return 0;
6 }
All that’s left is to find a good color scheme for vi.
edit: Ars Pythonica has added that in your .vimrc file, you can add: “let html_use_css = 1” to include css in the output.
Thanks to:
- Eli Bendersky - for the pre trick
- FluidBlog - For the vi TOHtml trick