Skip to content

Commit

Permalink
Update to latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Jul 24, 2014
1 parent c572b1e commit 09c2ec4
Show file tree
Hide file tree
Showing 31 changed files with 4,722 additions and 365 deletions.
17 changes: 17 additions & 0 deletions CHANGES.html
Expand Up @@ -151,5 +151,22 @@ <h2>29 March 2011</h2>
vulnerability. If you sanitize and prettify HTML from an
untrusted source, sanitize first.
</ul>
<h2>4 February 2013</h2>
<ul>
<li>Language handlers for Dart, Erlang, Mumps, TCL, R, S., and others</li>
<li>Bug fix: VB REM style comments.</li>
<li>Bug fix: CSS color literals / ID selector confusion.</li>
<li>Bug fix: IE8 line breaks.</li>
</ul>
<h2>24 February 2013</h2>
<ul>
<li>Added a one script autoload&amp;run mechanism and a way to
embed hints in processing instructions/comments.
See <a href="examples/quine.html">example</a>.
</ul>
<h2>4 March 2013</h2>
<ul>
<li>Matlab language handler courtesy Amro&#xb3;</li>
</ul>
</body>
</html>
77 changes: 44 additions & 33 deletions Makefile
@@ -1,52 +1,40 @@
SHELL := /bin/bash

CLOSURE_COMPILER=java -jar closure-compiler/compiler.jar \
CLOSURE_COMPILER=java -jar tools/closure-compiler/compiler.jar \
--warning_level VERBOSE \
--language_in ECMASCRIPT5 \
--compilation_level ADVANCED_OPTIMIZATIONS
--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 yui-compressor/yuicompressor-2.4.4.jar \
YUI_COMPRESSOR=java -jar tools/yui-compressor/yuicompressor-2.4.4.jar \
--charset UTF-8

TAR_ROOT=distrib/google-code-prettify

all: src/prettify.js distrib
all: distrib

clean:
rm -rf distrib.tstamp distrib src/prettify.js
rm -rf distrib.tstamp distrib src/prettify.js src/run_prettify.js

src/prettify.js: js-modules/*.js js-modules/*.pl
@if [ -e $@ ]; then chmod +w $@; fi
@perl -e '\
sub readInclude($$$$) {\
my $$prefix = $$_[0];\
my $$name = "js-modules/" . $$_[1];\
my $$buf = "";\
if ($$name =~ /\.pl$$/) {\
open(IN, "|perl $$name") or die "$$name: $$!";\
} else {\
open(IN, "<$$name") or die "$$name: $$!";\
}\
while (<IN>) {\
$$buf .= "$$prefix$$_";\
}\
return $$buf;\
}' \
-pe 's/^(\s*)include\("([^"]+)"\);/readInclude($$1, $$2)/ge' \
js-modules/prettify.js \
> src/prettify.js \
|| rm src/prettify.js
@if [ -e $@ ]; then chmod -w $@; fi
@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/*.js src/*.css
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 \
Expand All @@ -56,11 +44,21 @@ distrib.tstamp: src/*.js src/*.css
| grep -v total; \
done
@$(CLOSURE_COMPILER) --js src/prettify.js \
--externs closure-compiler/console-externs.js \
--externs closure-compiler/amd-externs.js \
--externs tools/closure-compiler/console-externs.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/console-externs.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 \
Expand All @@ -82,19 +80,32 @@ distrib.tstamp: src/*.js src/*.css
done
@touch distrib.tstamp

lang-aliases : lang-aliases.tstamp
lang-aliases.tstamp : distrib.tstamp
@tools/lang-handler-aliases.sh \
distrib/sources/google-code-prettify/src \
| perl -ne 'system("cp $$1 $$2") if m/^(\S+) (\S+)$$/ && ! -e $$2' \
&& touch lang-aliases.tstamp

%.tgz: %.tar
@gzip -c -9 $^ > $@

%.tar.bz2: %.tar
@bzip2 -9f $^
@bzip2 -k -9f $^

distrib/prettify-small.tar: distrib.tstamp
@pushd distrib >& /dev/null; \
tar cf ../$@ google-code-prettify; \
popd >& /dev/null
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

98 changes: 49 additions & 49 deletions README.html
Expand Up @@ -12,6 +12,7 @@
<style type="text/css">
body { margin-left: .5in }
h1, h2, h3, h4, .footer { margin-left: -.4in; }
a.Extension { display: inline-block; width: 5em; height:2.5em; border: 1px solid black; vertical-align: top; text-align: center }
</style>
</head>

Expand All @@ -22,15 +23,11 @@ <h1>Javascript code prettifier</h1>
<h2>Setup</h2>
<ol>
<li><a href="http://code.google.com/p/google-code-prettify/downloads/list">Download</a> a distribution
<li>Include the script and stylesheets in your document
(you will need to make sure the css and js file are on your server, and
adjust the paths in the <tt>script</tt> and <tt>link</tt> tag)
<li>Include the script tag below in your document
<pre class="prettyprint">
&lt;link href="prettify.css" type="text/css" rel="stylesheet" /&gt;
&lt;script type="text/javascript" src="prettify.js"&gt;&lt;/script&gt;</pre>
<li>Add <code class="prettyprint lang-in.tag">onload="prettyPrint()"</code> to your
document's body tag.
<li>Modify the stylesheet to get the coloring you prefer</li>
&gt;script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js&gt;&lt;/script&gt;</pre>
<li>See <a href="http://code.google.com/p/google-code-prettify/wiki/GettingStarted">Getting Started</a> to configure that URL with options you need.</a>
<li>Look at the <a href="http://google-code-prettify.googlecode.com/svn/trunk/styles/index.html">skin gallery</a> and pick styles that suit you.</li>
</ol>

<h2>Usage</h2>
Expand Down Expand Up @@ -66,47 +63,43 @@ <h2>FAQ</h2>
<h3 id="langs">For which languages does it work?</h3>
<p>The comments in <tt>prettify.js</tt> are authoritative but the lexer
should work on a number of languages including C and friends,
Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles.
Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, Makefiles,
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, or CAML-like languages.</p>

<p>LISPy languages are supported via an extension:
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lisp.js"
><code>lang-lisp.js</code></a>.</p>
<p>And similarly for
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-clj.js"
><code>Clojure</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-css.js"
><code>CSS</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-go.js"
><code>Go</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-hs.js"
><code>Haskell</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lua.js"
><code>Lua</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-ml.js"
><code>OCAML, SML, F#</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-n.js"
><code>Nemerle</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-proto.js"
><code>Protocol Buffers</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-scala.js"
><code>Scala</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-sql.js"
><code>SQL</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-tex.js"
><code>TeX, LaTeX</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-vhdl.js"
><code>VHDL</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-vb.js"
><code>Visual Basic</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-wiki.js"
><code>WikiText</code></a>,
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-xq.js"
><code>XQuery</code></a>, and
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-yaml.js"
><code>YAML</code></a>.
and Ruby, but, because of commenting conventions, but doesn't work on
Smalltalk.</p>

<p>Other languages are supported via extensions:
<div>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-apollo.js">Apollo</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-basic.js">Basic</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-clj.js">Clojure</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-css.js">CSS</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-dart.js">Dart</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-erlang.js">Erlang</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-go.js">Go</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-hs.js">Haskell</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lisp.js">Lisp, Scheme</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-llvm.js">Llvm</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lua.js">Lua</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-matlab.js">Matlab</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-ml.js">MLs:F#, Ocaml,SML</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-mumps.js">Mumps</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-n.js">Nemerle</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-pascal.js">Pascal</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-proto.js">Protocol buffers</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-r.js">R, S</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-rd.js">RD</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-scala.js">Scala</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-sql.js">SQL</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-tcl.js">TCL</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-tex.js">Latek</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-vb.js">Visual Basic</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-vhdl.js">CHDL</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-wiki.js">Wiki</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-xq.js">XQ</a>
<a class="Extension" href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-yaml.js">YAML</a>
</div>

<p>If you'd like to add an extension for your favorite language, please
look at <tt>src/lang-lisp.js</tt> and file an
Expand Down Expand Up @@ -223,11 +216,18 @@ <h3>How can I customize the colors and styles of my code?</h3>
theme gallery</a> for examples.
</p>

<h3>I can't add classes to my code (because it comes from Markdown, etc.)</h3>
<p>
Instead of <code class="prettyprint">&lt;pre class="prettyprint ..."&gt;</code> you can use a
comment or processing instructions that survives processing instructions :
<code>&lt;?prettify ...?&gt;</code> works as explained in
<a href="http://code.google.com/p/google-code-prettify/wiki/GettingStarted">Getting Started</a></p>

<br><br><br>

<div class="footer">
<!-- Created: Tue Oct 3 17:51:56 PDT 2006 -->
<!-- hhmts start -->Last modified: Fri May 27 20:23:23 PDT 2011 <!-- hhmts end -->
<!-- hhmts start -->Last modified: Mon Mar 4 14:16:04 EST 2013 <!-- hhmts end -->
</div>
</body>
</html>
55 changes: 55 additions & 0 deletions examples/quine.html
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Making Quines Prettier</title>
<!-- The defer is not necessary for autoloading, but is necessary for the
script at the bottom to work as a Quine. -->
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<style>.operative { font-weight: bold; border:1px solid yellow }</style>
</head>

<body>
<h1>Making Quines Prettier</h1>

<p>
Below is the content of this page prettified. The <code>&lt;pre&gt;</code>
element is prettified because it has <code>class="prettyprint"</code> and
because the sourced script loads a JavaScript library that styles source
code.
</p>

<p>
The line numbers to the left appear because the preceding comment
<code>&lt;?prettify lang=html linenums=true?&gt;</code> turns on
line-numbering and the
<a href="http://google-code-prettify.googlecode.com/svn/trunk/styles/index.html">stylesheet</a>
(see <code>skin=sunburst</code> in the <code>&lt;script src&gt;</code>)
specifies that every fifth line should be numbered.
</p>

<!-- Language hints can be put in XML application directive style comments. -->
<?prettify lang=html linenums=true?>
<pre class="prettyprint" id="quine" style="border:4px solid #88c"></pre>

<script>//<![CDATA[
(function () {
function html(s) {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

var quineHtml = html(
'<!DOCTYPE html>\n<html>\n'
+ document.documentElement.innerHTML
+ '\n<\/html>\n');

// Highlight the operative parts:
quineHtml = quineHtml.replace(
/&lt;script src[\s\S]*?&gt;&lt;\/script&gt;|&lt;!--\?[\s\S]*?--&gt;|&lt;pre\b[\s\S]*?&lt;\/pre&gt;/g,
'<span class="operative">$&</span>');

document.getElementById("quine").innerHTML = quineHtml;
})();
//]]>
</script></body>
</html>
52 changes: 25 additions & 27 deletions js-modules/extractSourceSpans.js
Expand Up @@ -52,34 +52,32 @@ function extractSourceSpans(node, isPreformatted) {
var k = 0;

function walk(node) {
switch (node.nodeType) {
case 1: // Element
if (nocode.test(node.className)) { return; }
for (var child = node.firstChild; child; child = child.nextSibling) {
walk(child);
var type = node.nodeType;
if (type == 1) { // Element
if (nocode.test(node.className)) { return; }
for (var child = node.firstChild; child; child = child.nextSibling) {
walk(child);
}
var nodeName = node.nodeName.toLowerCase();
if ('br' === nodeName || 'li' === nodeName) {
chunks[k] = '\n';
spans[k << 1] = length++;
spans[(k++ << 1) | 1] = node;
}
} else if (type == 3 || type == 4) { // Text
var text = node.nodeValue;
if (text.length) {
if (!isPreformatted) {
text = text.replace(/[ \t\r\n]+/g, ' ');
} else {
text = text.replace(/\r\n?/g, '\n'); // Normalize newlines.
}
var nodeName = node.nodeName.toLowerCase();
if ('br' === nodeName || 'li' === nodeName) {
chunks[k] = '\n';
spans[k << 1] = length++;
spans[(k++ << 1) | 1] = node;
}
break;
case 3: case 4: // Text
var text = node.nodeValue;
if (text.length) {
if (!isPreformatted) {
text = text.replace(/[ \t\r\n]+/g, ' ');
} else {
text = text.replace(/\r\n?/g, '\n'); // Normalize newlines.
}
// TODO: handle tabs here?
chunks[k] = text;
spans[k << 1] = length;
length += text.length;
spans[(k++ << 1) | 1] = node;
}
break;
// TODO: handle tabs here?
chunks[k] = text;
spans[k << 1] = length;
length += text.length;
spans[(k++ << 1) | 1] = node;
}
}
}

Expand Down

0 comments on commit 09c2ec4

Please sign in to comment.