If you want to display an XML fragment in a WordPress post – how do you do that?
Suppose you want to display this:
<family> <dad>whatever</dad> <mom>whatever</mom> </family>
Using the [sourcecode language="xml"]
does not help, as it mangles up the XML.
Also, I believe, plugins cannot be used with free version of WordPress ( i.e wordpress.com ) – so, probably that won’t be an option.
Using HTML <pre>
tag works, but it does not give correct look and feel.
Can any one show me how they have done it?
The wordpress codex has a whole page about writing code in your posts.
http://codex.wordpress.org/Writing_Code_in_Your_Posts
Their suggestion is to use html entity codes within
<pre>
or<code>
tagsThis could be tedious if you have a lot of code to show in your post. I suggest writing a small shortcode that would do this for you.
How to use your shortcode in a post
If [sourcecode] is available but you cannot install additional plugins or add shortcodes (which is the case on wordpress.com), you have, to my knowledge, no other option than to encode the problematic characters before copying them.
Here are the detailed steps:
I suffered from this problem recently.
For me what worked was to enter the code in text mode. Selection of code. Application of
code formatting
from the Format menu.Later, I used the crayon syntax highlight plugin. The plugin works well, you have to follow the same process as above with the only difference that instead of
code formatting
option, choose thecrayon
option after selecting the code to highlight.You can check the highlighting here
WordPress.com now has built-in support for code highlighting in a variety of languages using the
[code]
shortcode. I find that I still have to use html entity codes when highlighting XML, but other languages work well (JavaScript, C#, etc.), and it looks much better to the reader than your basic<pre>
or<code>
tags.