WP-Markdown treating java generics like HTML tags

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

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

Related posts

Leave a Reply

2 comments

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

  2. 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');
    

    Usage:

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

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