Need help? Check out our Support site, then

How to paste source code in blogs

  1. 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?

  2. From the forum search box several relevant threads

  3. It seems that the pre-tag is a partial solution to the problem. Templates keywords keep modifying the output. Can you help me?

  4. Nope...

    If you want something like:

    void main(){<br /> cout >> "Hello World";<br /> return;<br /> }

    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.

  5. you need to make sure all your code uses html characters. (e.g. &lt; instead of < ). easiest way is to paste your code into the visual editor, then switch to the code tab to add the <pre> tags

  6. 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!

  7. 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...

  8. 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.

Topic Closed

This topic has been closed to new replies.

About this Topic