How to paste source code in blogs
-
I have several examples in C++ programming languages, which I’d like to post on my blog. I tried to use the tag “
". However, due to certain fragments of the code (templates, class keyword, etc.) the output looks awful. Do you know a universal way of parsing the .cpp file? -
From the forum search box several relevant threads http://wordpress.com/forums/search.php?q=source+code
-
It seems that the pre-tag is a partial solution to the problem. Templates keywords keep modifying the output. Can you help me?
-
Nope…
If you want something like:
void main(){
cout >> "Hello World";
return;
}where void, cout and return are blue; main() is black and “Hello World” is bold… the solution I see to this is you formatting the code in HTML first and then pasting the formatted code into the editor… this process can be very laborious, though.
-
you need to make sure all your code uses html characters. (e.g.
< instead of < ). easiest way is to paste your code into the visual editor, then switch to the code tab to add the<pre>tags -
devblog, no – I am not talking about syntax coloring. The C++ language introduces templates – this technique means usage of “template <class T>” keywords etc.
sunburntkamel, I’ll try it!
-
sunburntkamel, your way seems to work! But why does the tab character (by me it is 4 spaces) disappear? It is strange to loose the indentation of a source code…
-
wordpress does funny things to text when it’s posted. the
<pre>tag used to preserve it, i don’t know what’s wrong with it these days.the tab character’s width may also be represented differently in HTML than in your editor.
- The topic ‘How to paste source code in blogs’ is closed to new replies.