googlearchive / code-prettify

An embeddable script that makes source-code snippets in HTML prettier.
Apache License 2.0
5.79k stars 905 forks source link

PHP syntax highlight does not support namespaces #313

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Code is:

<pre><code>catch (\PDOException $e) {
  $error = $e-&gt;getMessage();
</code></pre>

P in the class name should be the same colour as the rest of the name, only \ 
should be different. But the result is:

<pre class="default prettyprint prettyprinted" style=""><code><span 
class="kwd">catch</span><span class="pln"> </span><span 
class="pun">(</span><span class="pln">\P</span><span 
class="typ">DOException</span><span class="pln"> $e</span><span 
class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span 
class="pln">
  $error </span><span class="pun">=</span><span class="pln"> $e</span><span class="pun">-&gt;</span><span class="pln">getMessage</span><span class="pun">();</span></code></pre>

I'm using Stack Exchange version 
(http://drupal.stackexchange.com/a/91283/16495) - probably latest stable 
release. It happens on all major browsers.

Original issue reported on code.google.com by ext.rmol...@gmail.com on 6 Nov 2013 at 9:56

Attachments:

amroamroamro commented 8 years ago

confirmed: https://jsfiddle.net/amroamroamro/5u7v6aoy/

So \Exception shows up fine because \E is treated as plain followed by xception also as plain, then both get combined as plain. But \PDoException is parsed as: \P plain, then DoException is treated as type name.

This bug is not specific to PHP, it's the way the generic highlighter incorrectly handles an escape token followed by a type names (starting with an upper case letter).

It's related to 11c71c4d which fixed issue #144