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.

2 Answers 2


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.


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.

  • 1
    You would think this would happen automatically for a code block...
    – Doug T.
    Feb 22, 2013 at 13:39
  • Yea, not sure what WP's code markdown actually does. Feb 22, 2013 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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