nbell12 / google-code-prettify

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

Suggested Improvement (regexp classname search) #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

The hard-coded class name is too inflexible for code which is already in
production, a VERY small tweak will allow the prettyfier to work on any
existing class name.  

At the top of the code insert the following line.

var prettyClass = new RegExp('prettyprint','i');  

Replace the following lines...

---
if (cs.className && cs.className.indexOf('prettyprint') >= 0) {
with
if (cs.className && cs.className.search(prettyClass) >= 0) {

---

And

---
p.className && p.className.indexOf('prettyprint') >= 0) {
with
p.className && p.className.search(prettyClass) >=0 ) {

---

This allows for the className to be quickly and easily changed in one
single spot and makes the search case-insensitive which further reduces
errors on legacy code.

Original issue reported on code.google.com by phunl...@gmail.com on 23 Mar 2007 at 10:18

GoogleCodeExporter commented 8 years ago
How about instead of exposing prettyClass, I expose the function that gets the 
list
of DOM nodes to rewrite, and then callers can override that?

Original comment by mikesamuel@gmail.com on 27 Mar 2007 at 6:56

GoogleCodeExporter commented 8 years ago
closing for lack of response

Original comment by mikesamuel@gmail.com on 8 May 2007 at 6:12