大家好,我使用SyntaxHighlighter作为博客代码高亮的插件,使用<pre class="brush: cpp"> source code </pre> 的形式,SyntaxHighlighter官网提示使用<pre>标签,必须把小写转换为&lt; ,后来我自己又发现必须把 && 转换为 &amp;&amp; ,现在又提示错误,我实在找不出原因,求助.代码如下:
<pre class="brush: cpp">
    void BasicsCaller()
    {
        struct node* head;
        int len;
        head = BuildOneTwoThree(); // Start with {1, 2, 3}
        Push(&head, 13); // Push 13 on the front, yielding {13, 1, 2, 3}
        Push(&(head->next), 42); //push 42 into the second position yielding {13, 42, 1, 2, 3} 
        len = Length(head); // Computes that the length is 5.
    }
</pre>
错误提示如下:
REXML could not parse this XML/HTML: 
<pre class="brush: cpp">
    void BasicsCaller()
    {
        struct node* head;
        int len;
        head = BuildOneTwoThree(); // Start with {1, 2, 3}
        Push(&head, 13); // Push 13 on the front, yielding {13, 1, 2, 3}
        Push(&(head->next), 42); //push 42 into the second position yielding {13, 42, 1, 2, 3} 
        len = Length(head); // Computes that the length is 5.
    }
</pre>

解决方案 »

  1.   

    $code = <<<cpp
    void BasicsCaller()
      {
      struct node* head;
      int len;
      head = BuildOneTwoThree(); // Start with {1, 2, 3}
      Push(&head, 13); // Push 13 on the front, yielding {13, 1, 2, 3}
      Push(&(head->next), 42); //push 42 into the second position yielding {13, 42, 1, 2, 3}  
      len = Length(head); // Computes that the length is 5.
      }
    cpp;
    echo '<pre "class="brush: cpp">'. htmlspecialchars($code) .'</pre>';另外如果要使用cpp的语法高亮,需要预先加载 scripts/shBrushCpp.js 脚本文件
      

  2.   

    我不太明白你是什么意思,不过我还是试了一下,不行。我已经加入了shBrushCpp.js,并且开始使用了,大部分情况下都可以,偶尔会出来两个像上面这种诡异的情况,实在不知道什么原因。
      

  3.   

    我找到原因了 &( 这两个字符也是特殊字符,会出错