使用Prettify和尖括号

时间:2013-05-22 18:36:09

标签: html blogs

我想在我的博客中包含这个java代码(这是封闭的前缀):

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

但是因为它有几个尖括号,Blogger进入并自动填充所有推断的标签,将该块转换为以下内容:

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

然后显示为:

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);
    }
}

这与我试图呈现的代码不同。我认为这个问题源于html将我的东西与带有HTML标签的尖括号混淆。有没有办法让解析器忽略所有这些?我尝试将所有尖括号更改为&amp; gt和&amp; lt并获得以下输出:

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);
    }
}

1 个答案:

答案 0 :(得分:0)

html实体以分号终止:

  • &lt;
  • &gt;