Blogger Prettify – Using Prettify for Blogger with Angle Brackets in Code

blogger

I want to include this java code in my blog (this is with the enclosing pre's):

<pre class="prettyprint">
public Vector<Instruction> decodeTree(Tree<String> gene) {
    Vector<Instruction> ret = new Vector<Instruction>();
    ret.add(decodeString(gene.getValue()));
    Vector<Tree<String>> currentLayer = gene.getChildren();
    Vector<Tree<String>> nextLayer = new Vector<Tree<String>>();
    for(int i=0; i<currentLayer.size(); i++) {
        for(Tree<String> t: currentLayer.get(i).getChildren()) {
        nextLayer.add(t);
    }
}
</pre>

But because it has several angle brackets, Blogger goes in and autocompletes all the inferred tags, transforming that chunk into the following:

<pre class="prettyprint">public Vector<instruction> decodeTree(Tree<string> gene) {
    Vector<instruction> ret = new Vector<instruction>();
    ret.add(decodeString(gene.getValue()));
    Vector<tree tring="">&gt; currentLayer = gene.getChildren();
    Vector<tree tring="">&gt; nextLayer = new Vector<tree tring="">&gt;();
    for(int i=0; i<currentlayer .size="" for="" i="" ree="" tring=""> t: currentLayer.get(i).getChildren()) {
        nextLayer.add(t);
    }
}
</currentlayer></tree></tree></tree></instruction></instruction></string></instruction></pre>

Which then shows up as:

public Vector decodeTree(Tree gene) {
    Vector ret = new Vector();
    ret.add(decodeString(gene.getValue()));
    Vector> currentLayer = gene.getChildren();
    Vector> nextLayer = new Vector>();
    for(int i=0; i t: currentLayer.get(i).getChildren()) {
        nextLayer.add(t);
    }
}

Which is different from the code I'm trying to present. I think the problem originates in the html confusing my things with angle brackets with HTML tags. Is there a way I could get the parser to ignore all that? I tried changing all the angle brackets to &gt and &lt and got the following output:

public Vector&ltInstruction&gt decodeTree(Tree&ltString&gt gene) {
    Vector&ltInstruction&gt ret = new Vector&ltInstruction&gt();
    ret.add(decodeString(gene.getValue()));
    Vector&ltTree&ltString&gt&gt currentLayer = gene.getChildren();
    Vector&ltTree&ltString&gt&gt nextLayer = new Vector&ltTree&ltString&gt&gt();
    for(int i=0; i&ltcurrentLayer.size(); i++) {
        for(Tree&ltString&gt t: currentLayer.get(i).getChildren()) {
        nextLayer.add(t);
    }
}

Best Answer

You're putting this into a post? In the post-editor, in the bar at the right, there's a Options section near the bottom, which allows you to say "do not interpret HTML" code. Choosing this option makes Blogger present exactly what you entered.