My favorites | Sign in
Google
                
New issue | Search
for
| Advanced search | Search tips
Issue 40: Allow to run prettyprint multiple times
3 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----
Type-Defect
Priority-Medium


Sign in to add a comment
 
Reported by dirk.frederickx, Jun 02, 2008
What steps will reproduce the problem?
1. Run prettyprint() twice: the 2nd run causes previous rendered <pre> or <code> blocks to 
loose there formatting. 
2.
3.
(Please include HTML, not just your source code)


What is the expected output?  What do you see instead?

I would expect prettify to skip the blocks which already have been formatted.
This is especially useful when running prettify after eg ajax calls.

What version are you using?  On what browser?
vs 31 Aug 2007

Please provide any additional information below.

Suggeted implementation::
I changed prettify.js to add a 'prettified' class to each block when rendered.

         //mark the element as converted
         cs.className = cs.className+' prettified';

Then added a simply check of this classname when entereing the doWork loop

      /* added classname 'prettified' to avoid double processing */
      if (cs.className 
       && cs.className.indexOf('prettyprint') >= 0 
       && cs.className.indexOf('prettified') == -1 ) {




 
Comment 1 by sgbeal, Feb 21, 2009
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").
Sign in to add a comment