Closed GoogleCodeExporter closed 8 years ago
Pages which load code blocks dynamically using, e.g. jQuery, could really
benefit
from this (though i would recommend changing the class name to something less
likely
to conflict with client code, such as "google-code-prettified").
Original comment by sgbeal@googlemail.com
on 21 Feb 2009 at 11:46
Quote: "Google Prettify supports another API, prettyPrintOne(), which allows
you to pass in a string to be
prettified. "
http://www.codingthewheel.com/archives/syntax-highlighting-stackoverflow-google-
prettify
With this information I implemented the following in jQuery.
var my_html = '<html><head></head><body class="testing"><p id="hello">Hello
World</p></body></html>';
$('#code').append(<pre class="prettyprint"></pre>');
$('#code > pre:last').text(my_html).html(prettyPrintOne($('#code >
pre:last').html()));
// note: .text() calls the DOM method .createTextNode(), which replaces special
characters with their HTML
entity equivalents (such as < for <).
Original comment by i.chris....@gmail.com
on 25 May 2010 at 7:05
In reference to comment #2, This is a solution for most, but not all cases. I
have to agree with comment #1 about a non-conflicting CSS class. An example
case where #2 would be ineffictive at the least, involves getting back the
following snippet of HTML:
<div class='something'>blah blah blah</div><pre><code
class='prettyprint'>SomeCode</code></pre><span>Some more crap</span>
Not that it couldn't be done with #2's version, but it becomes more difficult.
It would be far easier if prettyprint could be run multiple times.
Original comment by plagueth...@gmail.com
on 22 Apr 2012 at 10:06
I actually fixed this but did not notice that this duplicate bug persisted.
Original comment by mikesamuel@gmail.com
on 23 Apr 2012 at 4:18
Fixed at http://code.google.com/p/google-code-prettify/source/detail?r=204#
Original comment by mikesamuel@gmail.com
on 23 Apr 2012 at 4:19
Simple fix remove class "prettyprinted" from the tag before calling
prettyPrint()
Original comment by gagandee...@gmail.com
on 4 Jan 2014 at 10:48
Original issue reported on code.google.com by
dirk.fre...@gmail.com
on 2 Jun 2008 at 7:18