WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With some Java generic code in a code block, ie:

List<Integer> l = new ArrayList<Integer>();

WP-Markdown was treating as HTML, and no matter what I did, the code above got turned into something like

List<Integer> l = new ArrayList</Integer><Integer>();</Integer>

Is there any way to get WP Markdown to behave better with this kind of code? Gist and (clearly) Stackexchange don't have this problem.

share|improve this question

I was trying to fix this for the longest time as well. It seems that the problem is not the rendering, but the editor - when you save, it updates your post.

I found a checkbox under Settings -> Writing called "WordPress should correct invalidly nested XHTML automatically". Unchecking this checkbox fixed the problem.

share|improve this answer

You could write a shortcode to pass your Java code into that runs htmlentities on it. That should get it to display correctly.

function clean_java($atts, $content)
    return htmlentities($content);

add_shortcode('clean_java', 'clean_java');


[clean_java]List<Integer> l = new ArrayList<Integer>();[/clean_java]

WP thinks your Java code is HTML code. Essentially, make it HTML code instead.

share|improve this answer
You would think this would happen automatically for a code block... – Doug T. Feb 22 '13 at 13:39
Yea, not sure what WP's code markdown actually does. – Nicholas Pickering Feb 22 '13 at 15:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.