diff --git a/.gitignore b/.gitignore
index 82c2cb8f..433f78b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,18 @@
-*.tstamp
+# temporary files
*~
-distrib/google-code-prettify
-distrib/prettify-small.tar
+*.swp
+.DS_Store
+
+# package managers
+/node_modules/
+/bower_components/
+npm-debug.log
+.bower.json
+
+# generated files
+#/src/prettify.js
+#/src/run_prettify.js
+#/loader/*.js
+#/loader/*.css
+#/loader/skins/*.css
+#/distrib/*.zip
diff --git a/CHANGES.md b/CHANGES.md
index a4a5bdc5..7371e7c8 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -13,15 +13,15 @@
## 29 March 2007
- * Added [tests](https://rawgit.com/google/code-prettify/master/tests/prettify_test.html#PHP)
+ * Added [tests](https://raw.githack.com/google/code-prettify/master/tests/prettify_test.html#php)
for PHP support to address issue [#3](https://github.com/google/code-prettify/issues/3).
* Fixed bug [#6](https://github.com/google/code-prettify/issues/6): `prettyPrintOne`
was not halting. This was not reachable through the normal entry point.
* Fixed bug [#4](https://github.com/google/code-prettify/issues/4): recursing into a
script block or PHP tag that was not properly closed would not silently drop the content.
- ([test](https://rawgit.com/google/code-prettify/master/tests/prettify_test.html#issue4))
+ ([test](https://raw.githack.com/google/code-prettify/master/tests/prettify_test.html#js_script))
* Fixed bug [#8](https://github.com/google/code-prettify/issues/8): was eating tabs
- ([test](https://rawgit.com/google/code-prettify/master/tests/prettify_test.html#issue8))
+ ([test](https://raw.githack.com/google/code-prettify/master/tests/prettify_test.html#issue8))
* Fixed entity handling so that the caveat
> Caveats: please properly escape less-thans. `x<y` instead of `x',
+ dest: '<%= uglify.prettify.dest %>'
+ },
+ runprettify: {
+ options: {
+ externs: 'tools/closure-compiler/amd-externs.js',
+ define: 'IN_GLOBAL_SCOPE=false',
+ output_wrapper: '!function(){%output%}()'
+ },
+ src: '<%= uglify.runprettify.src %>',
+ dest: '<%= uglify.runprettify.dest %>'
+ },
+ langs: {
+ options: {
+ externs: 'js-modules/externs.js'
+ },
+ files: '<%= uglify.langs.files %>'
+ }
+ },
+
+ // ./tasks/gcc.js
+ gcc: {
+ // same as 'closure-compiler:langs'
+ langs: {
+ options: {
+ externs: 'js-modules/externs.js'
+ },
+ files: '<%= uglify.langs.files %>'
+ }
+ },
+
+ // grunt-contrib-cssmin
+ cssmin: {
+ // https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api
+ options: {
+ report: 'gzip'
+ },
+ prettify: {
+ src: 'src/prettify.css',
+ dest: 'loader/prettify.css'
+ },
+ skins: {
+ files: [{
+ expand: true,
+ cwd: 'styles/',
+ src: ['*.css'],
+ dest: 'loader/skins/',
+ ext: '.css'
+ }]
+ }
+ },
+
+ // grunt-contrib-compress
+ compress: {
+ zip: {
+ options: {
+ archive: 'distrib/prettify-small.zip',
+ mode: 'zip',
+ level: 9
+ },
+ files: [{
+ expand: true,
+ cwd: 'loader/',
+ src: ['*.js', '*.css', 'skins/*.css'],
+ dest: 'google-code-prettify/'
+ }]
+ }
+ },
+
+ // grunt-contrib-clean
+ clean: {
+ js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'],
+ css: ['loader/*.css', 'loader/skins/*.css'],
+ zip: ['distrib/*.zip']
+ }
+ });
+
+ // load plugins that provide tasks
+ require('google-closure-compiler').grunt(grunt);
+ grunt.loadTasks('./tasks');
+ grunt.loadNpmTasks('grunt-preprocess');
+ grunt.loadNpmTasks('grunt-contrib-copy');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadNpmTasks('grunt-contrib-cssmin');
+ grunt.loadNpmTasks('grunt-contrib-compress');
+ grunt.loadNpmTasks('grunt-contrib-clean');
+
+ // register task aliases
+ grunt.registerTask('default', [
+ //'clean',
+ 'preprocess',
+ 'copy:prettify',
+ 'gcc',
+ 'copy:langs',
+ 'aliases',
+ 'cssmin',
+ 'compress'
+ ]);
+};
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 70bbacfc..00000000
--- a/Makefile
+++ /dev/null
@@ -1,120 +0,0 @@
-SHELL := /bin/bash
-
-CLOSURE_COMPILER=java -jar tools/closure-compiler/compiler.jar \
- --warning_level VERBOSE \
- --language_in ECMASCRIPT5 \
- --compilation_level ADVANCED_OPTIMIZATIONS \
- --charset US-ASCII
-# Don't specify --charset=UTF-8. If we do, then non-ascii codepoints
-# that do not correspond to line terminators are converted
-# to UTF-8 sequences instead of being emitted as ASCII.
-# This makes the resulting JavaScript less portable.
-
-YUI_COMPRESSOR=java -jar tools/yui-compressor/yuicompressor-2.4.8.jar \
- --charset UTF-8
-
-TAR_ROOT=distrib/google-code-prettify
-
-all: distrib loader
-
-clean:
- rm -rf distrib.tstamp distrib loader.tstamp src/prettify.js src/run_prettify.js
-
-src/prettify.js: js-modules/*.js js-modules/*.pl
- @if [ -e "$@" ]; then chmod +w "$@"; fi
- @perl js-modules/js_include.pl "$$(basename $@)" > "$@"
- @if [ -e "$@" ]; then chmod -w "$@"; fi
-
-src/run_prettify.js: js-modules/*.js js-modules/*.pl
- @if [ -e "$@" ]; then chmod +w "$@"; fi
- @perl js-modules/js_include.pl "$$(basename $@)" > "$@"
- @if [ -e "$@" ]; then chmod -w "$@"; fi
-
-distrib: distrib.tstamp distrib/prettify-small.tgz distrib/prettify-small.zip distrib/prettify-small.tar.bz2
- @wc -c distrib/prettify-small.{tar.bz2,tgz,zip} \
- | grep -v total
-
-distrib.tstamp: src/prettify.js src/run_prettify.js src/*.js src/*.css
- @echo Compiling
- @mkdir -p $(TAR_ROOT)
- @for f in src/*.css; do \
- $(YUI_COMPRESSOR) --type css $$f \
- > $(TAR_ROOT)/$$(basename $$f); \
- wc -c $$f $(TAR_ROOT)/$$(basename $$f) \
- | grep -v total; \
- done
- @$(CLOSURE_COMPILER) --js src/prettify.js \
- --externs tools/closure-compiler/amd-externs.js \
- --define IN_GLOBAL_SCOPE=true \
- --output_wrapper='!function(){%output%}()' \
- > $(TAR_ROOT)/prettify.js
- @wc -c src/prettify.js $(TAR_ROOT)/prettify.js \
- | grep -v total
- @$(CLOSURE_COMPILER) --js src/run_prettify.js \
- --externs tools/closure-compiler/amd-externs.js \
- --define IN_GLOBAL_SCOPE=false \
- --output_wrapper='!function(){%output%}()' \
- > $(TAR_ROOT)/run_prettify.js
- @wc -c src/run_prettify.js $(TAR_ROOT)/run_prettify.js \
- | grep -v total
- @for f in src/lang*.js; do \
- if [ $$f -nt $(TAR_ROOT)/$$(basename $$f) ]; then \
- $(CLOSURE_COMPILER) --js $$f --externs js-modules/externs.js \
- | perl -pe 's/\bPR\.PR_ATTRIB_NAME\b/"atn"/g; \
- s/\bPR\.PR_ATTRIB_VALUE\b/"atv"/g; \
- s/\bPR\.PR_COMMENT\b/"com"/g; \
- s/\bPR\.PR_DECLARATION\b/"dec"/g; \
- s/\bPR\.PR_KEYWORD\b/"kwd"/g; \
- s/\bPR\.PR_LITERAL\b/"lit"/g; \
- s/\bPR\.PR_PLAIN\b/"pln"/g; \
- s/\bPR\.PR_PUNCTUATION\b/"pun"/g; \
- s/\bPR\.PR_STRING\b/"str"/g; \
- s/\bPR\.PR_TAG\b/"tag"/g; \
- s/\bPR\.PR_TYPE\b/"typ"/g;' \
- > $(TAR_ROOT)/$$(basename $$f); \
- wc -c $$f $(TAR_ROOT)/$$(basename $$f) \
- | grep -v total; \
- fi \
- done
- @touch distrib.tstamp
-
-lang-aliases : lang-aliases.tstamp
-lang-aliases.tstamp : distrib.tstamp
- tools/lang-handler-aliases.sh \
- distrib/google-code-prettify \
- | perl -ne 'system("cp $$1 $$2") if m/^(\S+) (\S+)$$/ && ! -e $$2' \
- && touch lang-aliases.tstamp
-
-loader : loader.tstamp lang-aliases.tstamp styles/*.css
-
-loader.tstamp : distrib.tstamp
- @cp distrib/google-code-prettify/*.{css,js} loader/ \
- && for f in styles/*.css; do \
- $(YUI_COMPRESSOR) --type css $$f \
- > loader/skins/$$(basename $$f); \
- wc -c $$f loader/skins/$$(basename $$f) \
- | grep -v total; \
- done \
- && touch loader.tstamp
-
-%.tgz: %.tar
- @gzip -c -9 $^ > $@
-
-%.tar.bz2: %.tar
- @bzip2 -k -9f $^
-
-distrib/prettify-small.tar: distrib.tstamp
- tar cf $@ -C distrib google-code-prettify
-
-distrib/prettify-small.zip: distrib.tstamp
- @pushd distrib >& /dev/null; \
- rm -f ../$@; \
- zip -q -9 -r ../$@ google-code-prettify; \
- popd >& /dev/null
-
-distrib/prettify.tar: distrib.tstamp
- mkdir -p distrib/sources/google-code-prettify
- cp -fr CHANGES.html COPYING README.html Makefile \
- examples js-modules src styles tests tools \
- distrib/sources/google-code-prettify
- tar cf distrib/prettify.tar -C distrib/sources google-code-prettify
diff --git a/README.md b/README.md
index af3e91cd..41cd727e 100644
--- a/README.md
+++ b/README.md
@@ -1,25 +1,47 @@
-# Javascript code prettifier
+# Status: Archived
+
+
+
+This repository has been archived and is no longer maintained.
+
+---
+
+# JavaScript code prettifier
+
+Announcement: [**Action required** *rawgit.com* is going away](https://groups.google.com/forum/#!topic/js-code-prettifier/IFHev_kLm30).
An embeddable script that makes source-code snippets in HTML prettier.
-[See an example](https://rawgit.com/google/code-prettify/master/examples/quine.html)
+* Works on HTML pages.
+* Works even if code contains embedded links, line numbers, etc.
+* Simple API: include some JS & CSS and add an onload handler.
+* Lightweights: small download and does not block page from loading while
+ running.
+* Customizable styles via CSS. See the [themes gallery][1].
+* Supports all C-like, Bash-like, and XML-like languages. No need to specify
+ the language.
+* Extensible language handlers for other languages. You can specify the
+ language.
+* Widely used with good cross-browser support. Powers https://code.google.com/
+ and http://stackoverflow.com/
+
+[See an example][2].
## Setup
- * Include the script tag below in your document
+ * Include the script tag below in your document:
```HTML
-
+
```
* See [Getting Started](docs/getting_started.md) to configure that URL with
options you need.
- * Look at the [skin gallery](https://rawgit.com/google/code-prettify/master/styles/index.html)
- and pick styles that suit you.
+ * Look at the [skin gallery][1] and pick styles that suit you.
## Usage
Put code snippets in `
...
` or
`...` and it will automatically be
-pretty printed.
+pretty-printed.
```HTML
class Voila {
@@ -31,24 +53,17 @@ public:
}
```
-## Discussion
-
-Please use the official support group for discussions, suggestions, and
-general feedback at:
-
-http://groups.google.com/group/js-code-prettifier
-
## FAQ
### For which languages does it work?
-The comments in `prettify.js` are authoritative but the lexer should
-work on a number of languages including C and friends, Java, Python,
-Bash, SQL, HTML, XML, CSS, Javascript, Makefiles, and Rust.
+The comments in `prettify.js` are authoritative but the lexer should work on a
+number of languages including C and friends, Java, Python, Bash, SQL, HTML,
+XML, CSS, JavaScript, Makefile, and Rust.
-It works passably on Ruby, PHP, VB, and Awk and a decent subset of
-Perl and Ruby, but, because of commenting conventions, doesn't work on
-Smalltalk, OCaml, etc. without a language extension.
+It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl and
+Ruby, but because of commenting conventions, doesn't work on Smalltalk, OCaml,
+etc. without a language extension.
Other languages are supported via extensions:
@@ -62,10 +77,10 @@ Other languages are supported via extensions:
[Haskell](src/lang-hs.js);
[Lasso](src/lang-lasso.js);
[Lisp, Scheme](src/lang-lisp.js);
-[Llvm](src/lang-llvm.js);
+[LLVM](src/lang-llvm.js);
[Logtalk](src/lang-logtalk.js);
[Lua](src/lang-lua.js);
-[Matlab](src/lang-matlab.js);
+[MATLAB](src/lang-matlab.js);
[MLs: F#, Ocaml,SML](src/lang-ml.js);
[Mumps](src/lang-mumps.js);
[Nemerle](src/lang-n.js);
@@ -78,40 +93,40 @@ Other languages are supported via extensions:
[SQL](src/lang-sql.js);
[Swift](src/lang-swift.js);
[TCL](src/lang-tcl.js);
-[Latek](src/lang-tex.js);
+[LaTeX](src/lang-tex.js);
[Visual Basic](src/lang-vb.js);
[VHDL](src/lang-vhdl.js);
[Wiki](src/lang-wiki.js);
[XQ](src/lang-xq.js);
[YAML](src/lang-yaml.js)
-If you'd like to add an extension for your favorite language, please
-look at `src/lang-lisp.js` and submit a pull request.
+If you'd like to add an extension for your favorite language, please look at
+`src/lang-lisp.js` and submit a pull request.
### How do I specify the language of my code?
-You don't need to specify the language since `PR.prettyprint()`
-will guess. You can specify a language by specifying the language extension
-along with the `prettyprint` class:
+You don't need to specify the language since `PR.prettyPrint()` will guess.
+You can specify a language by specifying the language extension along with the
+`prettyprint` class:
```HTML
```
-You may also use the
-[HTML 5](http://dev.w3.org/html5/spec-author-view/the-code-element.html#the-code-element)
-convention of embedding a `code` element inside the `PRE` and using
-`language-java` style classes.
+You may also use the [HTML 5][3] convention of embedding a `` element
+inside the `
` and using `language-java` style classes:
-E.g. `
...
`
+```HTML
+
...
+```
-### It doesn't work on ``?
+### It doesn't work on "obfuscated code sample"?
Yes. Prettifying obfuscated code is like putting lipstick on a pig —
i.e. outside the scope of this tool.
@@ -119,30 +134,26 @@ i.e. outside the scope of this tool.
### Which browsers does it work with?
It's been tested with IE 6, Firefox 1.5 & 2, and Safari 2.0.4. Look at
-[the tests](https://rawgit.com/google/code-prettify/master/tests/prettify_test.html)
-to see if it works in your browser.
+[the tests][4] to see if it works in your browser.
### What's changed?
-See the [change log](CHANGES.md)
+See the [changelog](CHANGES.md).
### Why doesn't Prettyprinting of strings work on WordPress?
-Apparently wordpress does "smart quoting" which changes close quotes.
-This causes end quotes to not match up with open quotes.
+Apparently wordpress does "smart quoting" which changes close quotes. This
+causes end quotes to not match up with open quotes.
-This breaks prettifying as well as copying and pasting of code samples.
-See [WordPress's help center](http://wordpress.org/support/topic/125038)
-for info on how to stop smart quoting of code snippets.
+This breaks prettifying as well as copying and pasting of code samples. See
+[WordPress's help center][5] for info on how to stop smart quoting of code
+snippets.
### How do I put line numbers in my code?
-You can use the `linenums` class to turn on line
-numbering. If your code doesn't start at line number 1, you can
-add a colon and a line number to the end of that class as in
-`linenums:52`.
-
-For example
+You can use the `linenums` class to turn on line numbering. If your code
+doesn't start at line number `1`, you can add a colon and a line number to the
+end of that class as in `linenums:52`. For example:
```HTML
+
int x = foo(); /* This is a comment This is not code
Continuation of comment */
int y = bar();
```
-For a more complete example see the issue22
-[testcase](https://rawgit.com/google/code-prettify/master/tests/prettify_test.html#issue22).
+For a more complete example see the [issue #22 testcase][6].
### I get an error message "a is not a function" or "opt_whenDone is not a function"
If you are calling `prettyPrint` via an event handler, wrap it in a function.
-Instead of doing
+Instead of doing:
```JavaScript
addEventListener('load', PR.prettyPrint, false);
```
-wrap it in a closure like
+wrap it in a closure like:
```JavaScript
-addEventListener('load', function (event) { PR.prettyPrint() }, false);
+addEventListener('load', function(event) { PR.prettyPrint(); }, false);
```
so that the browser does not pass an event object to `PR.prettyPrint`
@@ -192,35 +201,48 @@ which will confuse it.
### How can I customize the colors and styles of my code?
-Prettify adds `` with `class`es describing the kind of code.
-You can create CSS styles to matches these classes.
+Prettify adds `` with `class`es describing the kind of code. You can
+create CSS styles to matches these classes.
-See the [theme gallery](https://rawgit.com/google/code-prettify/master/styles/index.html)
-for examples.
+See the [theme gallery][1] for examples.
### I can't add classes to my code (because it comes from Markdown, etc.)
-Instead of `
` you can use a comment
-or processing instructions that survives processing instructions :
-`` works as explained in
-[Getting Started](docs/getting_started.md).
+Instead of `
` you can use a comment or processing
+instructions that survives processing instructions: `` works
+as explained in [Getting Started](docs/getting_started.md).
### How can I put line numbers on every line instead of just every fifth line?
-Prettify puts lines into an HTML list element so that line numbers
-aren't caught by copy/paste, and the line numbering is controlled by
-CSS in the default stylesheet, `prettify.css`.
+Prettify puts lines into an HTML list element so that line numbers aren't
+caught by copy/paste, and the line numbering is controlled by CSS in the
+default stylesheet, `prettify.css`.
+
+The following should turn line numbering back on for the other lines:
```HTML
```
-should turn line numbering back on for the other lines.
+## Discussion
+
+Please use the official [support group][7] for discussions, suggestions, and
+general feedback.
## License
-[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)
+[Apache License 2.0](COPYING)
+
+
+[1]: https://raw.githack.com/google/code-prettify/master/styles/index.html
+[2]: https://raw.githack.com/google/code-prettify/master/examples/quine.html
+[3]: http://dev.w3.org/html5/spec-author-view/the-code-element.html#the-code-element
+[4]: https://raw.githack.com/google/code-prettify/master/tests/prettify_test.html
+[5]: http://wordpress.org/support/topic/125038
+[6]: https://raw.githack.com/google/code-prettify/master/tests/prettify_test.html#issue22
+[7]: http://groups.google.com/group/js-code-prettifier
diff --git a/bower.json b/bower.json
new file mode 100644
index 00000000..27b13817
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,40 @@
+{
+ "name": "code-prettify",
+ "description": "Google Code Prettify",
+ "authors": [
+ "Google"
+ ],
+ "license": "Apache-2.0",
+ "homepage": "https://github.com/google/code-prettify",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/google/code-prettify.git"
+ },
+ "keywords": [
+ "syntax",
+ "highlight",
+ "highlighting",
+ "source",
+ "code",
+ "prettify",
+ "google"
+ ],
+ "main": [
+ "src/prettify.js",
+ "src/prettify.css"
+ ],
+ "moduleType": [
+ "globals",
+ "amd"
+ ],
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "distrib",
+ "js-modules",
+ "tasks",
+ "tests",
+ "tools"
+ ]
+}
diff --git a/distrib/prettify-small.tar.bz2 b/distrib/prettify-small.tar.bz2
deleted file mode 100644
index 8900c194..00000000
Binary files a/distrib/prettify-small.tar.bz2 and /dev/null differ
diff --git a/distrib/prettify-small.tgz b/distrib/prettify-small.tgz
deleted file mode 100644
index 9b320c42..00000000
Binary files a/distrib/prettify-small.tgz and /dev/null differ
diff --git a/distrib/prettify-small.zip b/distrib/prettify-small.zip
index 0f1e2473..c63da471 100644
Binary files a/distrib/prettify-small.zip and b/distrib/prettify-small.zip differ
diff --git a/docs/getting_started.md b/docs/getting_started.md
index 194f644e..81221bfe 100644
--- a/docs/getting_started.md
+++ b/docs/getting_started.md
@@ -1,19 +1,16 @@
# Getting Started
-## How to style code in your web-pages
-
-## Getting Started
-
You can load the Prettify script to highlight code in your web pages.
-It adds styles to code snippets so that token boundaries stand out and
-your readers can get the gist of your code without having to mentally
-perform a left-to-right parse.
+It adds styles to code snippets so that token boundaries stand out and your
+readers can get the gist of your code without having to mentally perform a
+left-to-right parse.
## Marking code sections
-The prettyprinter looks for `
`, ``, or `` elements
-with the *prettyprint* class:
+The prettyprinter looks for `
`, ``, or `` elements with the
+*prettyprint* class, and adds ``s to colorize keywords, strings,
+comments, and other token types.
```HTML
@@ -21,12 +18,9 @@ source code here
```
-and adds ``s to colorize keywords, strings, comments, and other
-token types.
-
-If you're using Markdown or some other HTML generator that does not
-add classes, you can alternatively ask the prettifier to target your
-code by preceding it with a processing instruction thus:
+If you're using Markdown or some other HTML generator that does not add
+classes, you can alternatively ask the prettifier to target your code by
+preceding it with a processing instruction thus:
```HTML
@@ -35,95 +29,91 @@ code here
```
-[Larger example](https://rawgit.com/google/code-prettify/master/examples/quine.html)
-
+[Larger example](https://raw.githack.com/google/code-prettify/master/examples/quine.html)
## Auto-Loader
-You can load the JavaScript and CSS for prettify via one URL
+You can load the JavaScript and CSS for prettify via one URL:
```HTML
-
+
```
-will load the entire system and schedule the prettifier to run on page
-load. There are a variety of additional options you can specify (as
-CGI arguments) to configure the runner.
+This will load the entire system and schedule the prettifier to run on page
+load. There are a variety of additional options you can specify (as CGI
+arguments) to configure the runner.
-| CGI parameter | default | meaning |
-| ------------- | ------- | ------- |
-| autoload=(true, false) | true | run automatically on page load |
-| lang=... | none | Loads the language handler for the given language which is usually the file extension for source files for that language. See the [index of language handlers](https://github.com/google/code-prettify/tree/master/src). If specified multiple times (`?lang=css&lang=ml`) then all are loaded. |
-| skin=... | none | See the [skin gallery](https://cdn.rawgit.com/google/code-prettify/master/styles/index.html). If specified multiple times, the first one to successfully load is used. |
-| callback=js_ident | | `window.exports["js_ident"]` will be called when prettyprinting finishes. If specified multiple times, all are called. |
+| CGI parameter | default | meaning |
+| --------------------- | ------- | ------------------------------ |
+| autorun=(true, false) | true | run automatically on page load |
+| lang=... | none | Loads the language handler for the given language which is usually the file extension for source files for that language. See the [index of language handlers](../src). If specified multiple times (`?lang=css&lang=ml`) then all are loaded. |
+| skin=... | none | See the [skin gallery](https://raw.githack.com/google/code-prettify/master/styles/index.html). If specified multiple times, the first one to successfully load is used. |
+| callback=js_ident | | `window.exports["js_ident"]` will be called when prettyprinting finishes. If specified multiple times, all are called. |
-For example
+For example:
```HTML
-
+
```
-specifies the `lang` parameter to also load the CSS language extension
-and the `skin` parameter to load the
-[*sunburst*](https://cdn.rawgit.com/google/code-prettify/master/styles/index.html#sunburst) skin.
+The above specifies the `lang` parameter to also load the CSS language
+extension and the `skin` parameter to load the
+[*sunburst*](https://raw.githack.com/google/code-prettify/master/styles/index.html#sunburst)
+skin.
## Serving your own JS & CSS
You can
-[download](https://raw.githubusercontent.com/google/code-prettify/master/distrib/prettify-small.tgz)
-the scripts and styles and serve them yourself. Make sure to include
-both the script and a stylesheet:
+[download](https://github.com/google/code-prettify/raw/master/distrib/prettify-small.zip)
+the scripts and styles and serve them yourself. Make sure to include both the
+script and a stylesheet:
```HTML
-
+
```
-and then run the `prettyPrint` function once your page has finished
-loading. One way to do this is via the `onload` handler thus:
+Then run the `PR.prettyPrint()` function once your page has finished loading.
+One way to do this is via the `onload` handler thus:
```HTML
-
+
```
## Styling
-The prettifier only adds `class`es; it does not specify exact colors
-or fonts, so you can swap in a different stylesheet to change the way
-code is prettified.
+The prettifier only adds `class`es; it does not specify exact colors or fonts,
+so you can swap in a different stylesheet to change the way code is
+prettified.
-The easiest way to create your own stylesheet is by starting with one
-from the
-[style gallery](https://cdn.rawgit.com/google/code-prettify/master/styles/index.html)
+The easiest way to create your own stylesheet is by starting with one from the
+[style gallery](https://raw.githack.com/google/code-prettify/master/styles/index.html)
and tweaking it.
-You can use CSS `@media` rules to specify styles that work well with
-printers (for example, dark text on a white background) when someone
-tries to print it.
+You can use CSS `@media` rules to specify styles that work well with printers
+(for example, dark text on a white background) when someone tries to print it.
## Language Hints
-Prettify makes a best effort to guess the language but works best with
-C-like and HTML-like languages. For others, there are special
-language handlers that are chosen based on language hints.
+Prettify makes a best effort to guess the language but works best with C-like
+and HTML-like languages. For others, there are special language handlers that
+are chosen based on language hints.
+
+For example, set the `lang-scm` hint to specify that the code is Scheme code:
```HTML
(friends 'of '(parentheses))
```
-uses the `lang-scm` hint to specify that the code is Scheme code.
+It can also be specified as:
```HTML
(friends 'of '(parentheses))
```
-also works.
-
## Line Numbering
-The `linenums` class in
-
```HTML
Many
@@ -133,17 +123,16 @@ code
```
-tells the prettyprinter to insert an `` element and `
`
-elements around each line so that you get line numbers.
+The `linenums` class in the above code tells the prettyprinter to insert an
+`` element and `
` elements around each line so that you get line
+numbers.
Most stylesheets then hide the line numbers except for every fifth line.
-The class `linenums:40` makes line numbering start at line 40 if
-you're excerpting a larger chunk of code, and
+The class `linenums:40` makes line numbering start at line 40 if you're
+excerpting a larger chunk of code. The following also works:
```HTML
The line numbers to the left appear because the preceding comment
<?prettify lang=html linenums=true?> turns on
line-numbering and the
-stylesheet
+stylesheet
(see skin=sunburst in the <script src>)
specifies that every fifth line should be numbered.
-
-
-
-
-
- Last modified: Tue Mar 29 16:38:23 PDT 2011
-
diff --git a/js-modules/js_include.pl b/js-modules/js_include.pl
deleted file mode 100644
index 61ee4736..00000000
--- a/js-modules/js_include.pl
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/perl
-
-# Given a JS file looks for lines like
-# include("path/to/file/to/include");
-# and replaces them with the quoted file relative to the js-modules directory.
-# If the included file ends with ".pl" then it is treated as a perl file to
-# execute and the stdout is used as the JS to include.
-
-use strict;
-
-# Closure Compiler @define annotations that need to be pulled out of included
-# files because @defines need to be top-level vars.
-my $global_defs = "";
-
-# Find @defines at the top of a JS file by pulling off comments and looking for
-# comments containing @define followed by a var declaration.
-sub extractGlobalDefs($) {
- my @headerComments;
- my $s = shift;
- while ($s) {
- last unless $s =~ m#^\s*(?://[^\r\n]*|/\*.*?\*/[ \t]*)[\r\n]*#s;
- my $comment = $&;
- $s = $';
- if ($comment =~ /[\@](define|typedef)/
- && $s =~ /^\s*var\s+[^;]+;[ \t]*[\r\n]*/) {
- my $global = "$&";
- $s = $';
- $global =~ s/(var\s*IN_GLOBAL_SCOPE\s*=\s*)true\b/$1false/;
- $global_defs .= "$comment$global";
- } else {
- push(@headerComments, $comment);
- }
- }
- return (join "", @headerComments) . $s;
-}
-
-# readInclude(whiteSpacePrefix, path) returns the JS content at path
-# (with the ".pl" adjustment above) and prepends each line with the
-# whitespace in whiteSpacePrefix to produce a chunk of JS that matches the
-# indentation of the including file.
-# @defines are extracted so that they can all appear globally at the top of
-# the file.
-sub readInclude($$) {
- my $prefix = shift;
- my $name = "js-modules/" . (shift);
- my $in;
- if ($name =~ /\.pl$/) {
- open($in, "perl $name|") or die "$name: $!";
- } else {
- open($in, "<$name") or die "$name: $!";
- }
- my $buf = "";
- while (<$in>) {
- if (m/(\s*)include\("([^"]+)"\);\s*$/) {
- my $inc = extractGlobalDefs(readInclude("$prefix$1", $2));
- $buf .= $inc;
- } else {
- $buf .= "$prefix$_";
- }
- }
- close($in);
- return $buf;
-}
-
-my $target = shift;
-my $inc = readInclude("", $target);
-my $header = "";
-# Put descriptive top level comments above the grouped @defines.
-if ($inc =~ s#^(?://[^\r\n]*|/\*.*?\*/|\s)+##s) {
- $header = $&;
-}
-my $globals = $global_defs;
-# Un-indent @defines.
-$globals =~ s#^[ \t]*##gm;
-$globals .= "\n" unless $globals eq "";
-
-print "$header$globals$inc";
diff --git a/js-modules/node_prettify.js b/js-modules/node_prettify.js
new file mode 100644
index 00000000..7262a48e
--- /dev/null
+++ b/js-modules/node_prettify.js
@@ -0,0 +1,16 @@
+
+var IN_GLOBAL_SCOPE = false;
+
+/* @include prettify.js */
+
+var path = require('path');
+
+module.exports = {
+ prettyPrint: prettyPrint,
+ prettyPrintOne: prettyPrintOne,
+ // include paths for css preprocessor support
+ includePaths: [
+ __dirname,
+ path.resolve(__dirname, '../styles')
+ ]
+};
diff --git a/js-modules/numberLines.js b/js-modules/numberLines.js
index 2701ec25..e7ee3a42 100644
--- a/js-modules/numberLines.js
+++ b/js-modules/numberLines.js
@@ -30,7 +30,7 @@ function numberLines(node, startLineNum, isPreformatted) {
function walk(node) {
var type = node.nodeType;
if (type == 1 && !nocode.test(node.className)) { // Element
- if ('br' === node.nodeName) {
+ if ('br' === node.nodeName.toLowerCase()) {
breakAfter(node);
// Discard the since it is now flush against a .
if (node.parentNode) {
diff --git a/js-modules/numberLines_test.html b/js-modules/numberLines_test.html
deleted file mode 100644
index a074e014..00000000
--- a/js-modules/numberLines_test.html
+++ /dev/null
@@ -1,119 +0,0 @@
-
-
-Number Lines Test
-
-
-
-
-
-
-
-
-
-
-
-
- Last modified: Tue Mar 29 10:41:34 PDT 2011
-
diff --git a/js-modules/regexpPrecederPatterns.js b/js-modules/regexpPrecederPatterns.js
new file mode 100644
index 00000000..65d3de53
--- /dev/null
+++ b/js-modules/regexpPrecederPatterns.js
@@ -0,0 +1,30 @@
+
+// Regex pattern below is automatically generated by regexpPrecederPatterns.pl
+// Do not modify, your changes will be erased.
+
+// CAVEAT: this does not properly handle the case where a regular
+// expression immediately follows another since a regular expression may
+// have flags for case-sensitivity and the like. Having regexp tokens
+// adjacent is not valid in any language I'm aware of, so I'm punting.
+// TODO: maybe style special characters inside a regexp as punctuation.
+
+/**
+ * A set of tokens that can precede a regular expression literal in
+ * javascript
+ * http://web.archive.org/web/20070717142515/http://www.mozilla.org/js/language/js20/rationale/syntax.html
+ * has the full list, but I've removed ones that might be problematic when
+ * seen in languages that don't support regular expression literals.
+ *
+ * Specifically, I've removed any keywords that can't precede a regexp
+ * literal in a syntactically legal javascript program, and I've removed the
+ * "in" keyword since it's not a keyword in many languages, and might be used
+ * as a count of inches.
+ *
+ * The link above does not accurately describe EcmaScript rules since
+ * it fails to distinguish between (a=++/b/i) and (a++/b/i) but it works
+ * very well in practice.
+ *
+ * @private
+ * @const
+ */
+var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<=?|>>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*';
diff --git a/js-modules/regexpPrecederPatterns.pl b/js-modules/regexpPrecederPatterns.pl
index 488dbd68..0f1e1d59 100644
--- a/js-modules/regexpPrecederPatterns.pl
+++ b/js-modules/regexpPrecederPatterns.pl
@@ -1,6 +1,14 @@
use strict;
print "
+// Regex pattern below is automatically generated by regexpPrecederPatterns.pl
+// Do not modify, your changes will be erased.
+
+// CAVEAT: this does not properly handle the case where a regular
+// expression immediately follows another since a regular expression may
+// have flags for case-sensitivity and the like. Having regexp tokens
+// adjacent is not valid in any language I'm aware of, so I'm punting.
+// TODO: maybe style special characters inside a regexp as punctuation.
/**
* A set of tokens that can precede a regular expression literal in
@@ -9,12 +17,12 @@
* has the full list, but I've removed ones that might be problematic when
* seen in languages that don't support regular expression literals.
*
- *
Specifically, I've removed any keywords that can't precede a regexp
+ * Specifically, I've removed any keywords that can't precede a regexp
* literal in a syntactically legal javascript program, and I've removed the
* \"in\" keyword since it's not a keyword in many languages, and might be used
* as a count of inches.
*
- *
The link above does not accurately describe EcmaScript rules since
+ * The link above does not accurately describe EcmaScript rules since
* it fails to distinguish between (a=++/b/i) and (a++/b/i) but it works
* very well in practice.
*
@@ -34,7 +42,7 @@
"->",
"\\/=?", # "/", "/=",
"::?", # ":", "::",
- "<=?", # "<", "<<", "<<=", "<=",
+ "<=?", # "<", "<<", "<<=", "<=",
">>?>?=?", # ">", ">=", ">>", ">>=", ">>>", ">>>=",
",",
";", # ";"
@@ -58,11 +66,3 @@
$pattern .= ")\\\\s*'"; # matches at end, and matches empty string
print "$pattern;\n";
-
-print "
-// CAVEAT: this does not properly handle the case where a regular
-// expression immediately follows another since a regular expression may
-// have flags for case-sensitivity and the like. Having regexp tokens
-// adjacent is not valid in any language I'm aware of, so I'm punting.
-// TODO: maybe style special characters inside a regexp as punctuation.
-";
diff --git a/js-modules/run_prettify.js b/js-modules/run_prettify.js
index 84a34ff9..faae9897 100644
--- a/js-modules/run_prettify.js
+++ b/js-modules/run_prettify.js
@@ -35,7 +35,7 @@
* +------------------+---------------+------------------------------+--------+
* | skin= | skin name | Loads the skin stylesheet | none. |
* | | | named ".css". | |
- * | | | https://cdn.rawgit.com/ | |
+ * | | | https://raw.githack.com/ | |
* | | | google/code-prettify/master/ | |
* | | | styles/index.html | |
* +------------------+---------------+------------------------------+--------+
@@ -48,19 +48,23 @@
* | | | injection. | |
* +------------------+---------------+------------------------------+--------+
*
- * Exmaples
- * .../prettify.js?lang=css&skin=sunburst
+ * Examples
+ * .../run_prettify.js?lang=css&skin=sunburst
* 1. Loads the CSS language handler which can be used to prettify CSS
* stylesheets, HTML
-
-
+
-
-
+
+
+
+<!doctype html>
+<html>
+<head>
+<title>HTML Test</title>
<script type="text/javascript">
// Say hello world until the user starts questioning
// the meaningfulness of their existence.
@@ -51,11 +94,18 @@
}
}
</script>
-<style>
+<style type="text/css">
p { color: pink }
b { color: blue }
u { color: "umber" }
</style>
+</head>
+<body>
+<h1>Hello world!</h1>
+</body>
+</html>