Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit a5b4d3c

Browse files
comment fixup and made sure that typeof is recognized as a javascript keyword. Added some annotations to make it work with js compilers/minifiers.
1 parent c3d8c20 commit a5b4d3c

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h2>Usage</h2>
6262
</table>
6363

6464
<h2>FAQ</h2>
65-
<h3>Which languages does it work for?</h3>
65+
<h3 id="langs">Which languages does it work for?</h3>
6666
<p>The comments in <tt>prettify.js</tt> are authoritative but the lexer
6767
should work on a number of languages including C and friends,
6868
Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles.

src/prettify.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,41 @@
1616
/**
1717
* @fileoverview
1818
* some functions for browser-side pretty printing of code contained in html.
19+
* <p>
1920
*
20-
* The lexer should work on a number of languages including C and friends,
21-
* Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles.
22-
* It works passably on Ruby, PHP and Awk and a decent subset of Perl, but,
23-
* because of commenting conventions, doesn't work on Smalltalk, Lisp-like, or
24-
* CAML-like languages.
25-
*
26-
* If there's a language not mentioned here, then I don't know it, and don't
27-
* know whether it works. If it has a C-like, Bash-like, or XML-like syntax
28-
* then it should work passably.
29-
*
30-
* Usage:
31-
* 1) include this source file in an html page via
32-
* <script type="text/javascript" src="/path/to/prettify.js"></script>
33-
* 2) define style rules. See the example page for examples.
34-
* 3) mark the <pre> and <code> tags in your source with class=prettyprint.
35-
* You can also use the (html deprecated) <xmp> tag, but the pretty printer
36-
* needs to do more substantial DOM manipulations to support that, so some
37-
* css styles may not be preserved.
21+
* For a fairly comprehensive set of languages see the
22+
* <a href="http://google-code-prettify.googlecode.com/svn/trunk/README.html#langs">README</a>
23+
* file that came with this source. At a minimum, the lexer should work on a
24+
* number of languages including C and friends, Java, Python, Bash, SQL, HTML,
25+
* XML, CSS, Javascript, and Makefiles. It works passably on Ruby, PHP and Awk
26+
* and a subset of Perl, but, because of commenting conventions, doesn't work on
27+
* Smalltalk, Lisp-like, or CAML-like languages without an explicit lang class.
28+
* <p>
29+
* Usage: <ol>
30+
* <li> include this source file in an html page via
31+
* {@code <script type="text/javascript" src="/path/to/prettify.js"></script>}
32+
* <li> define style rules. See the example page for examples.
33+
* <li> mark the {@code <pre>} and {@code <code>} tags in your source with
34+
* {@code class=prettyprint.}
35+
* You can also use the (html deprecated) {@code <xmp>} tag, but the pretty
36+
* printer needs to do more substantial DOM manipulations to support that, so
37+
* some css styles may not be preserved.
38+
* </ol>
3839
* That's it. I wanted to keep the API as simple as possible, so there's no
39-
* need to specify which language the code is in.
40-
*
41-
* Change log:
40+
* need to specify which language the code is in, but if you wish, you can add
41+
* another class to the {@code <pre>} or {@code <code>} element to specify the
42+
* language, as in {@code <pre class="prettyprint lang-java">}. Any class that
43+
* starts with "lang-" followed by a file extension, specifies the file type.
44+
* See the "lang-*.js" files in this directory for code that implements
45+
* per-language file handlers.
46+
* <p>
47+
* Change log:<br>
4248
* cbeust, 2006/08/22
49+
* <blockquote>
4350
* Java annotations (start with "@") are now captured as literals ("lit")
51+
* </blockquote>
52+
* @requires console
53+
* @overrides window
4454
*/
4555

4656
// JSLint declarations
@@ -97,12 +107,12 @@ window['_pr_isIE6'] = function () {
97107
"double enum extern float goto int long register short signed sizeof " +
98108
"static struct switch typedef union unsigned void volatile ";
99109
var COMMON_KEYWORDS = C_KEYWORDS + "catch class delete false import " +
100-
"new operator private protected public this throw true try ";
110+
"new operator private protected public this throw true try typeof ";
101111
var CPP_KEYWORDS = COMMON_KEYWORDS + "alignof align_union asm axiom bool " +
102112
"concept concept_map const_cast constexpr decltype " +
103113
"dynamic_cast explicit export friend inline late_check " +
104114
"mutable namespace nullptr reinterpret_cast static_assert static_cast " +
105-
"template typeid typename typeof using virtual wchar_t where ";
115+
"template typeid typename using virtual wchar_t where ";
106116
var JAVA_KEYWORDS = COMMON_KEYWORDS +
107117
"abstract boolean byte extends final finally implements import " +
108118
"instanceof null native package strictfp super synchronized throws " +
@@ -283,7 +293,7 @@ window['_pr_isIE6'] = function () {
283293
// unnecessary computed style objects.
284294
if ('PRE' === node.tagName) { return true; }
285295
if (!newlineRe.test(content)) { return true; } // Don't care
286-
var whitespace;
296+
var whitespace = '';
287297
// For disconnected nodes, IE has no currentStyle.
288298
if (node.currentStyle) {
289299
whitespace = node.currentStyle.whiteSpace;
@@ -477,7 +487,6 @@ window['_pr_isIE6'] = function () {
477487

478488
// Walk over and identify back references to build the capturedGroups
479489
// mapping.
480-
var groupIndex;
481490
for (var i = 0, groupIndex = 0; i < n; ++i) {
482491
var p = parts[i];
483492
if (p === '(') {
@@ -842,7 +851,7 @@ window['_pr_isIE6'] = function () {
842851
for (var ti = 0, nTokens = tokens.length; ti < nTokens; ++ti) {
843852
var token = tokens[ti];
844853
var style = styleCache[token];
845-
var match;
854+
var match = void 0;
846855

847856
var isEmbedded;
848857
if (typeof style === 'string') {

0 commit comments

Comments
 (0)