You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/08/12 17:47:30 UTC

svn commit: r685201 [4/4] - in /incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/webdocs: ./ admin/ applets/ images/ scripts/ scripts/fckeditor/ scripts/json-rpc/

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/webdocs/scripts/prettify.js
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/webdocs/scripts/prettify.js?rev=685201&r1=685200&r2=685201&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/webdocs/scripts/prettify.js (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/webdocs/scripts/prettify.js Tue Aug 12 08:47:28 2008
@@ -1,29 +1,1481 @@
-// See http://code.google.com/p/google-code-prettify/
-(function () { 
-var F={};(function(){var b=["abstract bool break case catch char class const const_cast continue default delete deprecated dllexport dllimport do double dynamic_cast else enum explicit extern false float for friend goto if inline int long mutable naked namespace new noinline noreturn nothrow novtable operator private property protected public register reinterpret_cast return selectany short signed sizeof static static_cast struct switch template this thread throw true try typedef typeid typename union unsigned using declaration, directive uuid virtual void volatile while typeof",
-"as base by byte checked decimal delegate descending event finally fixed foreach from group implicit in interface internal into is lock null object out override orderby params readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var","package synchronized boolean implements import throws instanceof transient extends final strictfp native super","debugger export function with NaN Infinity","require sub unless until use elsif BEGIN END","and assert def del elif except exec global lambda not or pass print raise yield False True None",
-"then end begin rescue ensure module when undef next redo retry alias defined","done fi"];for(var c=0;c<b.length;c++){var a=b[c].split(" ");for(var d=0;d<a.length;d++){if(a[d]){F[a[d]]=true}}}}).call(this);function r(b,c){if(undefined===c){throw new Error("BAD");}if("number"!=typeof b){throw new Error("BAD");}this.end=b;this.style=c}r.prototype.toString=function(){return"[PR_TokenEnd "+this.end+(this.style?":"+this.style:"")+"]"};function q(b,c){if(undefined===c){throw new Error("BAD");}this.token=
-b;this.style=c}q.prototype.toString=function(){return"[PR_Token "+this.token+(this.style?":"+this.style:"")+"]"};function u(){this.next=0;this.ch="\u0000"}var J={lt:"<",gt:">",quot:'"',apos:"'",amp:"&"};u.prototype.decode=function(b,c){var a=c+1,d=b.charAt(c);if("&"===d){var f=b.indexOf(";",a);if(f>=0&&f<a+4){var h=b.substring(a,f),i=null;if(h.charAt(0)==="#"){var e=h.charAt(1),g;if(e==="x"||e==="X"){g=parseInt(h.substring(2),16)}else{g=parseInt(h.substring(1),10)}if(!isNaN(g)){i=String.fromCharCode(g)}}if(!i){i=
-J[h.toLowerCase()]}if(i){d=i;a=f+1}else{a=c+1;d="\u0000"}}}this.next=a;this.ch=d;return this.ch};function x(b){return b>="a"&&b<="z"||b>="A"&&b<="Z"}function z(b){return x(b)||b=="_"||b=="$"||b=="@"}function s(b){return"\t \r\n".indexOf(b)>=0}function w(b){return b>="0"&&b<="9"}function I(b){var c=0,a=b.length-1;while(c<=a&&s(b.charAt(c))){++c}while(a>c&&s(b.charAt(a))){--a}return b.substring(c,a+1)}function y(b,c){return b.length>=c.length&&c==b.substring(0,c.length)}function L(b,c){return b.length>=
-c.length&&c==b.substring(b.length-c.length,b.length)}function A(b,c,a){if(c<a.length){return false}for(var d=0,f=a.length;d<f;++d){if(a.charAt(d)!=b[d]){return false}}return true}function H(b){return b.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\xa0/g,"&nbsp;")}function E(b){return"XMP"==b.tagName}var B=null;function N(b){if(null==B){var c=document.createElement("PRE");c.appendChild(document.createTextNode('<!DOCTYPE foo PUBLIC "foo bar">\n<foo />'));B=!/</.test(c.innerHTML)}if(B){var a=
-b.innerHTML;if(E(b)){a=H(a)}return a}var d=[];for(var f=b.firstChild;f;f=f.nextSibling){D(f,d)}return d.join("")}function D(b,c){switch(b.nodeType){case 1:var a=b.tagName.toLowerCase();c.push("<",a);for(var d=0;d<b.attributes.length;++d){var f=b.attributes[d];if(!f.specified){continue}c.push(" ");D(f,c)}c.push(">");for(var h=b.firstChild;h;h=h.nextSibling){D(h,c)}if(b.firstChild||!/^(?:br|link|img)$/.test(a)){c.push("</",a,">")}break;case 2:c.push(b.name.toLowerCase(),'="',b.value.replace(/&/g,"&amp;").replace(/</g,
-"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/\xa0/,"&nbsp;"),'"');break;case 3:case 4:c.push(H(b.nodeValue));break}}function M(b,c){var a=0,d=new u,f=[];for(var h=0;h<b.length;++h){var i=b[h];if(i.style==null){f.push(i);continue}var e=i.token,g=0,k=[];for(var l=0,j=e.length;l<j;l=d.next){d.decode(e,l);var o=d.ch;switch(o){case "\t":k.push(e.substring(g,l));var m=c-a%c;a+=m;for(;m>=0;m-="                ".length){k.push("                ".substring(0,m))}g=d.next;break;case "\n":case "\r":a=
-0;break;default:++a}}k.push(e.substring(g));f.push(new q(k.join(""),i.style))}return f}function K(b){var c=/(?:[^<]+|<\/?[a-zA-Z][^>]*>|<)/g,a=b.match(c),d=[];if(a){var f=null;for(var h=0,i=a.length;h<i;++h){var e=a[h],g;if(e.length<2||e.charAt(0)!=="<"){if(f&&f.style==="pln"){f.token+=e;continue}g="pln"}else{g=null}f=new q(e,g);d.push(f)}}return d}function G(b,c){var a=[],d=0,f=0,h=0,i=new q("",null);for(var e=0,g=c.length,k=0;e<g;++e){var l=c[e],j=l.end;if(j===k){continue}var o=j-f,m=i.token.length-
-h;while(m<=o){if(m>0){a.push(new q(i.token.substring(h,i.token.length),null==i.style?null:l.style))}f+=m;h=0;if(d<b.length){i=b[d++]}o=j-f;m=i.token.length-h}if(o){a.push(new q(i.token.substring(h,h+o),l.style));f+=o;h+=o}}return a}function R(b){var c=[],a=0,d=0,f=-1,h=new Array(12),i=0,e=null,g=new u;for(var k=0,l=b.length;k<l;++k){var j=b[k];if("pln"!=j.style){d+=j.token.length;continue}var o=j.token;for(var m=0,n=o.length;m<n;){g.decode(o,m);var p=g.ch,v=g.next,t=null;switch(a){case 0:if("<"==
-p){a=1}break;case 1:i=0;if("/"==p){a=7}else if(null==e){if("!"==p){a=2}else if(x(p)){a=8}else if("?"==p){a=9}else if("%"==p){a=11}else if("<"!=p){a=0}}else if("<"!=p){a=0}break;case 2:if("-"==p){a=4}else if(x(p)){a=3}else if("<"==p){a=1}else{a=0}break;case 3:if(">"==p){a=0;t="dec"}break;case 4:if("-"==p){a=5}break;case 5:if("-"==p){a=6}break;case 6:if(">"==p){a=0;t="com"}else if("-"==p){a=6}else{a=4}break;case 7:if(x(p)){a=8}else if("<"==p){a=1}else{a=0}break;case 8:if(">"==p){a=0;t="tag"}break;case 9:if("?"==
-p){a=10}break;case 10:if(">"==p){a=0;t="src"}else if("?"!=p){a=9}break;case 11:if("%"==p){a=12}break;case 12:if(">"==p){a=0;t="src"}else if("%"!=p){a=11}break}if(i<h.length){h[i++]=p.toLowerCase()}if(1==a){f=d+m}m=v;if(t!=null){if(null!=t){if(e){if(A(h,i,e)){e=null}}else{if(A(h,i,"script")){e="/script"}else if(A(h,i,"style")){e="/style"}else if(A(h,i,"xmp")){e="/xmp"}}if(e&&i&&"/"==h[0]){t=null}}if(null!=t){c.push(new r(f,"pln"));c.push(new r(d+v,t))}}}d+=j.token.length}c.push(new r(d,"pln"));return c}
-function V(b){var c=[],a=0,d=-1,f=0;for(var h=0,i=b.length;h<i;++h){var e=b[h],g=e.token;if("pln"==e.style){var k=new u,l=-1,j;for(var o=0,m=g.length;o<m;l=o,o=j){k.decode(g,o);var n=k.ch;j=k.next;if(0==a){if(n=='"'||n=="'"||n=="`"){c.push(new r(f+o,"pln"));a=1;d=n}else if(n=="/"){a=3}else if(n=="#"){c.push(new r(f+o,"pln"));a=4}}else if(1==a){if(n==d){a=0;c.push(new r(f+j,"str"))}else if(n=="\\"){a=2}}else if(2==a){a=1}else if(3==a){if(n=="/"){a=4;c.push(new r(f+l,"pln"))}else if(n=="*"){a=5;c.push(new r(f+
-l,"pln"))}else{a=0;j=o}}else if(4==a){if(n=="\r"||n=="\n"){a=0;c.push(new r(f+o,"com"))}}else if(5==a){if(n=="*"){a=6}}else if(6==a){if(n=="/"){a=0;c.push(new r(f+j,"com"))}else if(n!="*"){a=5}}}}f+=g.length}var p;switch(a){case 1:case 2:p="str";break;case 4:case 5:case 6:p="com";break;default:p="pln";break}c.push(new r(f,p));return G(b,c)}function S(b,c){var a=0,d=0,f=new u,h;for(var i=0;i<=b.length;i=h){if(i==b.length){g=-2;h=i+1}else{f.decode(b,i);h=f.next;var e=f.ch,g=d;switch(d){case 0:if(z(e)){g=
-1}else if(w(e)){g=2}else if(!s(e)){g=3}if(g&&a<i){var k=b.substring(a,i);c.push(new q(k,"pln"));a=i}break;case 1:if(!(z(e)||w(e))){g=-1}break;case 2:if(!(w(e)||x(e)||e=="_")){g=-1}break;case 3:if(z(e)||w(e)||s(e)){g=-1}break}}if(g!=d){if(g<0){if(i>a){var k=b.substring(a,i),l=new u;l.decode(k,0);var j=l.ch,o=l.next==k.length,m;if(z(j)){if(F[k]){m="kwd"}else if(j==="@"){m="lit"}else{var n=false;if(j>="A"&&j<="Z"){for(var p=l.next;p<k.length;p=l.next){l.decode(k,p);var v=l.ch;if(v>="a"&&v<="z"){n=true;
-break}}if(!n&&!o&&k.substring(k.length-2)=="_t"){n=true}}m=n?"typ":"pln"}}else if(w(j)){m="lit"}else if(!s(j)){m="pun"}else{m="pln"}a=i;c.push(new q(k,m))}d=0;if(g==-1){h=i;continue}}d=g}}}function X(b){if(!(b&&b.length)){return b}var c=R(b);return G(b,c)}function W(b){var c=[],a=0,d="tag",f=null,h=new u;for(var i=0;i<b.length;++i){var e=b[i];if("tag"==e.style){var g=e.token,k=0;for(var l=0;l<g.length;){h.decode(g,l);var j=h.ch,o=h.next,m=null,n=null;if(j==">"){if("tag"!=d){m=l;n="tag"}}else{switch(a){case 0:if("<"==
-j){a=1}break;case 1:if(s(j)){a=2}break;case 2:if(!s(j)){n="atn";m=l;a=3}break;case 3:if("="==j){m=l;n="tag";a=5}else if(s(j)){m=l;n="tag";a=4}break;case 4:if("="==j){a=5}else if(!s(j)){m=l;n="atn";a=3}break;case 5:if('"'==j||"'"==j){m=l;n="atv";a=6;f=j}else if(!s(j)){m=l;n="atv";a=7}break;case 6:if(j==f){m=o;n="tag";a=2}break;case 7:if(s(j)){m=l;n="tag";a=2}break}}if(m){if(m>k){c.push(new q(g.substring(k,m),d));k=m}d=n}l=o}if(g.length>k){c.push(new q(g.substring(k,g.length),d))}}else{if(e.style){a=
-0;d="tag"}c.push(e)}}return c}function U(b){var c=[],a=null,d=new u,f=null;for(var h=0,i=b.length;;++h){var e;if(h<i){e=b[h];if(null==e.style){b.push(e);continue}}else if(!a){break}else{e=new q("",null)}var g=e.token;if(null==a){if("src"==e.style){if("<"==d.decode(g,0)){d.decode(g,d.next);if("%"==d.ch||"?"==d.ch){a=d.ch;c.push(new q(g.substring(0,d.next),"tag"));g=g.substring(d.next,g.length)}}}else if("tag"==e.style){if("<"==d.decode(g,0)&&"/"!=g.charAt(d.next)){var k=g.substring(d.next).toLowerCase();
-if(y(k,"script")||y(k,"style")||y(k,"xmp")){a="/"}}}}if(null!=a){var l=null;if("src"==e.style){if(a=="%"||a=="?"){var j=g.lastIndexOf(a);if(j>=0&&">"==d.decode(g,j+1)&&g.length==d.next){l=new q(g.substring(j,g.length),"tag");g=g.substring(0,j)}}if(null==f){f=[]}f.push(new q(g,"pln"))}else if("pln"==e.style){if(null==f){f=[]}f.push(e)}else if("tag"==e.style){if("<"==d.decode(e.token,0)&&e.token.length>d.next&&"/"==d.decode(e.token,d.next)){l=e}else{c.push(e)}}else if(h>=i){l=e}else{if(f){f.push(e)}else{c.push(e)}}if(l){if(f){var o=
-C(f);c.push(new q("<span class=embsrc>",null));for(var m=0,n=o.length;m<n;++m){c.push(o[m])}c.push(new q("</span>",null));f=null}if(l.token){c.push(l)}a=null}}else{c.push(e)}}return c}function Q(b){var c=null,a=null;for(var d=0;d<b.length;++d){if("pln"==b[d].style){c=d;break}}for(var d=b.length;--d>=0;){if("pln"==b[d].style){a=d;break}}if(null==c){return b}var f=new u,h=b[c].token,i=f.decode(h,0);if('"'!=i&&"'"!=i){return b}var e=f.next,g=b[a].token,k=g.lastIndexOf("&");if(k<0){k=g.length-1}var l=
-f.decode(g,k);if(l!=i||f.next!=g.length){l=null;k=g.length}var j=[];for(var d=0;d<c;++d){j.push(b[d])}j.push(new q(h.substring(0,e),"atv"));if(a==c){j.push(new q(h.substring(e,k),"pln"))}else{j.push(new q(h.substring(e,h.length),"pln"));for(var d=c+1;d<a;++d){j.push(b[d])}if(l){b.push(new q(g.substring(0,k),"pln"))}else{b.push(b[a])}}if(l){j.push(new q(g.substring(k,g.length),"pln"))}for(var d=a+1;d<b.length;++d){j.push(b[d])}return j}function T(b){var c=[],a=null,d=false,f="";for(var h=0,i=b.length;h<
-i;++h){var e=b[h],g=c;if("tag"==e.style){if(d){d=false;f="";if(a){c.push(new q("<span class=embsrc>",null));var k=C(Q(a));for(var l=0,j=k.length;l<j;++l){c.push(k[l])}c.push(new q("</span>",null));a=null}}else if(f&&e.token.indexOf("=")>=0){var o=f.toLowerCase();if(y(o,"on")||"style"==o){d=true}}else{f=""}}else if("atn"==e.style){f+=e.token}else if("atv"==e.style){if(d){if(null==a){a=[]}g=a;e=new q(e.token,"pln")}}else{if(a){g=a}}g.push(e)}return c}function C(b){var c=V(b),a=[];for(var d=0;d<c.length;++d){var f=
-c[d];if("pln"===f.style){S(f.token,a);continue}a.push(f)}return a}function O(b){var c=X(b);c=W(c);c=U(c);c=T(c);return c}function P(b){var c=M(K(b),8),a=false;for(var d=0;d<c.length;++d){if("pln"==c[d].style){if(y(I(c[d].token),"&lt;")){for(var f=c.length;--f>=0;){if("pln"==c[f].style){a=L(I(c[f].token),"&gt;");break}}}break}}return a?O(c):C(c)}function Z(b){try{var c=P(b),a=[],d=null;for(var f=0;f<c.length;f++){var h=c[f];if(h.style!=d){if(d!=null){a.push("</span>")}if(h.style!=null){a.push("<span class=",
-h.style,">")}d=h.style}var i=h.token;if(null!=h.style){i=i.replace(/(\r\n?|\n| ) /g,"$1&nbsp;").replace(/\r\n?|\n/g,"<br>")}a.push(i)}if(d!=null){a.push("</span>")}return a.join("")}catch(e){if("console"in window){console.log(e);console.trace()}return b}}function Y(){var b=[document.getElementsByTagName("pre"),document.getElementsByTagName("code"),document.getElementsByTagName("xmp")],c=[];for(var a=0;a<b.length;++a){for(var d=0;d<b[a].length;++d){c.push(b[a][d])}}b=null;var f=0;function h(){var i=
-(new Date).getTime()+250;for(;f<c.length&&(new Date).getTime()<i;f++){var e=c[f];if(e.className&&e.className.indexOf("prettyprint")>=0){var g=false;for(var k=e.parentNode;k!=null;k=k.parentNode){if((k.tagName=="pre"||k.tagName=="code"||k.tagName=="xmp")&&k.className&&k.className.indexOf("prettyprint")>=0){g=true;break}}if(!g){var l=N(e);l=l.replace(/(?:\r\n?|\n)$/,"");var j=Z(l);if(!E(e)){e.innerHTML=j}else{var o=document.createElement("PRE");for(var m=0;m<e.attributes.length;++m){var n=e.attributes[m];
-if(n.specified){o.setAttribute(n.name,n.value)}}o.innerHTML=j;e.parentNode.replaceChild(o,e)}}}}if(f<c.length){setTimeout(h,250)}}h()};this.prettyPrint=Y;
-; })();
+// Copyright (C) 2006 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+
+/**
+ * @fileoverview
+ * some functions for browser-side pretty printing of code contained in html.
+ *
+ * The lexer should work on a number of languages including C and friends,
+ * Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles.
+ * It works passably on Ruby, PHP and Awk and a decent subset of Perl, but,
+ * because of commenting conventions, doesn't work on Smalltalk, Lisp-like, or
+ * CAML-like languages.
+ *
+ * If there's a language not mentioned here, then I don't know it, and don't
+ * know whether it works.  If it has a C-like, Bash-like, or XML-like syntax
+ * then it should work passably.
+ *
+ * Usage:
+ * 1) include this source file in an html page via
+ * <script type="text/javascript" src="/path/to/prettify.js"></script>
+ * 2) define style rules.  See the example page for examples.
+ * 3) mark the <pre> and <code> tags in your source with class=prettyprint.
+ *    You can also use the (html deprecated) <xmp> tag, but the pretty printer
+ *    needs to do more substantial DOM manipulations to support that, so some
+ *    css styles may not be preserved.
+ * That's it.  I wanted to keep the API as simple as possible, so there's no
+ * need to specify which language the code is in.
+ *
+ * Change log:
+ * cbeust, 2006/08/22
+ *   Java annotations (start with "@") are now captured as literals ("lit")
+ */
+
+var PR_keywords = {};
+/** initialize the keyword list for our target languages. */
+(function () {
+  var CPP_KEYWORDS = "abstract bool break case catch char class const " +
+    "const_cast continue default delete deprecated dllexport dllimport do " +
+    "double dynamic_cast else enum explicit extern false float for friend " +
+    "goto if inline int long mutable naked namespace new noinline noreturn " +
+    "nothrow novtable operator private property protected public register " +
+    "reinterpret_cast return selectany short signed sizeof static " +
+    "static_cast struct switch template this thread throw true try typedef " +
+    "typeid typename union unsigned using declaration, directive uuid " +
+    "virtual void volatile while typeof";
+  var CSHARP_KEYWORDS = "as base by byte checked decimal delegate descending " +
+    "event finally fixed foreach from group implicit in interface internal " +
+    "into is lock null object out override orderby params readonly ref sbyte " +
+    "sealed stackalloc string select uint ulong unchecked unsafe ushort var";
+  var JAVA_KEYWORDS = "package synchronized boolean implements import throws " +
+    "instanceof transient extends final strictfp native super";
+  var JSCRIPT_KEYWORDS = "debugger export function with NaN Infinity";
+  var PERL_KEYWORDS = "require sub unless until use elsif BEGIN END";
+  var PYTHON_KEYWORDS = "and assert def del elif except exec global lambda " +
+    "not or pass print raise yield False True None";
+  var RUBY_KEYWORDS = "then end begin rescue ensure module when undef next " +
+    "redo retry alias defined";
+  var SH_KEYWORDS = "done fi";
+
+  var KEYWORDS = [CPP_KEYWORDS, CSHARP_KEYWORDS, JAVA_KEYWORDS,
+                  JSCRIPT_KEYWORDS, PERL_KEYWORDS, PYTHON_KEYWORDS,
+                  RUBY_KEYWORDS, SH_KEYWORDS];
+  for (var k = 0; k < KEYWORDS.length; k++) {
+    var kw = KEYWORDS[k].split(' ');
+    for (var i = 0; i < kw.length; i++) {
+      if (kw[i]) { PR_keywords[kw[i]] = true; }
+    }
+  }
+}).call(this);
+
+// token style names.  correspond to css classes
+/** token style for a string literal */
+var PR_STRING = 'str';
+/** token style for a keyword */
+var PR_KEYWORD = 'kwd';
+/** token style for a comment */
+var PR_COMMENT = 'com';
+/** token style for a type */
+var PR_TYPE = 'typ';
+/** token style for a literal value.  e.g. 1, null, true. */
+var PR_LITERAL = 'lit';
+/** token style for a punctuation string. */
+var PR_PUNCTUATION = 'pun';
+/** token style for a punctuation string. */
+var PR_PLAIN = 'pln';
+
+/** token style for an sgml tag. */
+var PR_TAG = 'tag';
+/** token style for a markup declaration such as a DOCTYPE. */
+var PR_DECLARATION = 'dec';
+/** token style for embedded source. */
+var PR_SOURCE = 'src';
+/** token style for an sgml attribute name. */
+var PR_ATTRIB_NAME = 'atn';
+/** token style for an sgml attribute value. */
+var PR_ATTRIB_VALUE = 'atv';
+
+/** the number of characters between tab columns */
+var PR_TAB_WIDTH = 8;
+
+/** the position of the end of a token during.  A division of a string into
+  * n tokens can be represented as a series n - 1 token ends, as long as
+  * runs of whitespace warrant their own token.
+  * @private
+  */
+function PR_TokenEnd(end, style) {
+  if (undefined === style) { throw new Error('BAD'); }
+  if ('number' != typeof(end)) { throw new Error('BAD'); }
+  this.end = end;
+  this.style = style;
+}
+PR_TokenEnd.prototype.toString = function () {
+  return '[PR_TokenEnd ' + this.end +
+    (this.style ? ':' + this.style : '') + ']';
+};
+
+
+/** a chunk of text with a style.  These are used to represent both the output
+  * from the lexing functions as well as intermediate results.
+  * @constructor
+  * @param token the token text
+  * @param style one of the token styles defined in designdoc-template, or null
+  *   for a styleless token, such as an embedded html tag.
+  * @private
+  */
+function PR_Token(token, style) {
+  if (undefined === style) { throw new Error('BAD'); }
+  this.token = token;
+  this.style = style;
+}
+
+PR_Token.prototype.toString = function () {
+  return '[PR_Token ' + this.token + (this.style ? ':' + this.style : '') + ']';
+};
+
+
+/** a helper class that decodes common html entities used to escape special
+  * characters in source code.
+  * @constructor
+  * @private
+  */
+function PR_DecodeHelper() {
+  this.next = 0;
+  this.ch = '\0';
+}
+
+var PR_NAMED_ENTITIES = {
+  'lt':   '<',
+  'gt':   '>',
+  'quot': '"',
+  'apos': "'",
+  'amp':  '&'   // reencoding requires that & always be decoded properly
+};
+
+PR_DecodeHelper.prototype.decode = function (s, i) {
+  var next = i + 1;
+  var ch = s.charAt(i);
+  if ('&' === ch) {
+    var semi = s.indexOf(';', next);
+    if (semi >= 0 && semi < next + 4) {
+      var entityName = s.substring(next, semi);
+      var decoded = null;
+      if (entityName.charAt(0) === '#') {  // check for numeric entity
+        var ch1 = entityName.charAt(1);
+        var charCode;
+        if (ch1 === 'x' || ch1 === 'X') {  // like &#xA0;
+          charCode = parseInt(entityName.substring(2), 16);
+        } else {  // like &#160;
+          charCode = parseInt(entityName.substring(1), 10);
+        }
+        if (!isNaN(charCode)) {
+          decoded = String.fromCharCode(charCode);
+        }
+      }
+      if (!decoded) {
+        decoded = PR_NAMED_ENTITIES[entityName.toLowerCase()];
+      }
+      if (decoded) {
+        ch = decoded;
+        next = semi + 1;
+      } else {  // skip over unrecognized entity
+        next = i + 1;
+        ch = '\0';
+      }
+    }
+  }
+  this.next = next;
+  this.ch = ch;
+  return this.ch;
+};
+
+
+// some string utilities
+function PR_isWordChar(ch) {
+  return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
+}
+
+function PR_isIdentifierStart(ch) {
+  return PR_isWordChar(ch) || ch == '_' || ch == '$' || ch == '@';
+}
+
+function PR_isIdentifierPart(ch) {
+  return PR_isIdentifierStart(ch) || PR_isDigitChar(ch);
+}
+
+function PR_isSpaceChar(ch) {
+  return "\t \r\n".indexOf(ch) >= 0;
+}
+
+function PR_isDigitChar(ch) {
+  return ch >= '0' && ch <= '9';
+}
+
+function PR_trim(s) {
+  var i = 0, j = s.length - 1;
+  while (i <= j && PR_isSpaceChar(s.charAt(i))) { ++i; }
+  while (j > i && PR_isSpaceChar(s.charAt(j))) { --j; }
+  return s.substring(i, j + 1);
+}
+
+function PR_startsWith(s, prefix) {
+  return s.length >= prefix.length && prefix == s.substring(0, prefix.length);
+}
+
+function PR_endsWith(s, suffix) {
+  return s.length >= suffix.length &&
+         suffix == s.substring(s.length - suffix.length, s.length);
+}
+
+/** true iff prefix matches the first prefix characters in chars[0:len].
+  * @private
+  */
+function PR_prefixMatch(chars, len, prefix) {
+  if (len < prefix.length) { return false; }
+  for (var i = 0, n = prefix.length; i < n; ++i) {
+    if (prefix.charAt(i) != chars[i]) { return false; }
+  }
+  return true;
+}
+
+/** like textToHtml but escapes double quotes to be attribute safe. */
+function PR_attribToHtml(str) {
+  return str.replace(/&/g, '&amp;')
+    .replace(/</g, '&lt;')
+    .replace(/>/g, '&gt;')
+    .replace(/\"/g, '&quot;')
+    .replace(/\xa0/, '&nbsp;');
+}
+
+/** escapest html special characters to html. */
+function PR_textToHtml(str) {
+  return str.replace(/&/g, '&amp;')
+    .replace(/</g, '&lt;')
+    .replace(/>/g, '&gt;')
+    .replace(/\xa0/g, '&nbsp;');
+}
+
+/** is the given node's innerHTML normally unescaped? */
+function PR_isRawContent(node) {
+  return 'XMP' == node.tagName;
+}
+
+var PR_innerHtmlWorks = null;
+function PR_getInnerHtml(node) {
+  // inner html is hopelessly broken in Safari 2.0.4 when the content is
+  // an html description of well formed XML and the containing tag is a PRE
+   // tag, so we detect that case and emulate innerHTML.
+  if (null == PR_innerHtmlWorks) {
+    var testNode = document.createElement('PRE');
+    testNode.appendChild(
+        document.createTextNode('<!DOCTYPE foo PUBLIC "foo bar">\n<foo />'));
+    PR_innerHtmlWorks = !/</.test(testNode.innerHTML);
+  }
+
+  if (PR_innerHtmlWorks) {
+    var content = node.innerHTML;
+    // XMP tags contain unescaped entities so require special handling.
+    if (PR_isRawContent(node)) {
+       content = PR_textToHtml(content);
+    }
+    return content;
+  }
+
+  var out = [];
+  for (var child = node.firstChild; child; child = child.nextSibling) {
+    PR_normalizedHtml(child, out);
+  }
+  return out.join('');
+}
+
+/**
+ * walks the DOM returning a properly escaped version of innerHTML.
+ */
+function PR_normalizedHtml(node, out) {
+  switch (node.nodeType) {
+    case 1:  // an element
+      var name = node.tagName.toLowerCase();
+      out.push('\074', name);
+      for (var i = 0; i < node.attributes.length; ++i) {
+        var attr = node.attributes[i];
+        if (!attr.specified) { continue; }
+        out.push(' ');
+        PR_normalizedHtml(attr, out);
+      }
+      out.push('>');
+      for (var child = node.firstChild; child; child = child.nextSibling) {
+        PR_normalizedHtml(child, out);
+      }
+      if (node.firstChild || !/^(?:br|link|img)$/.test(name)) {
+        out.push('<\/', name, '>');
+      }
+      break;
+    case 2: // an attribute
+      out.push(node.name.toLowerCase(), '="', PR_attribToHtml(node.value), '"');
+      break;
+    case 3: case 4: // text
+      out.push(PR_textToHtml(node.nodeValue));
+      break;
+  }
+}
+
+/** expand tabs to spaces
+  * @param {Array} chunks PR_Tokens possibly containing tabs
+  * @param {Number} tabWidth number of spaces between tab columns
+  * @return {Array} chunks with tabs replaced with spaces
+  */
+function PR_expandTabs(chunks, tabWidth) {
+  var SPACES = '                ';
+
+  var charInLine = 0;
+  var decodeHelper = new PR_DecodeHelper();
+
+  var chunksOut = []
+  for (var chunkIndex = 0; chunkIndex < chunks.length; ++chunkIndex) {
+    var chunk = chunks[chunkIndex];
+    if (chunk.style == null) {
+      chunksOut.push(chunk);
+      continue;
+    }
+
+    var s = chunk.token;
+    var pos = 0;  // index of last character output
+    var out = [];
+
+    // walk over each character looking for tabs and newlines.
+    // On tabs, expand them.  On newlines, reset charInLine.
+    // Otherwise increment charInLine
+    for (var charIndex = 0, n = s.length; charIndex < n;
+         charIndex = decodeHelper.next) {
+      decodeHelper.decode(s, charIndex);
+      var ch = decodeHelper.ch;
+
+      switch (ch) {
+        case '\t':
+          out.push(s.substring(pos, charIndex));
+          // calculate how much space we need in front of this part
+          // nSpaces is the amount of padding -- the number of spaces needed to
+          // move us to the next column, where columns occur at factors of
+          // tabWidth.
+          var nSpaces = tabWidth - (charInLine % tabWidth);
+          charInLine += nSpaces;
+          for (; nSpaces >= 0; nSpaces -= SPACES.length) {
+            out.push(SPACES.substring(0, nSpaces));
+          }
+          pos = decodeHelper.next;
+          break;
+        case '\n': case '\r':
+          charInLine = 0;
+          break;
+        default:
+          ++charInLine;
+      }
+    }
+    out.push(s.substring(pos));
+    chunksOut.push(new PR_Token(out.join(''), chunk.style));
+  }
+  return chunksOut
+}
+
+/** split markup into chunks of html tags (style null) and
+  * plain text (style {@link #PR_PLAIN}).
+  *
+  * @param {String} s html.
+  * @return {Array} of PR_Tokens of style PR_PLAIN, and null.
+  * @private
+  */
+function PR_chunkify(s) {
+  // The below pattern matches one of the following
+  // (1) /[^<]+/ : A run of characters other than '<'
+  // (2) /<\/?[a-zA-Z][^>]*>/ : A probably tag that should not be highlighted
+  // (3) /</ : A '<' that does not begin a larger chunk.  Treated as 1
+  var chunkPattern = /(?:[^<]+|<\/?[a-zA-Z][^>]*>|<)/g;
+  // since the pattern has the 'g' modifier and defines no capturing groups,
+  // this will return a list of all chunks which we then classify and wrap as
+  // PR_Tokens
+  var matches = s.match(chunkPattern);
+  var chunks = [];
+  if (matches) {
+    var lastChunk = null;
+    for (var i = 0, n = matches.length; i < n; ++i) {
+      var chunkText = matches[i];
+      var style;
+      if (chunkText.length < 2 || chunkText.charAt(0) !== '<') {
+        if (lastChunk && lastChunk.style === PR_PLAIN) {
+          lastChunk.token += chunkText;
+          continue;
+        }
+        style = PR_PLAIN;
+      } else {  // a tag
+        style = null;
+      }
+      lastChunk = new PR_Token(chunkText, style);
+      chunks.push(lastChunk);
+    }
+  }
+  return chunks;
+}
+
+/** walk the tokenEnds list and the chunk list in parallel to generate a list
+  * of split tokens.
+  * @private
+  */
+function PR_splitChunks(chunks, tokenEnds) {
+  var tokens = [];  // the output
+
+  var ci = 0;  // index into chunks
+  // position of beginning of amount written so far in absolute space.
+  var posAbs = 0;
+  // position of amount written so far in chunk space
+  var posChunk = 0;
+
+  // current chunk
+  var chunk = new PR_Token('', null);
+
+  for (var ei = 0, ne = tokenEnds.length, lastEnd = 0; ei < ne; ++ei) {
+    var tokenEnd = tokenEnds[ei];
+    var end = tokenEnd.end;
+    if (end === lastEnd) { continue; }  // skip empty regions
+
+    var tokLen = end - posAbs;
+    var remainingInChunk = chunk.token.length - posChunk;
+    while (remainingInChunk <= tokLen) {
+      if (remainingInChunk > 0) {
+        tokens.push(
+            new PR_Token(chunk.token.substring(posChunk, chunk.token.length),
+                         null == chunk.style ? null : tokenEnd.style));
+      }
+      posAbs += remainingInChunk;
+      posChunk = 0;
+      if (ci < chunks.length) {
+        chunk = chunks[ci++];
+      }
+
+      tokLen = end - posAbs;
+      remainingInChunk = chunk.token.length - posChunk;
+    }
+
+    if (tokLen) {
+      tokens.push(
+          new PR_Token(chunk.token.substring(posChunk, posChunk + tokLen),
+                       tokenEnd.style));
+      posAbs += tokLen;
+      posChunk += tokLen;
+    }
+  }
+
+  return tokens;
+}
+
+/** splits markup tokens into declarations, tags, and source chunks.
+  * @private
+  */
+function PR_splitMarkup(chunks) {
+  // A state machine to split out declarations, tags, etc.
+  // This state machine deals with absolute space in the text, indexed by k,
+  // and position in the current chunk, indexed by pos and tokenStart to
+  // generate a list of the ends of tokens.
+  // Absolute space is calculated by considering the chunks as appended into
+  // one big string, as they were before being split.
+
+  // Known failure cases
+  // Server side scripting sections such as <?...?> in attributes.
+  // i.e. <span class="<? foo ?>">
+  // Handling this would require a stack, and we don't use PHP.
+
+  // The output: a list of pairs of PR_TokenEnd instances
+  var tokenEnds = [];
+
+  var state = 0;  // FSM state variable
+  var k = 0;  // position in absolute space of the start of the current chunk
+  var tokenStart = -1;  // the start of the current token
+
+  // Try to find a closing tag for any open <style> or <script> tags
+  // We can't do this at a later stage because then the following case
+  // would fail:
+  // <script>document.writeln('<!--');</script>
+
+  // We use tokenChars[:tokenCharsI] to accumulate the tag name so that we
+  // can check whether to enter into a no scripting section when the tag ends.
+  var tokenChars = new Array(12);
+  var tokenCharsI = 0;
+  // if non null, the tag prefix that we need to see to break out.
+  var endScriptTag = null;
+  var decodeHelper = new PR_DecodeHelper();
+
+  for (var ci = 0, nc = chunks.length; ci < nc; ++ci) {
+    var chunk = chunks[ci];
+    if (PR_PLAIN != chunk.style) {
+      k += chunk.token.length;
+      continue;
+    }
+
+    var s = chunk.token;
+    var pos = 0;  // the position past the last character processed so far in s
+
+    for (var i = 0, n = s.length; i < n; /* i = next at bottom */) {
+      decodeHelper.decode(s, i);
+      var ch = decodeHelper.ch;
+      var next = decodeHelper.next;
+
+      var tokenStyle = null;
+      switch (state) {
+        case 0:
+          if ('<' == ch) { state = 1; }
+          break;
+        case 1:
+          tokenCharsI = 0;
+          if ('/' == ch) {  // only consider close tags if we're in script/style
+            state = 7;
+          } else if (null == endScriptTag) {
+            if ('!' == ch) {
+              state = 2;
+            } else if (PR_isWordChar(ch)) {
+              state = 8;
+            } else if ('?' == ch) {
+              state = 9;
+            } else if ('%' == ch) {
+              state = 11;
+            } else if ('<' != ch) {
+              state = 0;
+            }
+          } else if ('<' != ch) {
+            state = 0;
+          }
+          break;
+        case 2:
+          if ('-' == ch) {
+            state = 4;
+          } else if (PR_isWordChar(ch)) {
+            state = 3;
+          } else if ('<' == ch) {
+            state = 1;
+          } else {
+            state = 0;
+          }
+          break;
+        case 3:
+          if ('>' == ch) {
+            state = 0;
+            tokenStyle = PR_DECLARATION;
+          }
+          break;
+        case 4:
+          if ('-' == ch) { state = 5; }
+          break;
+        case 5:
+          if ('-' == ch) { state = 6; }
+          break;
+        case 6:
+          if ('>' == ch) {
+            state = 0;
+            tokenStyle = PR_COMMENT;
+          } else if ('-' == ch) {
+            state = 6;
+          } else {
+            state = 4;
+          }
+          break;
+        case 7:
+          if (PR_isWordChar(ch)) {
+            state = 8;
+          } else if ('<' == ch) {
+            state = 1;
+          } else {
+            state = 0;
+          }
+          break;
+        case 8:
+          if ('>' == ch) {
+            state = 0;
+            tokenStyle = PR_TAG;
+          }
+          break;
+        case 9:
+          if ('?' == ch) { state = 10; }
+          break;
+        case 10:
+          if ('>' == ch) {
+            state = 0;
+            tokenStyle = PR_SOURCE;
+          } else if ('?' != ch) {
+            state = 9;
+          }
+          break;
+        case 11:
+          if ('%' == ch) { state = 12; }
+          break;
+        case 12:
+          if ('>' == ch) {
+            state = 0;
+            tokenStyle = PR_SOURCE;
+          } else if ('%' != ch) {
+            state = 11;
+          }
+          break;
+      }
+
+      if (tokenCharsI < tokenChars.length) {
+        tokenChars[tokenCharsI++] = ch.toLowerCase();
+      }
+      if (1 == state) { tokenStart = k + i; }
+      i = next;
+      if (tokenStyle != null) {
+        if (null != tokenStyle) {
+          if (endScriptTag) {
+            if (PR_prefixMatch(tokenChars, tokenCharsI, endScriptTag)) {
+              endScriptTag = null;
+            }
+          } else {
+            if (PR_prefixMatch(tokenChars, tokenCharsI, 'script')) {
+              endScriptTag = '/script';
+            } else if (PR_prefixMatch(tokenChars, tokenCharsI, 'style')) {
+              endScriptTag = '/style';
+            } else if (PR_prefixMatch(tokenChars, tokenCharsI, 'xmp')) {
+              endScriptTag = '/xmp';
+            }
+          }
+          // disallow the tag if endScriptTag is set and this was not an open
+          // tag.
+          if (endScriptTag && tokenCharsI && '/' == tokenChars[0]) {
+            tokenStyle = null;
+          }
+        }
+        if (null != tokenStyle) {
+          tokenEnds.push(new PR_TokenEnd(tokenStart, PR_PLAIN));
+          tokenEnds.push(new PR_TokenEnd(k + next, tokenStyle));
+        }
+      }
+    }
+    k += chunk.token.length;
+  }
+  tokenEnds.push(new PR_TokenEnd(k, PR_PLAIN));
+
+  return tokenEnds;
+}
+
+/** splits the given string into comment, string, and "other" tokens.
+  * @return {Array} of PR_Tokens with style in
+  *   (PR_STRING, PR_COMMENT, PR_PLAIN, null)
+  *   The result array may contain spurious zero length tokens.  Ignore them.
+  *
+  * @private
+  */
+function PR_splitStringAndCommentTokens(chunks) {
+  // a state machine to split out comments, strings, and other stuff
+  var tokenEnds = [];  // positions of ends of tokens in absolute space
+  var state = 0;  // FSM state variable
+  var delim = -1;  // string delimiter
+  var k = 0;  // absolute position of beginning of current chunk
+
+  for (var ci = 0, nc = chunks.length; ci < nc; ++ci) {
+    var chunk = chunks[ci];
+    var s = chunk.token;
+    if (PR_PLAIN == chunk.style) {
+      var decodeHelper = new PR_DecodeHelper();
+      var last = -1;
+      var next;
+      for (var i = 0, n = s.length; i < n; last = i, i = next) {
+        decodeHelper.decode(s, i);
+        var ch = decodeHelper.ch;
+        next = decodeHelper.next;
+        if (0 == state) {
+          if (ch == '"' || ch == '\'' || ch == '`') {
+            tokenEnds.push(new PR_TokenEnd(k + i, PR_PLAIN));
+            state = 1;
+            delim = ch;
+          } else if (ch == '/') {
+            state = 3;
+          } else if (ch == '#') {
+            tokenEnds.push(new PR_TokenEnd(k + i, PR_PLAIN));
+            state = 4;
+          }
+        } else if (1 == state) {
+          if (ch == delim) {
+            state = 0;
+            tokenEnds.push(new PR_TokenEnd(k + next, PR_STRING));
+          } else if (ch == '\\') {
+            state = 2;
+          }
+        } else if (2 == state) {
+          state = 1;
+        } else if (3 == state) {
+          if (ch == '/') {
+            state = 4;
+            tokenEnds.push(new PR_TokenEnd(k + last, PR_PLAIN));
+          } else if (ch == '*') {
+            state = 5;
+            tokenEnds.push(new PR_TokenEnd(k + last, PR_PLAIN));
+          } else {
+            state = 0;
+            // next loop will reenter state 0 without same value of i, so
+            // ch will be reconsidered as start of new token.
+            next = i;
+          }
+        } else if (4 == state) {
+          if (ch == '\r' || ch == '\n') {
+            state = 0;
+            tokenEnds.push(new PR_TokenEnd(k + i, PR_COMMENT));
+          }
+        } else if (5 == state) {
+          if (ch == '*') {
+            state = 6;
+          }
+        } else if (6 == state) {
+          if (ch == '/') {
+            state = 0;
+            tokenEnds.push(new PR_TokenEnd(k + next, PR_COMMENT));
+          } else if (ch != '*') {
+            state = 5;
+          }
+        }
+      }
+    }
+    k += s.length;
+  }
+  var endTokenType;
+  switch (state) {
+    case 1: case 2:
+      endTokenType = PR_STRING;
+      break;
+    case 4: case 5: case 6:
+      endTokenType = PR_COMMENT;
+      break;
+    default:
+      endTokenType = PR_PLAIN;
+      break;
+  }
+  // handle unclosed token which can legally happen for line comments (state 4)
+  tokenEnds.push(new PR_TokenEnd(k, endTokenType));  // a token ends at the end
+
+  return PR_splitChunks(chunks, tokenEnds);
+}
+
+/** used by lexSource to split a non string, non comment token.
+  * @private
+  */
+function PR_splitNonStringNonCommentToken(s, outlist) {
+  var pos = 0;
+  var state = 0;
+
+  var decodeHelper = new PR_DecodeHelper();
+  var next;
+  for (var i = 0; i <= s.length; i = next) {
+    if (i == s.length) {
+      // nstate will not be equal to state, so it will append the token
+      nstate = -2;
+      next = i + 1;
+    } else {
+      decodeHelper.decode(s, i);
+      next = decodeHelper.next;
+      var ch = decodeHelper.ch;
+
+      // the next state.
+      // if set to -1 then it will cause a reentry to state 0 without consuming
+      // another character.
+      var nstate = state;
+
+      switch (state) {
+      case 0:  // whitespace state
+        if (PR_isIdentifierStart(ch)) {
+          nstate = 1;
+        } else if (PR_isDigitChar(ch)) {
+          nstate = 2;
+        } else if (!PR_isSpaceChar(ch)) {
+          nstate = 3;
+        }
+        if (nstate && pos < i) {
+          var t = s.substring(pos, i);
+          outlist.push(new PR_Token(t, PR_PLAIN));
+          pos = i;
+        }
+        break;
+      case 1:  // identifier state
+        if (!PR_isIdentifierPart(ch)) {
+          nstate = -1;
+        }
+        break;
+      case 2:  // number literal state
+        // handle numeric literals like
+        // 0x7f 300UL 100_000
+
+        // this does not treat floating point values as a single literal
+        //   0.1 and 3e-6
+        // are each split into multiple tokens
+        if (!(PR_isDigitChar(ch) || PR_isWordChar(ch) || ch == '_')) {
+          nstate = -1;
+        }
+        break;
+      case 3:  // punctuation state
+        if (PR_isIdentifierStart(ch) || PR_isDigitChar(ch) ||
+            PR_isSpaceChar(ch)) {
+          nstate = -1;
+        }
+        break;
+      }
+    }
+
+    if (nstate != state) {
+      if (nstate < 0) {
+        if (i > pos) {
+          var t = s.substring(pos, i);
+          var wordDecodeHelper = new PR_DecodeHelper();
+          wordDecodeHelper.decode(t, 0);
+          var ch0 = wordDecodeHelper.ch;
+          var isSingleCharacter = wordDecodeHelper.next == t.length;
+          var style;
+          if (PR_isIdentifierStart(ch0)) {
+            if (PR_keywords[t]) {
+              style = PR_KEYWORD;
+            } else if (ch0 === '@') {
+              style = PR_LITERAL;
+            } else {
+              // Treat any word that starts with an uppercase character and
+              // contains at least one lowercase character as a type, or
+              // ends with _t.
+              // This works perfectly for Java, pretty well for C++, and
+              // passably for Python.  The _t catches C structs.
+              var isType = false;
+              if (ch0 >= 'A' && ch0 <= 'Z') {
+                for (var j = wordDecodeHelper.next;
+                     j < t.length; j = wordDecodeHelper.next) {
+                  wordDecodeHelper.decode(t, j);
+                  var ch1 = wordDecodeHelper.ch;
+                  if (ch1 >= 'a' && ch1 <= 'z') {
+                    isType = true;
+                    break;
+                  }
+                }
+                if (!isType && !isSingleCharacter &&
+                    t.substring(t.length - 2) == '_t') {
+                  isType = true;
+                }
+              }
+              style = isType ? PR_TYPE : PR_PLAIN;
+            }
+          } else if (PR_isDigitChar(ch0)) {
+            style = PR_LITERAL;
+          } else if (!PR_isSpaceChar(ch0)) {
+            style = PR_PUNCTUATION;
+          } else {
+            style = PR_PLAIN;
+          }
+          pos = i;
+          outlist.push(new PR_Token(t, style));
+        }
+
+        state = 0;
+        if (nstate == -1) {
+          // don't increment.  This allows us to use state 0 to redispatch based
+          // on the current character.
+          next = i;
+          continue;
+        }
+      }
+      state = nstate;
+    }
+  }
+
+}
+
+/** split a group of chunks of markup.
+  * @private
+  */
+function PR_tokenizeMarkup(chunks) {
+  if (!(chunks && chunks.length)) { return chunks; }
+
+  var tokenEnds = PR_splitMarkup(chunks);
+  return PR_splitChunks(chunks, tokenEnds);
+}
+
+/** split tags attributes and their values out from the tag name, and
+  * recursively lex source chunks.
+  * @private
+  */
+function PR_splitTagAttributes(tokens) {
+  var tokensOut = [];
+  var state = 0;
+  var stateStyle = PR_TAG;
+  var delim = null;  // attribute delimiter for quoted value state.
+  var decodeHelper = new PR_DecodeHelper();
+  for (var ci = 0; ci < tokens.length; ++ci) {
+    var tok = tokens[ci];
+    if (PR_TAG == tok.style) {
+      var s = tok.token;
+      var start = 0;
+      for (var i = 0; i < s.length; /* i = next at bottom */) {
+        decodeHelper.decode(s, i);
+        var ch = decodeHelper.ch;
+        var next = decodeHelper.next;
+
+        var emitEnd = null;  // null or position of end of chunk to emit.
+        var nextStyle = null;  // null or next value of stateStyle
+        if (ch == '>') {
+          if (PR_TAG != stateStyle) {
+            emitEnd = i;
+            nextStyle = PR_TAG;
+          }
+        } else {
+          switch (state) {
+            case 0:
+              if ('<' == ch) { state = 1; }
+              break;
+            case 1:
+              if (PR_isSpaceChar(ch)) { state = 2; }
+              break;
+            case 2:
+              if (!PR_isSpaceChar(ch)) {
+                nextStyle = PR_ATTRIB_NAME;
+                emitEnd = i;
+                state = 3;
+              }
+              break;
+            case 3:
+              if ('=' == ch) {
+                emitEnd = i;
+                nextStyle = PR_TAG;
+                state = 5;
+              } else if (PR_isSpaceChar(ch)) {
+                emitEnd = i;
+                nextStyle = PR_TAG;
+                state = 4;
+              }
+              break;
+            case 4:
+              if ('=' == ch) {
+                state = 5;
+              } else if (!PR_isSpaceChar(ch)) {
+                emitEnd = i;
+                nextStyle = PR_ATTRIB_NAME;
+                state = 3;
+              }
+              break;
+            case 5:
+              if ('"' == ch || '\'' == ch) {
+                emitEnd = i;
+                nextStyle = PR_ATTRIB_VALUE;
+                state = 6;
+                delim = ch;
+              } else if (!PR_isSpaceChar(ch)) {
+                emitEnd = i;
+                nextStyle = PR_ATTRIB_VALUE;
+                state = 7;
+              }
+              break;
+            case 6:
+              if (ch == delim) {
+                emitEnd = next;
+                nextStyle = PR_TAG;
+                state = 2;
+              }
+              break;
+            case 7:
+              if (PR_isSpaceChar(ch)) {
+                emitEnd = i;
+                nextStyle = PR_TAG;
+                state = 2;
+              }
+              break;
+          }
+        }
+        if (emitEnd) {
+          if (emitEnd > start) {
+            tokensOut.push(
+                new PR_Token(s.substring(start, emitEnd), stateStyle));
+            start = emitEnd;
+          }
+          stateStyle = nextStyle;
+        }
+        i = next;
+      }
+      if (s.length > start) {
+        tokensOut.push(new PR_Token(s.substring(start, s.length), stateStyle));
+      }
+    } else {
+      if (tok.style) {
+        state = 0;
+        stateStyle = PR_TAG;
+      }
+      tokensOut.push(tok);
+    }
+  }
+  return tokensOut;
+}
+
+/** identify regions of markup that are really source code, and recursivley
+  * lex them.
+  * @private
+  */
+function PR_splitSourceNodes(tokens) {
+  var tokensOut = [];
+  // when we see a <script> tag, store '/' here so that we know to end the
+  // source processing
+  var endScriptTag = null;
+  var decodeHelper = new PR_DecodeHelper();
+
+  var sourceChunks = null;
+
+  for (var ci = 0, nc = tokens.length; /* break below */; ++ci) {
+    var tok;
+
+    if (ci < nc) {
+      tok = tokens[ci];
+      if (null == tok.style) {
+        tokens.push(tok);
+        continue;
+      }
+    } else if (!endScriptTag) {
+      break;
+    } else {
+      // else pretend there's an end tag so we can gracefully handle
+      // unclosed source blocks
+      tok = new PR_Token('', null);
+    }
+
+    var s = tok.token;
+
+    if (null == endScriptTag) {
+      if (PR_SOURCE == tok.style) {
+        // split off any starting and trailing <?, <%
+        if ('<' == decodeHelper.decode(s, 0)) {
+          decodeHelper.decode(s, decodeHelper.next);
+          if ('%' == decodeHelper.ch || '?' == decodeHelper.ch) {
+            endScriptTag = decodeHelper.ch;
+            tokensOut.push(new PR_Token(s.substring(0, decodeHelper.next),
+                                        PR_TAG));
+            s = s.substring(decodeHelper.next, s.length);
+          }
+        }
+      } else if (PR_TAG == tok.style) {
+        if ('<' == decodeHelper.decode(s, 0) &&
+            '/' != s.charAt(decodeHelper.next)) {
+          var tagContent = s.substring(decodeHelper.next).toLowerCase();
+          // FIXME(msamuel): this does not mirror exactly the code in
+          // in PR_splitMarkup that defers splitting tags inside script and
+          // style blocks.
+          if (PR_startsWith(tagContent, 'script') ||
+              PR_startsWith(tagContent, 'style') ||
+              PR_startsWith(tagContent, 'xmp')) {
+            endScriptTag = '/';
+          }
+        }
+      }
+    }
+
+    if (null != endScriptTag) {
+      var endTok = null;
+      if (PR_SOURCE == tok.style) {
+        if (endScriptTag == '%' || endScriptTag == '?') {
+          var pos = s.lastIndexOf(endScriptTag);
+          if (pos >= 0 && '>' == decodeHelper.decode(s, pos + 1) &&
+              s.length == decodeHelper.next) {
+            endTok = new PR_Token(s.substring(pos, s.length), PR_TAG);
+            s = s.substring(0, pos);
+          }
+        }
+        if (null == sourceChunks) { sourceChunks = []; }
+        sourceChunks.push(new PR_Token(s, PR_PLAIN));
+      } else if (PR_PLAIN == tok.style) {
+        if (null == sourceChunks) { sourceChunks = []; }
+        sourceChunks.push(tok);
+      } else if (PR_TAG == tok.style) {
+        // if it starts with </ then it must be the end tag.
+        if ('<' == decodeHelper.decode(tok.token, 0) &&
+            tok.token.length > decodeHelper.next &&
+            '/' == decodeHelper.decode(tok.token, decodeHelper.next)) {
+          endTok = tok;
+        } else {
+          tokensOut.push(tok);
+        }
+      } else if (ci >= nc) {
+        // force the token to close
+        endTok = tok;
+      } else {
+        if (sourceChunks) {
+          sourceChunks.push(tok);
+        } else {
+          // push remaining tag and attribute tokens from the opening tag
+          tokensOut.push(tok);
+        }
+      }
+      if (endTok) {
+        if (sourceChunks) {
+          var sourceTokens = PR_lexSource(sourceChunks);
+          tokensOut.push(new PR_Token('<span class=embsrc>', null));
+          for (var si = 0, ns = sourceTokens.length; si < ns; ++si) {
+            tokensOut.push(sourceTokens[si]);
+          }
+          tokensOut.push(new PR_Token('</span>', null));
+          sourceChunks = null;
+        }
+        if (endTok.token) { tokensOut.push(endTok); }
+        endScriptTag = null;
+      }
+    } else {
+      tokensOut.push(tok);
+    }
+  }
+  return tokensOut;
+}
+
+/** splits the quotes from an attribute value.
+  * ['"foo"'] -> ['"', 'foo', '"']
+  * @private
+  */
+function PR_splitAttributeQuotes(tokens) {
+  var firstPlain = null, lastPlain = null;
+  for (var i = 0; i < tokens.length; ++i) {
+    if (PR_PLAIN == tokens[i].style) {
+      firstPlain = i;
+      break;
+    }
+  }
+  for (var i = tokens.length; --i >= 0;) {
+    if (PR_PLAIN == tokens[i].style) {
+      lastPlain = i;
+      break;
+    }
+  }
+  if (null == firstPlain) { return tokens; }
+
+  var decodeHelper = new PR_DecodeHelper();
+  var fs = tokens[firstPlain].token;
+  var fc = decodeHelper.decode(fs, 0);
+  if ('"' != fc && '\'' != fc) {
+    return tokens;
+  }
+  var fpos = decodeHelper.next;
+
+  var ls = tokens[lastPlain].token;
+  var lpos = ls.lastIndexOf('&');
+  if (lpos < 0) { lpos = ls.length - 1; }
+  var lc = decodeHelper.decode(ls, lpos);
+  if (lc != fc || decodeHelper.next != ls.length) {
+    lc = null;
+    lpos = ls.length;
+  }
+
+  var tokensOut = [];
+  for (var i = 0; i < firstPlain; ++i) {
+    tokensOut.push(tokens[i]);
+  }
+  tokensOut.push(new PR_Token(fs.substring(0, fpos), PR_ATTRIB_VALUE));
+  if (lastPlain == firstPlain) {
+    tokensOut.push(new PR_Token(fs.substring(fpos, lpos), PR_PLAIN));
+  } else {
+    tokensOut.push(new PR_Token(fs.substring(fpos, fs.length), PR_PLAIN));
+    for (var i = firstPlain + 1; i < lastPlain; ++i) {
+      tokensOut.push(tokens[i]);
+    }
+    if (lc) {
+      tokens.push(new PR_Token(ls.substring(0, lpos), PR_PLAIN));
+    } else {
+      tokens.push(tokens[lastPlain]);
+    }
+  }
+  if (lc) {
+    tokensOut.push(new PR_Token(ls.substring(lpos, ls.length), PR_PLAIN));
+  }
+  for (var i = lastPlain + 1; i < tokens.length; ++i) {
+    tokensOut.push(tokens[i]);
+  }
+  return tokensOut;
+}
+
+/** identify attribute values that really contain source code and recursively
+  * lex them.
+  * @private
+  */
+function PR_splitSourceAttributes(tokens) {
+  var tokensOut = [];
+
+  var sourceChunks = null;
+  var inSource = false;
+  var name = '';
+
+  for (var ci = 0, nc = tokens.length; ci < nc; ++ci) {
+    var tok = tokens[ci];
+    var outList = tokensOut;
+    if (PR_TAG == tok.style) {
+      if (inSource) {
+        inSource = false;
+        name = '';
+        if (sourceChunks) {
+          tokensOut.push(new PR_Token('<span class=embsrc>', null));
+          var sourceTokens =
+            PR_lexSource(PR_splitAttributeQuotes(sourceChunks));
+          for (var si = 0, ns = sourceTokens.length; si < ns; ++si) {
+            tokensOut.push(sourceTokens[si]);
+          }
+          tokensOut.push(new PR_Token('</span>', null));
+          sourceChunks = null;
+        }
+      } else if (name && tok.token.indexOf('=') >= 0) {
+        var nameLower = name.toLowerCase();
+        if (PR_startsWith(nameLower, 'on') || 'style' == nameLower) {
+          inSource = true;
+        }
+      } else {
+        name = '';
+      }
+    } else if (PR_ATTRIB_NAME == tok.style) {
+      name += tok.token;
+    } else if (PR_ATTRIB_VALUE == tok.style) {
+      if (inSource) {
+        if (null == sourceChunks) { sourceChunks = []; }
+        outList = sourceChunks;
+        tok = new PR_Token(tok.token, PR_PLAIN);
+      }
+    } else {
+      if (sourceChunks) {
+        outList = sourceChunks;
+      }
+    }
+    outList.push(tok);
+  }
+  return tokensOut;
+}
+
+/** returns a list of PR_Token objects given chunks of source code.
+  *
+  * This code treats ", ', and ` as string delimiters, and \ as a string escape.
+  * It does not recognize perl's qq() style strings.  It has no special handling
+  * for double delimiter escapes as in basic, or tje tripled delimiters used in
+  * python, but should work on those regardless although in those cases a single
+  * string literal may be broken up into multiple adjacent string literals.
+  *
+  * It recognizes C, C++, and shell style comments.
+  *
+  * @param chunks PR_Tokens with style in (null, PR_PLAIN)
+  */
+function PR_lexSource(chunks) {
+  // split into strings, comments, and other.
+  // We do this because strings and comments are easily recognizable and can
+  // contain stuff that looks like other tokens, so we want to mark those early
+  // so we don't recurse into them.
+  var tokens = PR_splitStringAndCommentTokens(chunks);
+
+  // split non comment|string tokens on whitespace and word boundaries
+  var tokensOut = [];
+  for (var i = 0; i < tokens.length; ++i) {
+    var tok = tokens[i];
+    if (PR_PLAIN === tok.style) {
+      PR_splitNonStringNonCommentToken(tok.token, tokensOut);
+      continue;
+    }
+    tokensOut.push(tok);
+  }
+
+  return tokensOut;
+}
+
+/** returns a list of PR_Token objects given a string of markup.
+  *
+  * This code assumes that < tokens are html escaped, but " are not.
+  * It will do a resonable job with <, but will not recognize an &quot;
+  * as starting a string.
+  *
+  * This code recognizes a number of constructs.
+  * <!-- ... --> comment
+  * <!\w ... >   declaration
+  * <\w ... >    tag
+  * </\w ... >   tag
+  * <?...?>      embedded source
+  * &[#\w]...;   entity
+  *
+  * It does not recognizes %foo; entities.
+  *
+  * It will recurse into any <style>, <script>, and on* attributes using
+  * PR_lexSource.
+  */
+function PR_lexMarkup(chunks) {
+  // This function works as follows:
+  // 1) Start by splitting the markup into text and tag chunks
+  //    Input:  String s
+  //    Output: List<PR_Token> where style in (PR_PLAIN, null)
+  // 2) Then split the text chunks further into comments, declarations,
+  //    tags, etc.
+  //    After each split, consider whether the token is the start of an
+  //    embedded source section, i.e. is an open <script> tag.  If it is,
+  //    find the corresponding close token, and don't bother to lex in between.
+  //    Input:  List<String>
+  //    Output: List<PR_Token> with style in (PR_TAG, PR_PLAIN, PR_SOURCE, null)
+  // 3) Finally go over each tag token and split out attribute names and values.
+  //    Input:  List<PR_Token>
+  //    Output: List<PR_Token> where style in
+  //            (PR_TAG, PR_PLAIN, PR_SOURCE, NAME, VALUE, null)
+  var tokensOut = PR_tokenizeMarkup(chunks);
+  tokensOut = PR_splitTagAttributes(tokensOut);
+  tokensOut = PR_splitSourceNodes(tokensOut);
+  tokensOut = PR_splitSourceAttributes(tokensOut);
+  return tokensOut;
+}
+
+/**
+ * classify the string as either source or markup and lex appropriately.
+ * @param {String} html
+ */
+function PR_lexOne(html) {
+  var chunks = PR_expandTabs(PR_chunkify(html), PR_TAB_WIDTH);
+
+  // treat it as markup if the first non whitespace character is a < and the
+  // last non-whitespace character is a >
+  var isMarkup = false;
+  for (var i = 0; i < chunks.length; ++i) {
+    if (PR_PLAIN == chunks[i].style) {
+      if (PR_startsWith(PR_trim(chunks[i].token), '&lt;')) {
+        for (var j = chunks.length; --j >= 0;) {
+          if (PR_PLAIN == chunks[j].style) {
+            isMarkup = PR_endsWith(PR_trim(chunks[j].token), '&gt;');
+            break;
+          }
+        }
+      }
+      break;
+    }
+  }
+
+  return isMarkup ? PR_lexMarkup(chunks) : PR_lexSource(chunks);
+}
+
+/** pretty print a chunk of code.
+  *
+  * @param s code as html
+  * @return code as html, but prettier
+  */
+function prettyPrintOne(s) {
+  try {
+    var tokens = PR_lexOne(s);
+    var out = [];
+    var lastStyle = null;
+    for (var i = 0; i < tokens.length; i++) {
+      var t = tokens[i];
+      if (t.style != lastStyle) {
+        if (lastStyle != null) {
+          out.push('</span>');
+        }
+        if (t.style != null) {
+          out.push('<span class=', t.style, '>');
+        }
+        lastStyle = t.style;
+      }
+      var html = t.token;
+      if (null != t.style) {
+        // This interacts badly with some wikis which introduces paragraph tags
+        // into pre blocks for some strange reason.
+        // It's necessary for IE though which seems to lose the preformattedness
+        // of <pre> tags when their innerHTML is assigned.
+        // http://stud3.tuwien.ac.at/~e0226430/innerHtmlQuirk.html
+        html = html
+               .replace(/(\r\n?|\n| ) /g, '$1&nbsp;')
+               .replace(/\r\n?|\n/g, '<br>');
+      }
+      out.push(html);
+    }
+    if (lastStyle != null) {
+      out.push('</span>');
+    }
+    return out.join('');
+  } catch (e) {
+    if ('console' in window) {
+      console.log(e);
+      console.trace();
+    }
+    return s;
+  }
+}
+
+/** find all the < pre > and < code > tags in the DOM with class=prettyprint and
+  * prettify them.
+  */
+function prettyPrint() {
+  // fetch a list of nodes to rewrite
+  var codeSegments = [
+      document.getElementsByTagName('pre'),
+      document.getElementsByTagName('code'),
+      document.getElementsByTagName('xmp') ];
+  var elements = [];
+  for (var i = 0; i < codeSegments.length; ++i) {
+    for (var j = 0; j < codeSegments[i].length; ++j) {
+      elements.push(codeSegments[i][j]);
+    }
+  }
+  codeSegments = null;
+
+  // the loop is broken into a series of continuations to make sure that we
+  // don't make the browser unresponsive when rewriting a large page.
+  var k = 0;
+
+  function doWork() {
+    var endTime = new Date().getTime() + 250;
+    for (; k < elements.length && new Date().getTime() < endTime; k++) {
+      var cs = elements[k];
+      
+      /* added classname 'prettified' to avoid double processing */
+      if (cs.className 
+       && cs.className.indexOf('prettyprint') >= 0 
+       && cs.className.indexOf('prettified') == -1 ) {
+
+        // make sure this is not nested in an already prettified element
+        var nested = false;
+        for (var p = cs.parentNode; p != null; p = p.parentNode) {
+          if ((p.tagName == 'pre' || p.tagName == 'code' ||
+               p.tagName == 'xmp') &&
+              p.className && p.className.indexOf('prettyprint') >= 0) {
+            nested = true;
+            break;
+          }
+        }
+        if (!nested) {        
+          // fetch the content as a snippet of properly escaped HTML.
+          // Firefox adds newlines at the end.
+          var content = PR_getInnerHtml(cs);
+          content = content.replace(/(?:\r\n?|\n)$/, '');
+
+          // do the pretty printing
+          var newContent = prettyPrintOne(content);
+
+          // push the prettified html back into the tag.
+          if (!PR_isRawContent(cs)) {
+            // just replace the old html with the new
+            cs.innerHTML = newContent;
+          } else {
+            // we need to change the tag to a <pre> since <xmp>s do not allow
+            // embedded tags such as the span tags used to attach styles to
+            // sections of source code.
+            var pre = document.createElement('PRE');
+            for (var i = 0; i < cs.attributes.length; ++i) {
+              var a = cs.attributes[i];
+              if (a.specified) {
+                pre.setAttribute(a.name, a.value);
+              }
+            }
+            pre.innerHTML = newContent;
+            // remove the old
+            cs.parentNode.replaceChild(pre, cs);
+          }
+          //mark the element as converted
+          cs.className = cs.className+' prettified';
+        }
+      }
+    }
+    if (k < elements.length) {
+      // finish up in a continuation
+      setTimeout(doWork, 250);
+    }
+  }
+
+  doWork();
+}