Sometimes I need to post C++ code on forums or blogs that don't offer direct support for that. On these sites, the online editor allows you to directly modify the HTML code, but this is not the simplest or most enjoyable thing to do. Because I wanted C++ syntax highlighting so hard, I decided to create a little tool to automate this task as much as possible and to allow me to focus on the real subject.
Using the code
The result is cpptohtml.exe that takes a .cpp file as a command line argument and generates a .html file. If no file name is provided as argument, a standard "file open" dialog allows the user to specify the source .cpp file. The tool also accepts /C as a command line argument that specifies the source code is taken from the clipboard and the HTML result is also put in clipboard.
- Open your preferred IDE and copy the C++ source code into the clipboard.
- Launch the tool using the shortcut key combination. The HTML result is available in the clipboard.
- Paste the formatted HTML in the online blog editor.
Points of interest
The archive also contains a .js script to automate the shortcut creation. I am pretty happy with the final result and how C++, LEX, and JScript is combined to automate a boring repetitive task.
External download link: http://codecentrix.blogspot.com/2007/05/blogs-and-c-syntax-highlighting.html.