h13i32maru / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

PHP + HTML #226

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
code:
<pre class="prettyprint linenums">
&lt;meta charset=&#34&lt;?php bloginfo('charset'); ?>&#34 />
</pre>

result:
<meta charset="<?php bloginfo('charset'); ?>" />

do not prettify tag "meta"

Original issue reported on code.google.com by shtrih.m...@gmail.com on 1 Jul 2012 at 10:20

GoogleCodeExporter commented 9 years ago
I too have noticed this issue,

Is it possible to prioritize or run prettify twice so it parses HTML first 
before the enclosed PHP tags?

Maybe allow for two language hints in the class like the following so it runs 
twice:

<code class="prettyprint lang-html lang-php"> ... </code>

Thanks

Original comment by karoloch...@gmail.com on 5 Apr 2013 at 9:53

GoogleCodeExporter commented 9 years ago
Found a temporary hack around which isn't ideal but does get the job done.

Split out the enclosed PHP tag into another pre tag and replace it with a 
unique id which I also included as the id of the new pre, so for example using 
OP's code:

<pre class="prettyprint linenums">
    <meta charset="[php-replace-123]" />
</pre>

<pre class="prettyprint" id="php-replace-123">
    <?php bloginfo('charset'); ?>
</pre>

My site has jQuery loaded, so used it to receive the prettify complete event 
and then injected the PHP code into the original tag before destroying the 
temporary pre tag:

<script type="text/javascript">
    window['exports'] = {prettify_replace: {apply: function(win, arg) {
        $('pre[id^=php-replace-].prettyprinted').each(function(i, ob) {
            var id      = $(ob).attr('id');
            var html    = $(ob).html();

            $("pre").each(function () {
                $(this).html($(this).html().replace('['+id+']',html));
            });

            $(ob).remove();
        });
    }}};
</script>

With the following for loading prettify's js file:

<script 
src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?call
back=prettify_replace"></script>

Again, not ideal but does work.

Original comment by karoloch...@gmail.com on 5 Apr 2013 at 11:24