Added ada syntax highlighting
This commit is contained in:
parent
792cd682f0
commit
7e830706e7
@ -6,9 +6,12 @@
|
||||
<link type="text/css" rel="stylesheet" href="<?=base_url_make('/css/common.css')?>" />
|
||||
<link type="text/css" rel="stylesheet" href="<?=base_url_make('/css/code.css')?>" />
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/prettify.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-ada.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-basic.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-css.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-lisp.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-lua.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-pascal.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-sql.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-vb.js')?>"></script>
|
||||
|
||||
@ -173,14 +176,18 @@ print anchor ("code/fetch/{$project->id}/${xpar}{$revreq}", $this->lang->line('D
|
||||
|
||||
<?php
|
||||
$fileext = substr(strrchr($file['name'], '.'), 1);
|
||||
if ($fileext == "") $fileext = "html";
|
||||
if ($fileext == 'adb' || $fileext == 'ads') $fileext = 'ada';
|
||||
else if ($fileext == 'pas') $fileext = 'pascal';
|
||||
else if ($fileext == 'bas') $fileext = 'basic';
|
||||
|
||||
if ($fileext != '') $prettyprint_lang = "lang-$fileext";
|
||||
|
||||
$prettyprint_linenums = 'linenums';
|
||||
if ($login['settings'] != NULL &&
|
||||
$login['settings']->code_hide_line_num == 'Y') $prettyprint_linenums = '';
|
||||
?>
|
||||
|
||||
<pre class="prettyprint <?=$prettyprint_linenums?> lang-<?=$fileext?>" id="code_blame_mainarea_result_pre">
|
||||
<pre class="prettyprint <?=$prettyprint_linenums?> <?=$prettyprint_lang?>" id="code_blame_mainarea_result_pre">
|
||||
<?php
|
||||
|
||||
$content = $file['content'];
|
||||
|
@ -6,9 +6,12 @@
|
||||
<link type="text/css" rel="stylesheet" href="<?=base_url_make('/css/common.css')?>" />
|
||||
<link type="text/css" rel="stylesheet" href="<?=base_url_make('/css/code.css')?>" />
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/prettify.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-ada.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-basic.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-css.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-lisp.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-lua.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-pascal.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-sql.js')?>"></script>
|
||||
<script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-vb.js')?>"></script>
|
||||
|
||||
@ -176,14 +179,18 @@ $this->load->view (
|
||||
|
||||
<?php
|
||||
$fileext = substr(strrchr($file['name'], '.'), 1);
|
||||
if ($fileext == '') $fileext = "html";
|
||||
if ($fileext == 'adb' || $fileext == 'ads') $fileext = 'ada';
|
||||
else if ($fileext == 'pas') $fileext = 'pascal';
|
||||
else if ($fileext == 'bas') $fileext = 'basic';
|
||||
|
||||
if ($fileext != '') $prettyprint_lang = "lang-$fileext";
|
||||
|
||||
$prettyprint_linenums = 'linenums';
|
||||
if ($login['settings'] != NULL &&
|
||||
$login['settings']->code_hide_line_num == 'Y') $prettyprint_linenums = '';
|
||||
?>
|
||||
|
||||
<pre class="prettyprint <?=$prettyprint_linenums?> lang-<?=$fileext?>" id="code_file_mainarea_result_pre">
|
||||
<pre class="prettyprint <?=$prettyprint_linenums?> <?=$prettyprint_lang?>" id="code_file_mainarea_result_pre">
|
||||
<?php print htmlspecialchars($file['content']); ?>
|
||||
</pre>
|
||||
|
||||
|
@ -1,15 +1,34 @@
|
||||
wwwdir=$(WWWDIR)/js/prettify
|
||||
www_DATA = \
|
||||
lang-ada.js \
|
||||
lang-apollo.js \
|
||||
lang-basic.js \
|
||||
lang-clj.js \
|
||||
lang-css.js \
|
||||
lang-dart.js \
|
||||
lang-erlang.js \
|
||||
lang-go.js \
|
||||
lang-hs.js \
|
||||
lang-lisp.js \
|
||||
lang-llvm.js \
|
||||
lang-lua.js \
|
||||
lang-matlab.js \
|
||||
lang-ml.js \
|
||||
lang-mumps.js \
|
||||
lang-n.js \
|
||||
lang-pascal.js \
|
||||
lang-proto.js \
|
||||
lang-r.js \
|
||||
lang-rd.js \
|
||||
lang-scala.js \
|
||||
lang-sql.js \
|
||||
lang-tcl.js \
|
||||
lang-tex.js \
|
||||
lang-vb.js \
|
||||
lang-vhdl.js \
|
||||
lang-wiki.js \
|
||||
lang-xq.js \
|
||||
lang-yaml.js \
|
||||
prettify.css \
|
||||
prettify.js
|
||||
|
||||
|
32
codepot/src/js/prettify/lang-basic.js
Normal file
32
codepot/src/js/prettify/lang-basic.js
Normal file
@ -0,0 +1,32 @@
|
||||
// Contributed by peter dot kofler at code minus cop dot org
|
||||
|
||||
/**
|
||||
* @fileoverview
|
||||
* Registers a language handler for Basic.
|
||||
*
|
||||
* To use, include prettify.js and this file in your HTML page.
|
||||
* Then put your code in an HTML tag like
|
||||
* <pre class="prettyprint lang-basic">(my BASIC code)</pre>
|
||||
*
|
||||
* @author peter dot kofler at code minus cop dot org
|
||||
*/
|
||||
|
||||
PR.registerLangHandler(
|
||||
PR.createSimpleLexer(
|
||||
[ // shortcutStylePatterns
|
||||
// "single-line-string"
|
||||
[PR.PR_STRING, /^(?:"(?:[^\\"\r\n]|\\.)*(?:"|$))/, null, '"'],
|
||||
// Whitespace
|
||||
[PR.PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']
|
||||
],
|
||||
[ // fallthroughStylePatterns
|
||||
// A line comment that starts with REM
|
||||
[PR.PR_COMMENT, /^REM[^\r\n]*/, null],
|
||||
[PR.PR_KEYWORD, /^\b(?:AND|CLOSE|CLR|CMD|CONT|DATA|DEF ?FN|DIM|END|FOR|GET|GOSUB|GOTO|IF|INPUT|LET|LIST|LOAD|NEW|NEXT|NOT|ON|OPEN|OR|POKE|PRINT|READ|RESTORE|RETURN|RUN|SAVE|STEP|STOP|SYS|THEN|TO|VERIFY|WAIT)\b/, null],
|
||||
[PR.PR_PLAIN, /^[A-Z][A-Z0-9]?(?:\$|%)?/i, null],
|
||||
// Literals .0, 0, 0.0 0E13
|
||||
[PR.PR_LITERAL, /^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+\-]?\d+)?/i, null, '0123456789'],
|
||||
[PR.PR_PUNCTUATION, /^.[^\s\w\.$%"]*/, null]
|
||||
// [PR.PR_PUNCTUATION, /^[-,:;!<>=\+^\/\*]+/]
|
||||
]),
|
||||
['basic','cbm']);
|
@ -30,19 +30,95 @@
|
||||
* @author mikesamuel@gmail.com
|
||||
*/
|
||||
|
||||
// This file is a call to a function defined in prettify.js which defines a
|
||||
// lexical scanner for CSS and maps tokens to styles.
|
||||
|
||||
// The call to PR['registerLangHandler'] is quoted so that Closure Compiler
|
||||
// will not rename the call so that this language extensions can be
|
||||
// compiled/minified separately from one another. Other symbols defined in
|
||||
// prettify.js are similarly quoted.
|
||||
|
||||
// The call is structured thus:
|
||||
// PR['registerLangHandler'](
|
||||
// PR['createSimpleLexer'](
|
||||
// shortcutPatterns,
|
||||
// fallThroughPatterns),
|
||||
// [languageId0, ..., languageIdN])
|
||||
|
||||
// Langugage IDs
|
||||
// =============
|
||||
// The language IDs are typically the file extensions of source files for
|
||||
// that language so that users can syntax highlight arbitrary files based
|
||||
// on just the extension. This is heuristic, but works pretty well in
|
||||
// practice.
|
||||
|
||||
// Patterns
|
||||
// ========
|
||||
// Lexers are typically implemented as a set of regular expressions.
|
||||
// The SimpleLexer function takes regular expressions, styles, and some
|
||||
// pragma-info and produces a lexer. A token description looks like
|
||||
// [STYLE_NAME, /regular-expression/, pragmas]
|
||||
|
||||
// Initially, simple lexer's inner loop looked like:
|
||||
|
||||
// while sourceCode is not empty:
|
||||
// try each regular expression in order until one matches
|
||||
// remove the matched portion from sourceCode
|
||||
|
||||
// This was really slow for large files because some JS interpreters
|
||||
// do a buffer copy on the matched portion which is O(n*n)
|
||||
|
||||
// The current loop now looks like
|
||||
|
||||
// 1. use js-modules/combinePrefixPatterns.js to
|
||||
// combine all regular expressions into one
|
||||
// 2. use a single global regular expresion match to extract all tokens
|
||||
// 3. for each token try regular expressions in order until one matches it
|
||||
// and classify it using the associated style
|
||||
|
||||
// This is a lot more efficient but it does mean that lookahead and lookbehind
|
||||
// can't be used across boundaries to classify tokens.
|
||||
|
||||
// Sometimes we need lookahead and lookbehind and sometimes we want to handle
|
||||
// embedded language -- JavaScript or CSS embedded in HTML, or inline assembly
|
||||
// in C.
|
||||
|
||||
// If a particular pattern has a numbered group, and its style pattern starts
|
||||
// with "lang-" as in
|
||||
// ['lang-js', /<script>(.*?)<\/script>/]
|
||||
// then the token classification step breaks the token into pieces.
|
||||
// Group 1 is re-parsed using the language handler for "lang-js", and the
|
||||
// surrounding portions are reclassified using the current language handler.
|
||||
// This mechanism gives us both lookahead, lookbehind, and language embedding.
|
||||
|
||||
// Shortcut Patterns
|
||||
// =================
|
||||
// A shortcut pattern is one that is tried before other patterns if the first
|
||||
// character in the token is in the string of characters.
|
||||
// This very effectively lets us make quick correct decisions for common token
|
||||
// types.
|
||||
|
||||
// All other patterns are fall-through patterns.
|
||||
|
||||
|
||||
|
||||
// The comments inline below refer to productions in the CSS specification's
|
||||
// lexical grammar. See link above.
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
// Shortcut patterns.
|
||||
[
|
||||
// The space production <s>
|
||||
[PR['PR_PLAIN'], /^[ \t\r\n\f]+/, null, ' \t\r\n\f']
|
||||
],
|
||||
// Fall-through patterns.
|
||||
[
|
||||
// Quoted strings. <string1> and <string2>
|
||||
[PR['PR_STRING'],
|
||||
/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/, null],
|
||||
[PR['PR_STRING'],
|
||||
/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/, null],
|
||||
['lang-css-str', /^url\(([^\)\"\']*)\)/i],
|
||||
['lang-css-str', /^url\(([^\)\"\']+)\)/i],
|
||||
[PR['PR_KEYWORD'],
|
||||
/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,
|
||||
null],
|
||||
@ -55,7 +131,7 @@ PR['registerLangHandler'](
|
||||
// A number possibly containing a suffix.
|
||||
[PR['PR_LITERAL'], /^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],
|
||||
// A hex color
|
||||
[PR['PR_LITERAL'], /^#(?:[0-9a-f]{3}){1,2}/i],
|
||||
[PR['PR_LITERAL'], /^#(?:[0-9a-f]{3}){1,2}\b/i],
|
||||
// An identifier
|
||||
[PR['PR_PLAIN'],
|
||||
/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],
|
||||
@ -63,6 +139,8 @@ PR['registerLangHandler'](
|
||||
[PR['PR_PUNCTUATION'], /^[^\s\w\'\"]+/]
|
||||
]),
|
||||
['css']);
|
||||
// Above we use embedded languages to highlight property names (identifiers
|
||||
// followed by a colon) differently from identifiers in values.
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer']([],
|
||||
[
|
||||
@ -70,6 +148,9 @@ PR['registerLangHandler'](
|
||||
/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]
|
||||
]),
|
||||
['css-kw']);
|
||||
// The content of an unquoted URL literal like url(http://foo/img.png) should
|
||||
// be colored as string content. This language handler is used above in the
|
||||
// URL production to do so.
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer']([],
|
||||
[
|
||||
|
88
codepot/src/js/prettify/lang-dart.js
Normal file
88
codepot/src/js/prettify/lang-dart.js
Normal file
@ -0,0 +1,88 @@
|
||||
// Copyright (C) 2013 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
|
||||
* Registers a language handler Dart.
|
||||
* Loosely structured based on the DartLexer in Pygments: http://pygments.org/.
|
||||
*
|
||||
* To use, include prettify.js and this file in your HTML page.
|
||||
* Then put your code in an HTML tag like
|
||||
* <pre class="prettyprint lang-dart">(Dart code)</pre>
|
||||
*
|
||||
* @author armstrong.timothy@gmail.com
|
||||
*/
|
||||
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
[
|
||||
// Whitespace.
|
||||
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0']
|
||||
],
|
||||
[
|
||||
// Script tag.
|
||||
[PR['PR_COMMENT'], /^#!(?:.*)/],
|
||||
|
||||
// `import`, `library`, `part of`, `part`, `as`, `show`, and `hide`
|
||||
// keywords.
|
||||
[PR['PR_KEYWORD'], /^\b(?:import|library|part of|part|as|show|hide)\b/i],
|
||||
|
||||
// Single-line comments.
|
||||
[PR['PR_COMMENT'], /^\/\/(?:.*)/],
|
||||
|
||||
// Multiline comments.
|
||||
[PR['PR_COMMENT'], /^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//], // */
|
||||
|
||||
// `class` and `interface` keywords.
|
||||
[PR['PR_KEYWORD'], /^\b(?:class|interface)\b/i],
|
||||
|
||||
// General keywords.
|
||||
[PR['PR_KEYWORD'], /^\b(?:assert|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|this|throw|try|while)\b/i],
|
||||
|
||||
// Declaration keywords.
|
||||
[PR['PR_KEYWORD'], /^\b(?:abstract|const|extends|factory|final|get|implements|native|operator|set|static|typedef|var)\b/i],
|
||||
|
||||
// Keywords for types.
|
||||
[PR['PR_TYPE'], /^\b(?:bool|double|Dynamic|int|num|Object|String|void)\b/i],
|
||||
|
||||
// Keywords for constants.
|
||||
[PR['PR_KEYWORD'], /^\b(?:false|null|true)\b/i],
|
||||
|
||||
// Multiline strings, single- and double-quoted.
|
||||
[PR['PR_STRING'], /^r?[\']{3}[\s|\S]*?[^\\][\']{3}/],
|
||||
[PR['PR_STRING'], /^r?[\"]{3}[\s|\S]*?[^\\][\"]{3}/],
|
||||
|
||||
// Normal and raw strings, single- and double-quoted.
|
||||
[PR['PR_STRING'], /^r?\'(\'|(?:[^\n\r\f])*?[^\\]\')/],
|
||||
[PR['PR_STRING'], /^r?\"(\"|(?:[^\n\r\f])*?[^\\]\")/],
|
||||
|
||||
// Identifiers.
|
||||
[PR['PR_PLAIN'], /^[a-z_$][a-z0-9_]*/i],
|
||||
|
||||
// Operators.
|
||||
[PR['PR_PUNCTUATION'], /^[~!%^&*+=|?:<>/-]/],
|
||||
|
||||
// Hex numbers.
|
||||
[PR['PR_LITERAL'], /^\b0x[0-9a-f]+/i],
|
||||
|
||||
// Decimal numbers.
|
||||
[PR['PR_LITERAL'], /^\b\d+(?:\.\d*)?(?:e[+-]?\d+)?/i],
|
||||
[PR['PR_LITERAL'], /^\b\.\d+(?:e[+-]?\d+)?/i],
|
||||
|
||||
// Punctuation.
|
||||
[PR['PR_PUNCTUATION'], /^[(){}\[\],.;]/]
|
||||
]),
|
||||
['dart']);
|
92
codepot/src/js/prettify/lang-erlang.js
Normal file
92
codepot/src/js/prettify/lang-erlang.js
Normal file
@ -0,0 +1,92 @@
|
||||
// Copyright (C) 2013 Andrew Allen
|
||||
//
|
||||
// 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
|
||||
* Registers a language handler for Erlang.
|
||||
*
|
||||
* Derived from https://raw.github.com/erlang/otp/dev/lib/compiler/src/core_parse.yrl
|
||||
* Modified from Mike Samuel's Haskell plugin for google-code-prettify
|
||||
*
|
||||
* @author achew22@gmail.com
|
||||
*/
|
||||
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
[
|
||||
// Whitespace
|
||||
// whitechar -> newline | vertab | space | tab | uniWhite
|
||||
// newline -> return linefeed | return | linefeed | formfeed
|
||||
[PR['PR_PLAIN'], /^[\t\n\x0B\x0C\r ]+/, null, '\t\n\x0B\x0C\r '],
|
||||
// Single line double-quoted strings.
|
||||
[PR['PR_STRING'], /^\"(?:[^\"\\\n\x0C\r]|\\[\s\S])*(?:\"|$)/,
|
||||
null, '"'],
|
||||
|
||||
// Handle atoms
|
||||
[PR['PR_LITERAL'], /^[a-z][a-zA-Z0-9_]*/],
|
||||
// Handle single quoted atoms
|
||||
[PR['PR_LITERAL'], /^\'(?:[^\'\\\n\x0C\r]|\\[^&])+\'?/,
|
||||
null, "'"],
|
||||
|
||||
// Handle macros. Just to be extra clear on this one, it detects the ?
|
||||
// then uses the regexp to end it so be very careful about matching
|
||||
// all the terminal elements
|
||||
[PR['PR_LITERAL'], /^\?[^ \t\n({]+/, null, "?"],
|
||||
|
||||
|
||||
|
||||
// decimal -> digit{digit}
|
||||
// octal -> octit{octit}
|
||||
// hexadecimal -> hexit{hexit}
|
||||
// integer -> decimal
|
||||
// | 0o octal | 0O octal
|
||||
// | 0x hexadecimal | 0X hexadecimal
|
||||
// float -> decimal . decimal [exponent]
|
||||
// | decimal exponent
|
||||
// exponent -> (e | E) [+ | -] decimal
|
||||
[PR['PR_LITERAL'],
|
||||
/^(?:0o[0-7]+|0x[\da-f]+|\d+(?:\.\d+)?(?:e[+\-]?\d+)?)/i,
|
||||
null, '0123456789']
|
||||
],
|
||||
[
|
||||
// TODO: catch @declarations inside comments
|
||||
|
||||
// Comments in erlang are started with % and go till a newline
|
||||
[PR['PR_COMMENT'], /^%[^\n]*/],
|
||||
|
||||
// Catch macros
|
||||
//[PR['PR_TAG'], /?[^( \n)]+/],
|
||||
|
||||
/**
|
||||
* %% Keywords (atoms are assumed to always be single-quoted).
|
||||
* 'module' 'attributes' 'do' 'let' 'in' 'letrec'
|
||||
* 'apply' 'call' 'primop'
|
||||
* 'case' 'of' 'end' 'when' 'fun' 'try' 'catch' 'receive' 'after'
|
||||
*/
|
||||
[PR['PR_KEYWORD'], /^(?:module|attributes|do|let|in|letrec|apply|call|primop|case|of|end|when|fun|try|catch|receive|after|char|integer|float,atom,string,var)\b/],
|
||||
|
||||
/**
|
||||
* Catch definitions (usually defined at the top of the file)
|
||||
* Anything that starts -something
|
||||
*/
|
||||
[PR['PR_KEYWORD'], /^-[a-z_]+/],
|
||||
|
||||
// Catch variables
|
||||
[PR['PR_TYPE'], /^[A-Z_][a-zA-Z0-9_]*/],
|
||||
|
||||
// matches the symbol production
|
||||
[PR['PR_PUNCTUATION'], /^[.,;]/]
|
||||
]),
|
||||
['erlang', 'erl']);
|
@ -28,6 +28,7 @@
|
||||
* lang-el - Emacs Lisp
|
||||
* lang-lisp - Lisp
|
||||
* lang-scm - Scheme
|
||||
* lang-lsp - FAT 8.3 filename version of lang-lisp.
|
||||
*
|
||||
*
|
||||
* I used http://www.devincook.com/goldparser/doc/meta-language/grammar-LISP.htm
|
||||
@ -90,4 +91,4 @@ PR['registerLangHandler'](
|
||||
// A printable non-space non-special character
|
||||
[PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0()\"\\\';]+/]
|
||||
]),
|
||||
['cl', 'el', 'lisp', 'scm']);
|
||||
['cl', 'el', 'lisp', 'lsp', 'scm', 'ss', 'rkt']);
|
||||
|
61
codepot/src/js/prettify/lang-llvm.js
Normal file
61
codepot/src/js/prettify/lang-llvm.js
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2013 Nikhil Dabas
|
||||
//
|
||||
// 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
|
||||
* Registers a language handler for LLVM.
|
||||
* From https://gist.github.com/ndabas/2850418
|
||||
*
|
||||
*
|
||||
* To use, include prettify.js and this file in your HTML page.
|
||||
* Then put your code in an HTML tag like
|
||||
* <pre class="prettyprint lang-llvm">(my LLVM code)</pre>
|
||||
*
|
||||
*
|
||||
* The regular expressions were adapted from:
|
||||
* https://github.com/hansstimer/llvm.tmbundle/blob/76fedd8f50fd6108b1780c51d79fbe3223de5f34/Syntaxes/LLVM.tmLanguage
|
||||
*
|
||||
* http://llvm.org/docs/LangRef.html#constants describes the language grammar.
|
||||
*
|
||||
* @author Nikhil Dabas
|
||||
*/
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
[
|
||||
// Whitespace
|
||||
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
|
||||
// A double quoted, possibly multi-line, string.
|
||||
[PR['PR_STRING'], /^!?\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"'],
|
||||
// comment.llvm
|
||||
[PR['PR_COMMENT'], /^;[^\r\n]*/, null, ';']
|
||||
],
|
||||
[
|
||||
// variable.llvm
|
||||
[PR['PR_PLAIN'], /^[%@!](?:[-a-zA-Z$._][-a-zA-Z$._0-9]*|\d+)/],
|
||||
|
||||
// According to http://llvm.org/docs/LangRef.html#well-formedness
|
||||
// These reserved words cannot conflict with variable names, because none of them start with a prefix character ('%' or '@').
|
||||
[PR['PR_KEYWORD'], /^[A-Za-z_][0-9A-Za-z_]*/, null],
|
||||
|
||||
// constant.numeric.float.llvm
|
||||
[PR['PR_LITERAL'], /^\d+\.\d+/],
|
||||
|
||||
// constant.numeric.integer.llvm
|
||||
[PR['PR_LITERAL'], /^(?:\d+|0[xX][a-fA-F0-9]+)/],
|
||||
|
||||
// punctuation
|
||||
[PR['PR_PUNCTUATION'], /^[()\[\]{},=*<>:]|\.\.\.$/]
|
||||
]),
|
||||
['llvm', 'll']);
|
180
codepot/src/js/prettify/lang-matlab.js
Normal file
180
codepot/src/js/prettify/lang-matlab.js
Normal file
File diff suppressed because one or more lines are too long
139
codepot/src/js/prettify/lang-mumps.js
Normal file
139
codepot/src/js/prettify/lang-mumps.js
Normal file
@ -0,0 +1,139 @@
|
||||
// Copyright (C) 2011 Kitware 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
|
||||
* Registers a language handler for MUMPS.
|
||||
*
|
||||
*
|
||||
* To use, include prettify.js and this file in your HTML page.
|
||||
* Then put your code in an HTML tag like
|
||||
* <pre class="prettyprint lang-mumps">(my SQL code)</pre>
|
||||
*
|
||||
* Commands, intrinsic functions and variables taken from ISO/IEC 11756:1999(E)
|
||||
*
|
||||
* @author chris.harris@kitware.com
|
||||
*
|
||||
* Known issues:
|
||||
*
|
||||
* - Currently can't distinguish between keywords and local or global variables having the same name
|
||||
* for exampe SET IF="IF?"
|
||||
* - m file are already used for MatLab hence using mumps.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
|
||||
var commands = 'B|BREAK|' +
|
||||
'C|CLOSE|' +
|
||||
'D|DO|' +
|
||||
'E|ELSE|' +
|
||||
'F|FOR|' +
|
||||
'G|GOTO|' +
|
||||
'H|HALT|' +
|
||||
'H|HANG|' +
|
||||
'I|IF|' +
|
||||
'J|JOB|' +
|
||||
'K|KILL|' +
|
||||
'L|LOCK|' +
|
||||
'M|MERGE|' +
|
||||
'N|NEW|' +
|
||||
'O|OPEN|' +
|
||||
'Q|QUIT|' +
|
||||
'R|READ|' +
|
||||
'S|SET|' +
|
||||
'TC|TCOMMIT|' +
|
||||
'TRE|TRESTART|' +
|
||||
'TRO|TROLLBACK|' +
|
||||
'TS|TSTART|' +
|
||||
'U|USE|' +
|
||||
'V|VIEW|' +
|
||||
'W|WRITE|' +
|
||||
'X|XECUTE';
|
||||
|
||||
var intrinsicVariables = 'D|DEVICE|' +
|
||||
'EC|ECODE|' +
|
||||
'ES|ESTACK|' +
|
||||
'ET|ETRAP|' +
|
||||
'H|HOROLOG|' +
|
||||
'I|IO|' +
|
||||
'J|JOB|' +
|
||||
'K|KEY|' +
|
||||
'P|PRINCIPAL|' +
|
||||
'Q|QUIT|' +
|
||||
'ST|STACK|' +
|
||||
'S|STORAGE|' +
|
||||
'SY|SYSTEM|' +
|
||||
'T|TEST|' +
|
||||
'TL|TLEVEL|' +
|
||||
'TR|TRESTART|' +
|
||||
'X|' +
|
||||
'Y|' +
|
||||
'Z[A-Z]*|';
|
||||
|
||||
var intrinsicFunctions = 'A|ASCII|' +
|
||||
'C|CHAR|' +
|
||||
'D|DATA|' +
|
||||
'E|EXTRACT|' +
|
||||
'F|FIND|' +
|
||||
'FN|FNUMBER|' +
|
||||
'G|GET|' +
|
||||
'J|JUSTIFY|' +
|
||||
'L|LENGTH|' +
|
||||
'NA|NAME|' +
|
||||
'O|ORDER|' +
|
||||
'P|PIECE|' +
|
||||
'QL|QLENGTH|' +
|
||||
'QS|QSUBSCRIPT|' +
|
||||
'Q|QUERY|' +
|
||||
'R|RANDOM|' +
|
||||
'RE|REVERSE|' +
|
||||
'S|SELECT|' +
|
||||
'ST|STACK|' +
|
||||
'T|TEXT|' +
|
||||
'TR|TRANSLATE|' +
|
||||
'V|VIEW|' *
|
||||
'Z[A-Z]*|';
|
||||
|
||||
var intrinsic = intrinsicVariables + intrinsicFunctions;
|
||||
|
||||
|
||||
var shortcutStylePatterns = [
|
||||
// Whitespace
|
||||
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
|
||||
// A double or single quoted, possibly multi-line, string.
|
||||
[PR['PR_STRING'], /^(?:"(?:[^"]|\\.)*")/, null, '"']
|
||||
];
|
||||
|
||||
var fallthroughStylePatterns = [
|
||||
// A line comment that starts with ;
|
||||
[PR['PR_COMMENT'], /^;[^\r\n]*/, null, ';'],
|
||||
// Add intrinsic variables and functions as declarations, there not really but it mean
|
||||
// they will hilighted differently from commands.
|
||||
[PR['PR_DECLARATION'], new RegExp('^(?:\\$(?:' + intrinsic + '))\\b', 'i'), null],
|
||||
// Add commands as keywords
|
||||
[PR['PR_KEYWORD'], new RegExp('^(?:[^\\$]' + commands + ')\\b', 'i'), null],
|
||||
// A number is a decimal real literal or in scientific notation.
|
||||
[PR['PR_LITERAL'],
|
||||
/^[+-]?(?:(?:\.\d+|\d+(?:\.\d*)?)(?:E[+\-]?\d+)?)/i],
|
||||
// An identifier
|
||||
[PR['PR_PLAIN'], /^[a-z][a-zA-Z0-9]*/i],
|
||||
// Exclude $ % and ^
|
||||
[PR['PR_PUNCTUATION'], /^[^\w\t\n\r\xA0\"\$;%\^]|_/]
|
||||
];
|
||||
// Can't use m as its already used for MatLab
|
||||
PR.registerLangHandler(PR.createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns), ['mumps']);
|
||||
})();
|
@ -20,6 +20,7 @@
|
||||
* @author Zimin A.V.
|
||||
*/
|
||||
(function () {
|
||||
// http://nemerle.org/wiki/index.php?title=Base_keywords
|
||||
var keywords = 'abstract|and|as|base|catch|class|def|delegate|enum|event|extern|false|finally|'
|
||||
+ 'fun|implements|interface|internal|is|macro|match|matches|module|mutable|namespace|new|'
|
||||
+ 'null|out|override|params|partial|private|protected|public|ref|sealed|static|struct|'
|
||||
@ -27,24 +28,26 @@
|
||||
+ 'assert|assert2|async|break|checked|continue|do|else|ensures|for|foreach|if|late|lock|new|nolate|'
|
||||
+ 'otherwise|regexp|repeat|requires|return|surroundwith|unchecked|unless|using|while|yield';
|
||||
|
||||
var shortcutStylePatterns = [
|
||||
[PR.PR_STRING, /^(?:\'(?:[^\\\'\r\n]|\\.)*\'|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/, null, '"'],
|
||||
[PR.PR_COMMENT, /^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/, null, '#'],
|
||||
[PR.PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']
|
||||
];
|
||||
|
||||
var fallthroughStylePatterns = [
|
||||
[PR.PR_STRING, /^@\"(?:[^\"]|\"\")*(?:\"|$)/, null],
|
||||
[PR.PR_STRING, /^<#(?:[^#>])*(?:#>|$)/, null],
|
||||
[PR.PR_STRING, /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/, null],
|
||||
[PR.PR_COMMENT, /^\/\/[^\r\n]*/, null],
|
||||
[PR.PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null],
|
||||
[PR.PR_KEYWORD, new RegExp('^(?:' + keywords + ')\\b'), null],
|
||||
[PR.PR_TYPE, /^(?:array|bool|byte|char|decimal|double|float|int|list|long|object|sbyte|short|string|ulong|uint|ufloat|ulong|ushort|void)\b/, null],
|
||||
[PR.PR_LITERAL, /^@[a-z_$][a-z_$@0-9]*/i, null],
|
||||
[PR.PR_TYPE, /^@[A-Z]+[a-z][A-Za-z_$@0-9]*/, null],
|
||||
[PR.PR_PLAIN, /^'?[A-Za-z_$][a-z_$@0-9]*/i, null],
|
||||
[PR.PR_LITERAL, new RegExp(
|
||||
PR['registerLangHandler'](PR['createSimpleLexer'](
|
||||
// shortcutStylePatterns
|
||||
[
|
||||
[PR['PR_STRING'], /^(?:\'(?:[^\\\'\r\n]|\\.)*\'|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/, null, '"'],
|
||||
[PR['PR_COMMENT'], /^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/, null, '#'],
|
||||
[PR['PR_PLAIN'], /^\s+/, null, ' \r\n\t\xA0']
|
||||
],
|
||||
// fallthroughStylePatterns
|
||||
[
|
||||
[PR['PR_STRING'], /^@\"(?:[^\"]|\"\")*(?:\"|$)/, null],
|
||||
[PR['PR_STRING'], /^<#(?:[^#>])*(?:#>|$)/, null],
|
||||
[PR['PR_STRING'], /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/, null],
|
||||
[PR['PR_COMMENT'], /^\/\/[^\r\n]*/, null],
|
||||
[PR['PR_COMMENT'], /^\/\*[\s\S]*?(?:\*\/|$)/, null],
|
||||
[PR['PR_KEYWORD'], new RegExp('^(?:' + keywords + ')\\b'), null],
|
||||
[PR['PR_TYPE'], /^(?:array|bool|byte|char|decimal|double|float|int|list|long|object|sbyte|short|string|ulong|uint|ufloat|ulong|ushort|void)\b/, null],
|
||||
[PR['PR_LITERAL'], /^@[a-z_$][a-z_$@0-9]*/i, null],
|
||||
[PR['PR_TYPE'], /^@[A-Z]+[a-z][A-Za-z_$@0-9]*/, null],
|
||||
[PR['PR_PLAIN'], /^'?[A-Za-z_$][a-z_$@0-9]*/i, null],
|
||||
[PR['PR_LITERAL'], new RegExp(
|
||||
'^(?:'
|
||||
// A hex number
|
||||
+ '0x[a-f0-9]+'
|
||||
@ -56,7 +59,7 @@
|
||||
// with an optional modifier like UL for unsigned long
|
||||
+ '[a-z]*', 'i'), null, '0123456789'],
|
||||
|
||||
[PR.PR_PUNCTUATION, /^.[^\s\w\.$@\'\"\`\/\#]*/, null]
|
||||
];
|
||||
PR.registerLangHandler(PR.createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns), ['n', 'nemerle']);
|
||||
[PR['PR_PUNCTUATION'], /^.[^\s\w\.$@\'\"\`\/\#]*/, null]
|
||||
]),
|
||||
['n', 'nemerle']);
|
||||
})();
|
||||
|
32
codepot/src/js/prettify/lang-pascal.js
Normal file
32
codepot/src/js/prettify/lang-pascal.js
Normal file
@ -0,0 +1,32 @@
|
||||
// Contributed by peter dot kofler at code minus cop dot org
|
||||
|
||||
/**
|
||||
* @fileoverview
|
||||
* Registers a language handler for (Turbo) Pascal.
|
||||
*
|
||||
* To use, include prettify.js and this file in your HTML page.
|
||||
* Then put your code in an HTML tag like
|
||||
* <pre class="prettyprint lang-pascal">(my Pascal code)</pre>
|
||||
*
|
||||
* @author peter dot kofler at code minus cop dot org
|
||||
*/
|
||||
|
||||
PR.registerLangHandler(
|
||||
PR.createSimpleLexer(
|
||||
[ // shortcutStylePatterns
|
||||
// 'single-line-string'
|
||||
[PR.PR_STRING, /^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$))/, null, '\''],
|
||||
// Whitespace
|
||||
[PR.PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']
|
||||
],
|
||||
[ // fallthroughStylePatterns
|
||||
// A cStyleComments comment (* *) or {}
|
||||
[PR.PR_COMMENT, /^\(\*[\s\S]*?(?:\*\)|$)|^\{[\s\S]*?(?:\}|$)/, null],
|
||||
[PR.PR_KEYWORD, /^(?:ABSOLUTE|AND|ARRAY|ASM|ASSEMBLER|BEGIN|CASE|CONST|CONSTRUCTOR|DESTRUCTOR|DIV|DO|DOWNTO|ELSE|END|EXTERNAL|FOR|FORWARD|FUNCTION|GOTO|IF|IMPLEMENTATION|IN|INLINE|INTERFACE|INTERRUPT|LABEL|MOD|NOT|OBJECT|OF|OR|PACKED|PROCEDURE|PROGRAM|RECORD|REPEAT|SET|SHL|SHR|THEN|TO|TYPE|UNIT|UNTIL|USES|VAR|VIRTUAL|WHILE|WITH|XOR)\b/i, null],
|
||||
[PR.PR_LITERAL, /^(?:true|false|self|nil)/i, null],
|
||||
[PR.PR_PLAIN, /^[a-z][a-z0-9]*/i, null],
|
||||
// Literals .0, 0, 0.0 0E13
|
||||
[PR.PR_LITERAL, /^(?:\$[a-f0-9]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+\-]?\d+)?)/i, null, '0123456789'],
|
||||
[PR.PR_PUNCTUATION, /^.[^\s\w\.$@\'\/]*/, null]
|
||||
]),
|
||||
['pascal']);
|
57
codepot/src/js/prettify/lang-r.js
Normal file
57
codepot/src/js/prettify/lang-r.js
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2012 Jeffrey B. Arnold
|
||||
//
|
||||
// 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
|
||||
* Registers a language handler for S, S-plus, and R source code.
|
||||
*
|
||||
*
|
||||
* To use, include prettify.js and this file in your HTML page.
|
||||
* Then put your code in an HTML tag like
|
||||
* <pre class="prettyprint lang-r"> code </pre>
|
||||
*
|
||||
* Language definition from
|
||||
* http://cran.r-project.org/doc/manuals/R-lang.html.
|
||||
* Many of the regexes are shared with the pygments SLexer,
|
||||
* http://pygments.org/.
|
||||
*
|
||||
* Original: https://raw.github.com/jrnold/prettify-lang-r-bugs/master/lang-r.js
|
||||
*
|
||||
* @author jeffrey.arnold@gmail.com
|
||||
*/
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
[
|
||||
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
|
||||
[PR['PR_STRING'], /^\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"'],
|
||||
[PR['PR_STRING'], /^\'(?:[^\'\\]|\\[\s\S])*(?:\'|$)/, null, "'"]
|
||||
],
|
||||
[
|
||||
[PR['PR_COMMENT'], /^#.*/],
|
||||
[PR['PR_KEYWORD'], /^(?:if|else|for|while|repeat|in|next|break|return|switch|function)(?![A-Za-z0-9_.])/],
|
||||
// hex numbes
|
||||
[PR['PR_LITERAL'], /^0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/],
|
||||
// Decimal numbers
|
||||
[PR['PR_LITERAL'], /^[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?/],
|
||||
// builtin symbols
|
||||
[PR['PR_LITERAL'], /^(?:NULL|NA(?:_(?:integer|real|complex|character)_)?|Inf|TRUE|FALSE|NaN|\.\.(?:\.|[0-9]+))(?![A-Za-z0-9_.])/],
|
||||
// assignment, operators, and parens, etc.
|
||||
[PR['PR_PUNCTUATION'], /^(?:<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\*|\+|\^|\/|!|%.*?%|=|~|\$|@|:{1,3}|[\[\](){};,?])/],
|
||||
// valid variable names
|
||||
[PR['PR_PLAIN'], /^(?:[A-Za-z]+[A-Za-z0-9_.]*|\.[a-zA-Z_][0-9a-zA-Z\._]*)(?![A-Za-z0-9_.])/],
|
||||
// string backtick
|
||||
[PR['PR_STRING'], /^`.+`/]
|
||||
]),
|
||||
['r', 's', 'R', 'S', 'Splus']);
|
47
codepot/src/js/prettify/lang-rd.js
Normal file
47
codepot/src/js/prettify/lang-rd.js
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2012 Jeffrey Arnold
|
||||
//
|
||||
// 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
|
||||
* Support for R documentation (Rd) files
|
||||
*
|
||||
* Minimal highlighting or Rd files, basically just highlighting
|
||||
* macros. It does not try to identify verbatim or R-like regions of
|
||||
* macros as that is too complicated for a lexer. Descriptions of the
|
||||
* Rd format can be found
|
||||
* http://cran.r-project.org/doc/manuals/R-exts.html and
|
||||
* http://developer.r-project.org/parseRd.pdf.
|
||||
*
|
||||
* @author Jeffrey Arnold
|
||||
*/
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
[
|
||||
// whitespace
|
||||
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
|
||||
// all comments begin with '%'
|
||||
[PR['PR_COMMENT'], /^%[^\r\n]*/, null, '%']
|
||||
],
|
||||
[// special macros with no args
|
||||
[PR['PR_LITERAL'], /^\\(?:cr|l?dots|R|tab)\b/],
|
||||
// macros
|
||||
[PR['PR_KEYWORD'], /^\\[a-zA-Z@]+/],
|
||||
// highlighted as macros, since technically they are
|
||||
[PR['PR_KEYWORD'], /^#(?:ifn?def|endif)/ ],
|
||||
// catch escaped brackets
|
||||
[PR['PR_PLAIN'], /^\\[{}]/],
|
||||
// punctuation
|
||||
[PR['PR_PUNCTUATION'], /^[{}()\[\]]+/]
|
||||
]),
|
||||
['Rd', 'rd']);
|
@ -25,8 +25,9 @@
|
||||
*
|
||||
*
|
||||
* http://savage.net.au/SQL/sql-99.bnf.html is the basis for the grammar, and
|
||||
* http://msdn.microsoft.com/en-us/library/aa238507(SQL.80).aspx as the basis
|
||||
* for the keyword list.
|
||||
* http://msdn.microsoft.com/en-us/library/aa238507(SQL.80).aspx and
|
||||
* http://meta.stackoverflow.com/q/92352/137403 as the bases for the keyword
|
||||
* list.
|
||||
*
|
||||
* @author mikesamuel@gmail.com
|
||||
*/
|
||||
@ -44,7 +45,7 @@ PR['registerLangHandler'](
|
||||
// A comment is either a line comment that starts with two dashes, or
|
||||
// two dashes preceding a long bracketed block.
|
||||
[PR['PR_COMMENT'], /^(?:--[^\r\n]*|\/\*[\s\S]*?(?:\*\/|$))/],
|
||||
[PR['PR_KEYWORD'], /^(?:ADD|ALL|ALTER|AND|ANY|AS|ASC|AUTHORIZATION|BACKUP|BEGIN|BETWEEN|BREAK|BROWSE|BULK|BY|CASCADE|CASE|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMN|COMMIT|COMPUTE|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATABASE|DBCC|DEALLOCATE|DECLARE|DEFAULT|DELETE|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DROP|DUMMY|DUMP|ELSE|END|ERRLVL|ESCAPE|EXCEPT|EXEC|EXECUTE|EXISTS|EXIT|FETCH|FILE|FILLFACTOR|FOR|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GOTO|GRANT|GROUP|HAVING|HOLDLOCK|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF|IN|INDEX|INNER|INSERT|INTERSECT|INTO|IS|JOIN|KEY|KILL|LEFT|LIKE|LINENO|LOAD|MATCH|MERGE|NATIONAL|NOCHECK|NONCLUSTERED|NOT|NULL|NULLIF|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|OPTION|OR|ORDER|OUTER|OVER|PERCENT|PLAN|PRECISION|PRIMARY|PRINT|PROC|PROCEDURE|PUBLIC|RAISERROR|READ|READTEXT|RECONFIGURE|REFERENCES|REPLICATION|RESTORE|RESTRICT|RETURN|REVOKE|RIGHT|ROLLBACK|ROWCOUNT|ROWGUIDCOL|RULE|SAVE|SCHEMA|SELECT|SESSION_USER|SET|SETUSER|SHUTDOWN|SOME|STATISTICS|SYSTEM_USER|TABLE|TEXTSIZE|THEN|TO|TOP|TRAN|TRANSACTION|TRIGGER|TRUNCATE|TSEQUAL|UNION|UNIQUE|UPDATE|UPDATETEXT|USE|USER|USING|VALUES|VARYING|VIEW|WAITFOR|WHEN|WHERE|WHILE|WITH|WRITETEXT)(?=[^\w-]|$)/i, null],
|
||||
[PR['PR_KEYWORD'], /^(?:ADD|ALL|ALTER|AND|ANY|APPLY|AS|ASC|AUTHORIZATION|BACKUP|BEGIN|BETWEEN|BREAK|BROWSE|BULK|BY|CASCADE|CASE|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMN|COMMIT|COMPUTE|CONNECT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATABASE|DBCC|DEALLOCATE|DECLARE|DEFAULT|DELETE|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DROP|DUMMY|DUMP|ELSE|END|ERRLVL|ESCAPE|EXCEPT|EXEC|EXECUTE|EXISTS|EXIT|FETCH|FILE|FILLFACTOR|FOLLOWING|FOR|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GOTO|GRANT|GROUP|HAVING|HOLDLOCK|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF|IN|INDEX|INNER|INSERT|INTERSECT|INTO|IS|JOIN|KEY|KILL|LEFT|LIKE|LINENO|LOAD|MATCH|MATCHED|MERGE|NATURAL|NATIONAL|NOCHECK|NONCLUSTERED|NOCYCLE|NOT|NULL|NULLIF|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|OPTION|OR|ORDER|OUTER|OVER|PARTITION|PERCENT|PIVOT|PLAN|PRECEDING|PRECISION|PRIMARY|PRINT|PROC|PROCEDURE|PUBLIC|RAISERROR|READ|READTEXT|RECONFIGURE|REFERENCES|REPLICATION|RESTORE|RESTRICT|RETURN|REVOKE|RIGHT|ROLLBACK|ROWCOUNT|ROWGUIDCOL|ROWS?|RULE|SAVE|SCHEMA|SELECT|SESSION_USER|SET|SETUSER|SHUTDOWN|SOME|START|STATISTICS|SYSTEM_USER|TABLE|TEXTSIZE|THEN|TO|TOP|TRAN|TRANSACTION|TRIGGER|TRUNCATE|TSEQUAL|UNBOUNDED|UNION|UNIQUE|UNPIVOT|UPDATE|UPDATETEXT|USE|USER|USING|VALUES|VARYING|VIEW|WAITFOR|WHEN|WHERE|WHILE|WITH|WITHIN|WRITETEXT|XML)(?=[^\w-]|$)/i, null],
|
||||
// A number is a hex integer literal, a decimal real literal, or in
|
||||
// scientific notation.
|
||||
[PR['PR_LITERAL'],
|
||||
|
62
codepot/src/js/prettify/lang-tcl.js
Normal file
62
codepot/src/js/prettify/lang-tcl.js
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2012 Pyrios.
|
||||
//
|
||||
// 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
|
||||
* Registers a language handler for TCL
|
||||
*
|
||||
*
|
||||
* To use, include prettify.js and this file in your HTML page.
|
||||
* Then put your code in an HTML tag like
|
||||
* <pre class="prettyprint lang-tcl">proc foo {} {puts bar}</pre>
|
||||
*
|
||||
* I copy-pasted lang-lisp.js, so this is probably not 100% accurate.
|
||||
* I used http://wiki.tcl.tk/1019 for the keywords, but tried to only
|
||||
* include as keywords that had more impact on the program flow
|
||||
* rather than providing convenience. For example, I included 'if'
|
||||
* since that provides branching, but left off 'open' since that is more
|
||||
* like a proc. Add more if it makes sense.
|
||||
*
|
||||
* @author pyrios@gmail.com
|
||||
*/
|
||||
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
[
|
||||
['opn', /^\{+/, null, '{'],
|
||||
['clo', /^\}+/, null, '}'],
|
||||
// A line comment that starts with ;
|
||||
[PR['PR_COMMENT'], /^#[^\r\n]*/, null, '#'],
|
||||
// Whitespace
|
||||
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
|
||||
// A double quoted, possibly multi-line, string.
|
||||
[PR['PR_STRING'], /^\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"']
|
||||
],
|
||||
[
|
||||
[PR['PR_KEYWORD'], /^(?:after|append|apply|array|break|case|catch|continue|error|eval|exec|exit|expr|for|foreach|if|incr|info|proc|return|set|switch|trace|uplevel|upvar|while)\b/, null],
|
||||
[PR['PR_LITERAL'],
|
||||
/^[+\-]?(?:[0#]x[0-9a-f]+|\d+\/\d+|(?:\.\d+|\d+(?:\.\d*)?)(?:[ed][+\-]?\d+)?)/i],
|
||||
// A single quote possibly followed by a word that optionally ends with
|
||||
// = ! or ?.
|
||||
[PR['PR_LITERAL'],
|
||||
/^\'(?:-*(?:\w|\\[\x21-\x7e])(?:[\w-]*|\\[\x21-\x7e])[=!?]?)?/],
|
||||
// A word that optionally ends with = ! or ?.
|
||||
[PR['PR_PLAIN'],
|
||||
/^-*(?:[a-z_]|\\[\x21-\x7e])(?:[\w-]*|\\[\x21-\x7e])[=!?]?/i],
|
||||
// A printable non-space non-special character
|
||||
[PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0()\"\\\';]+/]
|
||||
]),
|
||||
['tcl']);
|
@ -20,27 +20,27 @@
|
||||
* @author Martin S.
|
||||
*/
|
||||
|
||||
PR.registerLangHandler(
|
||||
PR.createSimpleLexer(
|
||||
PR['registerLangHandler'](
|
||||
PR['createSimpleLexer'](
|
||||
[
|
||||
// whitespace
|
||||
[PR.PR_PLAIN, /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
|
||||
[PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
|
||||
// all comments begin with '%'
|
||||
[PR.PR_COMMENT, /^%[^\r\n]*/, null, '%']
|
||||
[PR['PR_COMMENT'], /^%[^\r\n]*/, null, '%']
|
||||
],
|
||||
[
|
||||
//[PR.PR_DECLARATION, /^\\([egx]?def|(new|renew|provide)(command|environment))\b/],
|
||||
//[PR['PR_DECLARATION'], /^\\([egx]?def|(new|renew|provide)(command|environment))\b/],
|
||||
// any command starting with a \ and contains
|
||||
// either only letters (a-z,A-Z), '@' (internal macros)
|
||||
[PR.PR_KEYWORD, /^\\[a-zA-Z@]+/],
|
||||
[PR['PR_KEYWORD'], /^\\[a-zA-Z@]+/],
|
||||
// or contains only one character
|
||||
[PR.PR_KEYWORD, /^\\./],
|
||||
[PR['PR_KEYWORD'], /^\\./],
|
||||
// Highlight dollar for math mode and ampersam for tabular
|
||||
[PR.PR_TYPE, /^[$&]/],
|
||||
[PR['PR_TYPE'], /^[$&]/],
|
||||
// numeric measurement values with attached units
|
||||
[PR.PR_LITERAL,
|
||||
[PR['PR_LITERAL'],
|
||||
/[+-]?(?:\.\d+|\d+(?:\.\d*)?)(cm|em|ex|in|pc|pt|bp|mm)/i],
|
||||
// punctuation usually occurring within commands
|
||||
[PR.PR_PUNCTUATION, /^[{}()\[\]=]+/]
|
||||
[PR['PR_PUNCTUATION'], /^[{}()\[\]=]+/]
|
||||
]),
|
||||
['latex', 'tex']);
|
||||
|
@ -41,17 +41,22 @@ PR['registerLangHandler'](
|
||||
'"\u201C\u201D'],
|
||||
// A comment starts with a single quote and runs until the end of the
|
||||
// line.
|
||||
[PR['PR_COMMENT'], /^[\'\u2018\u2019][^\r\n\u2028\u2029]*/, null, '\'\u2018\u2019']
|
||||
// VB6 apparently allows _ as an escape sequence for newlines though
|
||||
// this is not a documented feature of VB.net.
|
||||
// http://meta.stackoverflow.com/q/121497/137403
|
||||
[PR['PR_COMMENT'], /^[\'\u2018\u2019](?:_(?:\r\n?|[^\r]?)|[^\r\n_\u2028\u2029])*/, null, '\'\u2018\u2019']
|
||||
],
|
||||
[
|
||||
[PR['PR_KEYWORD'], /^(?:AddHandler|AddressOf|Alias|And|AndAlso|Ansi|As|Assembly|Auto|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|CDbl|CDec|Char|CInt|Class|CLng|CObj|Const|CShort|CSng|CStr|CType|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else|ElseIf|End|EndIf|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get|GetType|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|Let|Lib|Like|Long|Loop|Me|Mod|Module|MustInherit|MustOverride|MyBase|MyClass|Namespace|New|Next|Not|NotInheritable|NotOverridable|Object|On|Option|Optional|Or|OrElse|Overloads|Overridable|Overrides|ParamArray|Preserve|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|Select|Set|Shadows|Shared|Short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TypeOf|Unicode|Until|Variant|Wend|When|While|With|WithEvents|WriteOnly|Xor|EndIf|GoSub|Let|Variant|Wend)\b/i, null],
|
||||
// A second comment form
|
||||
[PR['PR_COMMENT'], /^REM[^\r\n\u2028\u2029]*/i],
|
||||
[PR['PR_COMMENT'], /^REM\b[^\r\n\u2028\u2029]*/i],
|
||||
// A boolean, numeric, or date literal.
|
||||
[PR['PR_LITERAL'],
|
||||
/^(?:True\b|False\b|Nothing\b|\d+(?:E[+\-]?\d+[FRD]?|[FRDSIL])?|(?:&H[0-9A-F]+|&O[0-7]+)[SIL]?|\d*\.\d+(?:E[+\-]?\d+)?[FRD]?|#\s+(?:\d+[\-\/]\d+[\-\/]\d+(?:\s+\d+:\d+(?::\d+)?(\s*(?:AM|PM))?)?|\d+:\d+(?::\d+)?(\s*(?:AM|PM))?)\s+#)/i],
|
||||
// An identifier?
|
||||
[PR['PR_PLAIN'], /^(?:(?:[a-z]|_\w)\w*|\[(?:[a-z]|_\w)\w*\])/i],
|
||||
// An identifier. Keywords can be turned into identifers
|
||||
// with square brackets, and there may be optional type
|
||||
// characters after a normal identifier in square brackets.
|
||||
[PR['PR_PLAIN'], /^(?:(?:[a-z]|_\w)\w*(?:\[[%&@!#]+\])?|\[(?:[a-z]|_\w)\w*\])/i],
|
||||
// A run of punctuation
|
||||
[PR['PR_PUNCTUATION'],
|
||||
/^[^\w\t\n\r \"\'\[\]\xA0\u2018\u2019\u201C\u201D\u2028\u2029]+/],
|
||||
|
@ -53,7 +53,10 @@
|
||||
*/
|
||||
|
||||
// JSLint declarations
|
||||
/*global console, document, navigator, setTimeout, window */
|
||||
/*global console, document, navigator, setTimeout, window, define */
|
||||
|
||||
/** @define {boolean} */
|
||||
var IN_GLOBAL_SCOPE = true;
|
||||
|
||||
/**
|
||||
* Split {@code prettyPrint} into multiple timeouts so as not to interfere with
|
||||
@ -62,33 +65,57 @@
|
||||
*/
|
||||
window['PR_SHOULD_USE_CONTINUATION'] = true;
|
||||
|
||||
/**
|
||||
* Pretty print a chunk of code.
|
||||
* @param {string} sourceCodeHtml The HTML to pretty print.
|
||||
* @param {string} opt_langExtension The language name to use.
|
||||
* Typically, a filename extension like 'cpp' or 'java'.
|
||||
* @param {number|boolean} opt_numberLines True to number lines,
|
||||
* or the 1-indexed number of the first line in sourceCodeHtml.
|
||||
* @return {string} code as html, but prettier
|
||||
*/
|
||||
var prettyPrintOne;
|
||||
/**
|
||||
* Find all the {@code <pre>} and {@code <code>} tags in the DOM with
|
||||
* {@code class=prettyprint} and prettify them.
|
||||
*
|
||||
* @param {Function} opt_whenDone called when prettifying is done.
|
||||
* @param {HTMLElement|HTMLDocument} opt_root an element or document
|
||||
* containing all the elements to pretty print.
|
||||
* Defaults to {@code document.body}.
|
||||
*/
|
||||
var prettyPrint;
|
||||
|
||||
|
||||
(function () {
|
||||
var win = window;
|
||||
// Keyword lists for various languages.
|
||||
// We use things that coerce to strings to make them compact when minified
|
||||
// and to defeat aggressive optimizers that fold large string constants.
|
||||
var FLOW_CONTROL_KEYWORDS = ["break,continue,do,else,for,if,return,while"];
|
||||
var C_KEYWORDS = [FLOW_CONTROL_KEYWORDS,"auto,case,char,const,default," +
|
||||
"double,enum,extern,float,goto,int,long,register,short,signed,sizeof," +
|
||||
"static,struct,switch,typedef,union,unsigned,void,volatile"];
|
||||
"double,enum,extern,float,goto,inline,int,long,register,short,signed," +
|
||||
"sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];
|
||||
var COMMON_KEYWORDS = [C_KEYWORDS,"catch,class,delete,false,import," +
|
||||
"new,operator,private,protected,public,this,throw,true,try,typeof"];
|
||||
var CPP_KEYWORDS = [COMMON_KEYWORDS,"alignof,align_union,asm,axiom,bool," +
|
||||
"concept,concept_map,const_cast,constexpr,decltype," +
|
||||
"dynamic_cast,explicit,export,friend,inline,late_check," +
|
||||
"mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast," +
|
||||
"template,typeid,typename,using,virtual,where"];
|
||||
"concept,concept_map,const_cast,constexpr,decltype,delegate," +
|
||||
"dynamic_cast,explicit,export,friend,generic,late_check," +
|
||||
"mutable,namespace,nullptr,property,reinterpret_cast,static_assert," +
|
||||
"static_cast,template,typeid,typename,using,virtual,where"];
|
||||
var JAVA_KEYWORDS = [COMMON_KEYWORDS,
|
||||
"abstract,boolean,byte,extends,final,finally,implements,import," +
|
||||
"instanceof,null,native,package,strictfp,super,synchronized,throws," +
|
||||
"transient"];
|
||||
"abstract,assert,boolean,byte,extends,final,finally,implements,import," +
|
||||
"instanceof,interface,null,native,package,strictfp,super,synchronized," +
|
||||
"throws,transient"];
|
||||
var CSHARP_KEYWORDS = [JAVA_KEYWORDS,
|
||||
"as,base,by,checked,decimal,delegate,descending,dynamic,event," +
|
||||
"fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock," +
|
||||
"object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed," +
|
||||
"stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];
|
||||
"fixed,foreach,from,group,implicit,in,internal,into,is,let," +
|
||||
"lock,object,out,override,orderby,params,partial,readonly,ref,sbyte," +
|
||||
"sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort," +
|
||||
"var,virtual,where"];
|
||||
var COFFEE_KEYWORDS = "all,and,by,catch,class,else,extends,false,finally," +
|
||||
"for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then," +
|
||||
"true,try,unless,until,when,while,yes";
|
||||
"throw,true,try,unless,until,when,while,yes";
|
||||
var JSCRIPT_KEYWORDS = [COMMON_KEYWORDS,
|
||||
"debugger,eval,export,function,get,null,set,undefined,var,with," +
|
||||
"Infinity,NaN"];
|
||||
@ -103,12 +130,15 @@ window['PR_SHOULD_USE_CONTINUATION'] = true;
|
||||
"def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo," +
|
||||
"rescue,retry,self,super,then,true,undef,unless,until,when,yield," +
|
||||
"BEGIN,END"];
|
||||
var RUST_KEYWORDS = [FLOW_CONTROL_KEYWORDS, "as,assert,const,copy,drop," +
|
||||
"enum,extern,fail,false,fn,impl,let,log,loop,match,mod,move,mut,priv," +
|
||||
"pub,pure,ref,self,static,struct,true,trait,type,unsafe,use"];
|
||||
var SH_KEYWORDS = [FLOW_CONTROL_KEYWORDS, "case,done,elif,esac,eval,fi," +
|
||||
"function,in,local,set,then,until"];
|
||||
var ALL_KEYWORDS = [
|
||||
CPP_KEYWORDS, CSHARP_KEYWORDS, JSCRIPT_KEYWORDS, PERL_KEYWORDS +
|
||||
CPP_KEYWORDS, CSHARP_KEYWORDS, JSCRIPT_KEYWORDS, PERL_KEYWORDS,
|
||||
PYTHON_KEYWORDS, RUBY_KEYWORDS, SH_KEYWORDS];
|
||||
var C_TYPES = /^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;
|
||||
var C_TYPES = /^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)\b/;
|
||||
|
||||
// token style names. correspond to css classes
|
||||
/**
|
||||
@ -142,7 +172,7 @@ window['PR_SHOULD_USE_CONTINUATION'] = true;
|
||||
*/
|
||||
var PR_PUNCTUATION = 'pun';
|
||||
/**
|
||||
* token style for a punctuation string.
|
||||
* token style for plain text.
|
||||
* @const
|
||||
*/
|
||||
var PR_PLAIN = 'pln';
|
||||
@ -182,7 +212,7 @@ window['PR_SHOULD_USE_CONTINUATION'] = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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
|
||||
@ -194,21 +224,20 @@ window['PR_SHOULD_USE_CONTINUATION'] = true;
|
||||
* "in" keyword since it's not a keyword in many languages, and might be used
|
||||
* as a count of inches.
|
||||
*
|
||||
* <p>The link a above does not accurately describe EcmaScript rules since
|
||||
* <p>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*';
|
||||
|
||||
// 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.
|
||||
var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<<?=?|>>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*';
|
||||
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* Given a group of {@link RegExp}s, returns a {@code RegExp} that globally
|
||||
@ -267,10 +296,8 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
return (charCode < 0x10 ? '\\x0' : '\\x') + charCode.toString(16);
|
||||
}
|
||||
var ch = String.fromCharCode(charCode);
|
||||
if (ch === '\\' || ch === '-' || ch === '[' || ch === ']') {
|
||||
ch = '\\' + ch;
|
||||
}
|
||||
return ch;
|
||||
return (ch === '\\' || ch === '-' || ch === ']' || ch === '^')
|
||||
? "\\" + ch : ch;
|
||||
}
|
||||
|
||||
function caseFoldCharset(charSet) {
|
||||
@ -284,13 +311,16 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
+ '|-'
|
||||
+ '|[^-\\\\]',
|
||||
'g'));
|
||||
var groups = [];
|
||||
var ranges = [];
|
||||
var inverse = charsetParts[0] === '^';
|
||||
|
||||
var out = ['['];
|
||||
if (inverse) { out.push('^'); }
|
||||
|
||||
for (var i = inverse ? 1 : 0, n = charsetParts.length; i < n; ++i) {
|
||||
var p = charsetParts[i];
|
||||
if (/\\[bdsw]/i.test(p)) { // Don't muck with named groups.
|
||||
groups.push(p);
|
||||
out.push(p);
|
||||
} else {
|
||||
var start = decodeEscape(p);
|
||||
var end;
|
||||
@ -320,7 +350,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
// -> [[1, 12], [14, 14], [16, 17]]
|
||||
ranges.sort(function (a, b) { return (a[0] - b[0]) || (b[1] - a[1]); });
|
||||
var consolidatedRanges = [];
|
||||
var lastRange = [NaN, NaN];
|
||||
var lastRange = [];
|
||||
for (var i = 0; i < ranges.length; ++i) {
|
||||
var range = ranges[i];
|
||||
if (range[0] <= lastRange[1] + 1) {
|
||||
@ -330,9 +360,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
}
|
||||
}
|
||||
|
||||
var out = ['['];
|
||||
if (inverse) { out.push('^'); }
|
||||
out.push.apply(out, groups);
|
||||
for (var i = 0; i < consolidatedRanges.length; ++i) {
|
||||
var range = consolidatedRanges[i];
|
||||
out.push(encodeEscape(range[0]));
|
||||
@ -358,7 +385,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
+ '|\\\\[0-9]+' // a back-reference or octal escape
|
||||
+ '|\\\\[^ux0-9]' // other escape sequence
|
||||
+ '|\\(\\?[:!=]' // start of a non-capturing group
|
||||
+ '|[\\(\\)\\^]' // start/emd of a group, or line start
|
||||
+ '|[\\(\\)\\^]' // start/end of a group, or line start
|
||||
+ '|[^\\x5B\\x5C\\(\\)\\^]+' // run of other characters
|
||||
+ ')',
|
||||
'g'));
|
||||
@ -378,8 +405,15 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
++groupIndex;
|
||||
} else if ('\\' === p.charAt(0)) {
|
||||
var decimalValue = +p.substring(1);
|
||||
if (decimalValue && decimalValue <= groupIndex) {
|
||||
if (decimalValue) {
|
||||
if (decimalValue <= groupIndex) {
|
||||
capturedGroups[decimalValue] = -1;
|
||||
} else {
|
||||
// Replace with an unambiguous escape sequence so that
|
||||
// an octal escape sequence does not turn into a backreference
|
||||
// to a capturing group from an earlier regex.
|
||||
parts[i] = encodeEscape(decimalValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -395,20 +429,20 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
var p = parts[i];
|
||||
if (p === '(') {
|
||||
++groupIndex;
|
||||
if (capturedGroups[groupIndex] === undefined) {
|
||||
if (!capturedGroups[groupIndex]) {
|
||||
parts[i] = '(?:';
|
||||
}
|
||||
} else if ('\\' === p.charAt(0)) {
|
||||
var decimalValue = +p.substring(1);
|
||||
if (decimalValue && decimalValue <= groupIndex) {
|
||||
parts[i] = '\\' + capturedGroups[groupIndex];
|
||||
parts[i] = '\\' + capturedGroups[decimalValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any prefix anchors so that the output will match anywhere.
|
||||
// ^^ really does mean an anchored match though.
|
||||
for (var i = 0, groupIndex = 0; i < n; ++i) {
|
||||
for (var i = 0; i < n; ++i) {
|
||||
if ('^' === parts[i] && '^' !== parts[i + 1]) { parts[i] = ''; }
|
||||
}
|
||||
|
||||
@ -446,7 +480,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
return new RegExp(rewritten.join('|'), ignoreCase ? 'gi' : 'g');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Split markup into a string of source code and an array mapping ranges in
|
||||
* that string to the text nodes in which they appear.
|
||||
@ -488,9 +521,11 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
* </p>
|
||||
*
|
||||
* @param {Node} node an HTML DOM subtree containing source-code.
|
||||
* @param {boolean} isPreformatted true if white-space in text nodes should
|
||||
* be considered significant.
|
||||
* @return {Object} source code and the text nodes in which they occur.
|
||||
*/
|
||||
function extractSourceSpans(node) {
|
||||
function extractSourceSpans(node, isPreformatted) {
|
||||
var nocode = /(?:^|\s)nocode(?:\s|$)/;
|
||||
|
||||
var chunks = [];
|
||||
@ -498,30 +533,20 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
var spans = [];
|
||||
var k = 0;
|
||||
|
||||
var whitespace;
|
||||
if (node.currentStyle) {
|
||||
whitespace = node.currentStyle.whiteSpace;
|
||||
} else if (window.getComputedStyle) {
|
||||
whitespace = document.defaultView.getComputedStyle(node, null)
|
||||
.getPropertyValue('white-space');
|
||||
}
|
||||
var isPreformatted = whitespace && 'pre' === whitespace.substring(0, 3);
|
||||
|
||||
function walk(node) {
|
||||
switch (node.nodeType) {
|
||||
case 1: // Element
|
||||
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;
|
||||
if ('BR' === nodeName || 'LI' === nodeName) {
|
||||
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
|
||||
} else if (type == 3 || type == 4) { // Text
|
||||
var text = node.nodeValue;
|
||||
if (text.length) {
|
||||
if (!isPreformatted) {
|
||||
@ -535,7 +560,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
length += text.length;
|
||||
spans[(k++ << 1) | 1] = node;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -547,7 +571,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply the given language handler to sourceCode and add the resulting
|
||||
* decorations to out.
|
||||
@ -812,12 +835,13 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
} else {
|
||||
// Stop C preprocessor declarations at an unclosed open comment
|
||||
shortcutStylePatterns.push(
|
||||
[PR_COMMENT, /^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,
|
||||
[PR_COMMENT, /^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\b|[^\r\n]*)/,
|
||||
null, '#']);
|
||||
}
|
||||
// #include <stdio.h>
|
||||
fallthroughStylePatterns.push(
|
||||
[PR_STRING,
|
||||
/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,
|
||||
/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/,
|
||||
null]);
|
||||
} else {
|
||||
shortcutStylePatterns.push([PR_COMMENT, /^#[^\r\n]*/, null, '#']);
|
||||
@ -828,7 +852,18 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
fallthroughStylePatterns.push(
|
||||
[PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null]);
|
||||
}
|
||||
if (options['regexLiterals']) {
|
||||
var regexLiterals = options['regexLiterals'];
|
||||
if (regexLiterals) {
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
var regexExcls = regexLiterals > 1
|
||||
? '' // Multiline regex literals
|
||||
: '\n\r';
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
var regexAny = regexExcls ? '.' : '[\\S\\s]';
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
@ -836,18 +871,19 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
// A regular expression literal starts with a slash that is
|
||||
// not followed by * or / so that it is not confused with
|
||||
// comments.
|
||||
'/(?=[^/*])'
|
||||
'/(?=[^/*' + regexExcls + '])'
|
||||
// and then contains any number of raw characters,
|
||||
+ '(?:[^/\\x5B\\x5C]'
|
||||
+ '(?:[^/\\x5B\\x5C' + regexExcls + ']'
|
||||
// escape sequences (\x5C),
|
||||
+ '|\\x5C[\\s\\S]'
|
||||
+ '|\\x5C' + regexAny
|
||||
// or non-nesting character sets (\x5B\x5D);
|
||||
+ '|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+'
|
||||
+ '|\\x5B(?:[^\\x5C\\x5D' + regexExcls + ']'
|
||||
+ '|\\x5C' + regexAny + ')*(?:\\x5D|$))+'
|
||||
// finally closed by a /.
|
||||
+ '/');
|
||||
fallthroughStylePatterns.push(
|
||||
['lang-regex',
|
||||
new RegExp('^' + REGEXP_PRECEDER_PATTERN + '(' + REGEX_LITERAL + ')')
|
||||
RegExp('^' + REGEXP_PRECEDER_PATTERN + '(' + REGEX_LITERAL + ')')
|
||||
]);
|
||||
}
|
||||
|
||||
@ -865,6 +901,48 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
}
|
||||
|
||||
shortcutStylePatterns.push([PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']);
|
||||
|
||||
var punctuation =
|
||||
// The Bash man page says
|
||||
|
||||
// A word is a sequence of characters considered as a single
|
||||
// unit by GRUB. Words are separated by metacharacters,
|
||||
// which are the following plus space, tab, and newline: { }
|
||||
// | & $ ; < >
|
||||
// ...
|
||||
|
||||
// A word beginning with # causes that word and all remaining
|
||||
// characters on that line to be ignored.
|
||||
|
||||
// which means that only a '#' after /(?:^|[{}|&$;<>\s])/ starts a
|
||||
// comment but empirically
|
||||
// $ echo {#}
|
||||
// {#}
|
||||
// $ echo \$#
|
||||
// $#
|
||||
// $ echo }#
|
||||
// }#
|
||||
|
||||
// so /(?:^|[|&;<>\s])/ is more appropriate.
|
||||
|
||||
// http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC3
|
||||
// suggests that this definition is compatible with a
|
||||
// default mode that tries to use a single token definition
|
||||
// to recognize both bash/python style comments and C
|
||||
// preprocessor directives.
|
||||
|
||||
// This definition of punctuation does not include # in the list of
|
||||
// follow-on exclusions, so # will not be broken before if preceeded
|
||||
// by a punctuation character. We could try to exclude # after
|
||||
// [|&;<>] but that doesn't seem to cause many major problems.
|
||||
// If that does turn out to be a problem, we should change the below
|
||||
// when hc is truthy to include # in the run of punctuation characters
|
||||
// only when not followint [|&;<>].
|
||||
'^.[^\\s\\w.$@\'"`/\\\\]*';
|
||||
if (options['regexLiterals']) {
|
||||
punctuation += '(?!\s*\/)';
|
||||
}
|
||||
|
||||
fallthroughStylePatterns.push(
|
||||
// TODO(mikesamuel): recognize non-latin letters and numerals in idents
|
||||
[PR_LITERAL, /^@[a-z_$][a-z_$@0-9]*/i, null],
|
||||
@ -883,9 +961,10 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
// with an optional modifier like UL for unsigned long
|
||||
+ '[a-z]*', 'i'),
|
||||
null, '0123456789'],
|
||||
// Don't treat escaped quotes in bash as starting strings. See issue 144.
|
||||
// Don't treat escaped quotes in bash as starting strings.
|
||||
// See issue 144.
|
||||
[PR_PLAIN, /^\\[\s\S]?/, null],
|
||||
[PR_PUNCTUATION, /^.[^\s\w\.$@\'\"\`\/\#\\]*/, null]);
|
||||
[PR_PUNCTUATION, new RegExp(punctuation), null]);
|
||||
|
||||
return createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns);
|
||||
}
|
||||
@ -906,25 +985,16 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
* HTMLOListElement, and each line is moved into a separate list item.
|
||||
* This requires cloning elements, so the input might not have unique
|
||||
* IDs after numbering.
|
||||
* @param {boolean} isPreformatted true iff white-space in text nodes should
|
||||
* be treated as significant.
|
||||
*/
|
||||
function numberLines(node, opt_startLineNum) {
|
||||
function numberLines(node, opt_startLineNum, isPreformatted) {
|
||||
var nocode = /(?:^|\s)nocode(?:\s|$)/;
|
||||
var lineBreak = /\r\n?|\n/;
|
||||
|
||||
var document = node.ownerDocument;
|
||||
|
||||
var whitespace;
|
||||
if (node.currentStyle) {
|
||||
whitespace = node.currentStyle.whiteSpace;
|
||||
} else if (window.getComputedStyle) {
|
||||
whitespace = document.defaultView.getComputedStyle(node, null)
|
||||
.getPropertyValue('white-space');
|
||||
}
|
||||
// If it's preformatted, then we need to split lines on line breaks
|
||||
// in addition to <BR>s.
|
||||
var isPreformatted = whitespace && 'pre' === whitespace.substring(0, 3);
|
||||
|
||||
var li = document.createElement('LI');
|
||||
var li = document.createElement('li');
|
||||
while (node.firstChild) {
|
||||
li.appendChild(node.firstChild);
|
||||
}
|
||||
@ -933,10 +1003,9 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
var listItems = [li];
|
||||
|
||||
function walk(node) {
|
||||
switch (node.nodeType) {
|
||||
case 1: // Element
|
||||
if (nocode.test(node.className)) { break; }
|
||||
if ('BR' === node.nodeName) {
|
||||
var type = node.nodeType;
|
||||
if (type == 1 && !nocode.test(node.className)) { // Element
|
||||
if ('br' === node.nodeName) {
|
||||
breakAfter(node);
|
||||
// Discard the <BR> since it is now flush against a </LI>.
|
||||
if (node.parentNode) {
|
||||
@ -947,9 +1016,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
walk(child);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3: case 4: // Text
|
||||
if (isPreformatted) {
|
||||
} else if ((type == 3 || type == 4) && isPreformatted) { // Text
|
||||
var text = node.nodeValue;
|
||||
var match = text.match(lineBreak);
|
||||
if (match) {
|
||||
@ -968,8 +1035,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Split a line after the given node.
|
||||
@ -1028,7 +1093,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
listItems[0].setAttribute('value', opt_startLineNum);
|
||||
}
|
||||
|
||||
var ol = document.createElement('OL');
|
||||
var ol = document.createElement('ol');
|
||||
ol.className = 'linenums';
|
||||
var offset = Math.max(0, ((opt_startLineNum - 1 /* zero index */)) | 0) || 0;
|
||||
for (var i = 0, n = listItems.length; i < n; ++i) {
|
||||
@ -1045,12 +1110,12 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
|
||||
node.appendChild(ol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Breaks {@code job.sourceCode} around style boundaries in
|
||||
* {@code job.decorations} and modifies {@code job.sourceNode} in place.
|
||||
* @param {Object} job like <pre>{
|
||||
* sourceCode: {string} source as plain text,
|
||||
* sourceNode: {HTMLElement} the element containing the source,
|
||||
* spans: {Array.<number|Node>} alternating span start indices into source
|
||||
* and the text node or element (e.g. {@code <BR>}) corresponding to that
|
||||
* span.
|
||||
@ -1060,7 +1125,8 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
* @private
|
||||
*/
|
||||
function recombineTagsAndDecorations(job) {
|
||||
var isIE = /\bMSIE\b/.test(navigator.userAgent);
|
||||
var isIE8OrEarlier = /\bMSIE\s(\d+)/.exec(navigator.userAgent);
|
||||
isIE8OrEarlier = isIE8OrEarlier && +isIE8OrEarlier[1] <= 8;
|
||||
var newlineRe = /\n/g;
|
||||
|
||||
var source = job.sourceCode;
|
||||
@ -1108,12 +1174,18 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
|
||||
nDecorations = decorations.length = decPos;
|
||||
|
||||
var sourceNode = job.sourceNode;
|
||||
var oldDisplay;
|
||||
if (sourceNode) {
|
||||
oldDisplay = sourceNode.style.display;
|
||||
sourceNode.style.display = 'none';
|
||||
}
|
||||
try {
|
||||
var decoration = null;
|
||||
while (spanIndex < nSpans) {
|
||||
var spanStart = spans[spanIndex];
|
||||
var spanEnd = spans[spanIndex + 2] || sourceLength;
|
||||
|
||||
var decStart = decorations[decorationIndex];
|
||||
var decEnd = decorations[decorationIndex + 2] || sourceLength;
|
||||
|
||||
var end = Math.min(spanEnd, decEnd);
|
||||
@ -1128,10 +1200,12 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
// Emitting Windows standard issue linebreaks (CRLF) causes a blank
|
||||
// space to appear at the beginning of every line but the first.
|
||||
// Emitting an old Mac OS 9 line separator makes everything spiffy.
|
||||
if (isIE) { styledText = styledText.replace(newlineRe, '\r'); }
|
||||
if (isIE8OrEarlier) {
|
||||
styledText = styledText.replace(newlineRe, '\r');
|
||||
}
|
||||
textNode.nodeValue = styledText;
|
||||
var document = textNode.ownerDocument;
|
||||
var span = document.createElement('SPAN');
|
||||
var span = document.createElement('span');
|
||||
span.className = decorations[decorationIndex + 1];
|
||||
var parentNode = textNode.parentNode;
|
||||
parentNode.replaceChild(span, textNode);
|
||||
@ -1153,8 +1227,12 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
decorationIndex += 2;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (sourceNode) {
|
||||
sourceNode.style.display = oldDisplay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Maps language-specific file extensions to handlers. */
|
||||
var langHandlerRegistry = {};
|
||||
@ -1179,7 +1257,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
var ext = fileExtensions[i];
|
||||
if (!langHandlerRegistry.hasOwnProperty(ext)) {
|
||||
langHandlerRegistry[ext] = handler;
|
||||
} else if (window['console']) {
|
||||
} else if (win['console']) {
|
||||
console['warn']('cannot override language handler %s', ext);
|
||||
}
|
||||
}
|
||||
@ -1259,30 +1337,30 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
'keywords': SH_KEYWORDS,
|
||||
'hashComments': true,
|
||||
'multiLineStrings': true
|
||||
}), ['bsh', 'csh', 'sh']);
|
||||
}), ['bash', 'bsh', 'csh', 'sh']);
|
||||
registerLangHandler(sourceDecorator({
|
||||
'keywords': PYTHON_KEYWORDS,
|
||||
'hashComments': true,
|
||||
'multiLineStrings': true,
|
||||
'tripleQuotedStrings': true
|
||||
}), ['cv', 'py']);
|
||||
}), ['cv', 'py', 'python']);
|
||||
registerLangHandler(sourceDecorator({
|
||||
'keywords': PERL_KEYWORDS,
|
||||
'hashComments': true,
|
||||
'multiLineStrings': true,
|
||||
'regexLiterals': true
|
||||
'regexLiterals': 2 // multiline regex literals
|
||||
}), ['perl', 'pl', 'pm']);
|
||||
registerLangHandler(sourceDecorator({
|
||||
'keywords': RUBY_KEYWORDS,
|
||||
'hashComments': true,
|
||||
'multiLineStrings': true,
|
||||
'regexLiterals': true
|
||||
}), ['rb']);
|
||||
}), ['rb', 'ruby']);
|
||||
registerLangHandler(sourceDecorator({
|
||||
'keywords': JSCRIPT_KEYWORDS,
|
||||
'cStyleComments': true,
|
||||
'regexLiterals': true
|
||||
}), ['js']);
|
||||
}), ['javascript', 'js']);
|
||||
registerLangHandler(sourceDecorator({
|
||||
'keywords': COFFEE_KEYWORDS,
|
||||
'hashComments': 3, // ### style block comments
|
||||
@ -1291,14 +1369,20 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
'tripleQuotedStrings': true,
|
||||
'regexLiterals': true
|
||||
}), ['coffee']);
|
||||
registerLangHandler(createSimpleLexer([], [[PR_STRING, /^[\s\S]+/]]), ['regex']);
|
||||
registerLangHandler(sourceDecorator({
|
||||
'keywords': RUST_KEYWORDS,
|
||||
'cStyleComments': true,
|
||||
'multilineStrings': true
|
||||
}), ['rc', 'rs', 'rust']);
|
||||
registerLangHandler(
|
||||
createSimpleLexer([], [[PR_STRING, /^[\s\S]+/]]), ['regex']);
|
||||
|
||||
function applyDecorator(job) {
|
||||
var opt_langExtension = job.langExtension;
|
||||
|
||||
try {
|
||||
// Extract tags, and convert the source code to plain text.
|
||||
var sourceAndSpans = extractSourceSpans(job.sourceNode);
|
||||
var sourceAndSpans = extractSourceSpans(job.sourceNode, job.pre);
|
||||
/** Plain text. @type {string} */
|
||||
var source = sourceAndSpans.sourceCode;
|
||||
job.sourceCode = source;
|
||||
@ -1312,40 +1396,58 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
// modifying the sourceNode in place.
|
||||
recombineTagsAndDecorations(job);
|
||||
} catch (e) {
|
||||
if ('console' in window) {
|
||||
console['log'](e && e['stack'] ? e['stack'] : e);
|
||||
if (win['console']) {
|
||||
console['log'](e && e['stack'] || e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretty print a chunk of code.
|
||||
* @param sourceCodeHtml {string} The HTML to pretty print.
|
||||
* @param opt_langExtension {string} The language name to use.
|
||||
* Typically, a filename extension like 'cpp' or 'java'.
|
||||
* @param opt_numberLines {number|boolean} True to number lines,
|
||||
* or the 1-indexed number of the first line in sourceCodeHtml.
|
||||
*/
|
||||
function prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines) {
|
||||
var container = document.createElement('PRE');
|
||||
function $prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines) {
|
||||
var container = document.createElement('div');
|
||||
// This could cause images to load and onload listeners to fire.
|
||||
// E.g. <img onerror="alert(1337)" src="nosuchimage.png">.
|
||||
// We assume that the inner HTML is from a trusted source.
|
||||
container.innerHTML = sourceCodeHtml;
|
||||
// The pre-tag is required for IE8 which strips newlines from innerHTML
|
||||
// when it is injected into a <pre> tag.
|
||||
// http://stackoverflow.com/questions/451486/pre-tag-loses-line-breaks-when-setting-innerhtml-in-ie
|
||||
// http://stackoverflow.com/questions/195363/inserting-a-newline-into-a-pre-tag-ie-javascript
|
||||
container.innerHTML = '<pre>' + sourceCodeHtml + '</pre>';
|
||||
container = container.firstChild;
|
||||
if (opt_numberLines) {
|
||||
numberLines(container, opt_numberLines);
|
||||
numberLines(container, opt_numberLines, true);
|
||||
}
|
||||
|
||||
var job = {
|
||||
langExtension: opt_langExtension,
|
||||
numberLines: opt_numberLines,
|
||||
sourceNode: container
|
||||
sourceNode: container,
|
||||
pre: 1
|
||||
};
|
||||
applyDecorator(job);
|
||||
return container.innerHTML;
|
||||
}
|
||||
|
||||
function prettyPrint(opt_whenDone) {
|
||||
function byTagName(tn) { return document.getElementsByTagName(tn); }
|
||||
/**
|
||||
* Find all the {@code <pre>} and {@code <code>} tags in the DOM with
|
||||
* {@code class=prettyprint} and prettify them.
|
||||
*
|
||||
* @param {Function} opt_whenDone called when prettifying is done.
|
||||
* @param {HTMLElement|HTMLDocument} opt_root an element or document
|
||||
* containing all the elements to pretty print.
|
||||
* Defaults to {@code document.body}.
|
||||
*/
|
||||
function $prettyPrint(opt_whenDone, opt_root) {
|
||||
var root = opt_root || document.body;
|
||||
var doc = root.ownerDocument || document;
|
||||
function byTagName(tn) { return root.getElementsByTagName(tn); }
|
||||
// fetch a list of nodes to rewrite
|
||||
var codeSegments = [byTagName('pre'), byTagName('code'), byTagName('xmp')];
|
||||
var elements = [];
|
||||
@ -1368,59 +1470,124 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
|
||||
var langExtensionRe = /\blang(?:uage)?-([\w.]+)(?!\S)/;
|
||||
var prettyPrintRe = /\bprettyprint\b/;
|
||||
var prettyPrintedRe = /\bprettyprinted\b/;
|
||||
var preformattedTagNameRe = /pre|xmp/i;
|
||||
var codeRe = /^code$/i;
|
||||
var preCodeXmpRe = /^(?:pre|code|xmp)$/i;
|
||||
var EMPTY = {};
|
||||
|
||||
function doWork() {
|
||||
var endTime = (window['PR_SHOULD_USE_CONTINUATION'] ?
|
||||
var endTime = (win['PR_SHOULD_USE_CONTINUATION'] ?
|
||||
clock['now']() + 250 /* ms */ :
|
||||
Infinity);
|
||||
for (; k < elements.length && clock['now']() < endTime; k++) {
|
||||
var cs = elements[k];
|
||||
var className = cs.className;
|
||||
if (className.indexOf('prettyprint') >= 0) {
|
||||
// If the classes includes a language extensions, use it.
|
||||
// Language extensions can be specified like
|
||||
// <pre class="prettyprint lang-cpp">
|
||||
// the language extension "cpp" is used to find a language handler as
|
||||
// passed to PR.registerLangHandler.
|
||||
// HTML5 recommends that a language be specified using "language-"
|
||||
// as the prefix instead. Google Code Prettify supports both.
|
||||
// http://dev.w3.org/html5/spec-author-view/the-code-element.html
|
||||
var langExtension = className.match(langExtensionRe);
|
||||
// Support <pre class="prettyprint"><code class="language-c">
|
||||
var wrapper;
|
||||
if (!langExtension && (wrapper = childContentWrapper(cs))
|
||||
&& "CODE" === wrapper.tagName) {
|
||||
langExtension = wrapper.className.match(langExtensionRe);
|
||||
|
||||
// Look for a preceding comment like
|
||||
// <?prettify lang="..." linenums="..."?>
|
||||
var attrs = EMPTY;
|
||||
{
|
||||
for (var preceder = cs; (preceder = preceder.previousSibling);) {
|
||||
var nt = preceder.nodeType;
|
||||
// <?foo?> is parsed by HTML 5 to a comment node (8)
|
||||
// like <!--?foo?-->, but in XML is a processing instruction
|
||||
var value = (nt === 7 || nt === 8) && preceder.nodeValue;
|
||||
if (value
|
||||
? !/^\??prettify\b/.test(value)
|
||||
: (nt !== 3 || /\S/.test(preceder.nodeValue))) {
|
||||
// Skip over white-space text nodes but not others.
|
||||
break;
|
||||
}
|
||||
if (value) {
|
||||
attrs = {};
|
||||
value.replace(
|
||||
/\b(\w+)=([\w:.%+-]+)/g,
|
||||
function (_, name, value) { attrs[name] = value; });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (langExtension) {
|
||||
langExtension = langExtension[1];
|
||||
}
|
||||
var className = cs.className;
|
||||
if ((attrs !== EMPTY || prettyPrintRe.test(className))
|
||||
// Don't redo this if we've already done it.
|
||||
// This allows recalling pretty print to just prettyprint elements
|
||||
// that have been added to the page since last call.
|
||||
&& !prettyPrintedRe.test(className)) {
|
||||
|
||||
// make sure this is not nested in an already prettified element
|
||||
var nested = false;
|
||||
for (var p = cs.parentNode; p; p = p.parentNode) {
|
||||
if ((p.tagName === 'pre' || p.tagName === 'code' ||
|
||||
p.tagName === 'xmp') &&
|
||||
p.className && p.className.indexOf('prettyprint') >= 0) {
|
||||
var tn = p.tagName;
|
||||
if (preCodeXmpRe.test(tn)
|
||||
&& p.className && prettyPrintRe.test(p.className)) {
|
||||
nested = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!nested) {
|
||||
// Mark done. If we fail to prettyprint for whatever reason,
|
||||
// we shouldn't try again.
|
||||
cs.className += ' prettyprinted';
|
||||
|
||||
// If the classes includes a language extensions, use it.
|
||||
// Language extensions can be specified like
|
||||
// <pre class="prettyprint lang-cpp">
|
||||
// the language extension "cpp" is used to find a language handler
|
||||
// as passed to PR.registerLangHandler.
|
||||
// HTML5 recommends that a language be specified using "language-"
|
||||
// as the prefix instead. Google Code Prettify supports both.
|
||||
// http://dev.w3.org/html5/spec-author-view/the-code-element.html
|
||||
var langExtension = attrs['lang'];
|
||||
if (!langExtension) {
|
||||
langExtension = className.match(langExtensionRe);
|
||||
// Support <pre class="prettyprint"><code class="language-c">
|
||||
var wrapper;
|
||||
if (!langExtension && (wrapper = childContentWrapper(cs))
|
||||
&& codeRe.test(wrapper.tagName)) {
|
||||
langExtension = wrapper.className.match(langExtensionRe);
|
||||
}
|
||||
|
||||
if (langExtension) { langExtension = langExtension[1]; }
|
||||
}
|
||||
|
||||
var preformatted;
|
||||
if (preformattedTagNameRe.test(cs.tagName)) {
|
||||
preformatted = 1;
|
||||
} else {
|
||||
var currentStyle = cs['currentStyle'];
|
||||
var defaultView = doc.defaultView;
|
||||
var whitespace = (
|
||||
currentStyle
|
||||
? currentStyle['whiteSpace']
|
||||
: (defaultView
|
||||
&& defaultView.getComputedStyle)
|
||||
? defaultView.getComputedStyle(cs, null)
|
||||
.getPropertyValue('white-space')
|
||||
: 0);
|
||||
preformatted = whitespace
|
||||
&& 'pre' === whitespace.substring(0, 3);
|
||||
}
|
||||
|
||||
// Look for a class like linenums or linenums:<n> where <n> is the
|
||||
// 1-indexed number of the first line.
|
||||
var lineNums = cs.className.match(/\blinenums\b(?::(\d+))?/);
|
||||
lineNums = lineNums
|
||||
? lineNums[1] && lineNums[1].length ? +lineNums[1] : true
|
||||
var lineNums = attrs['linenums'];
|
||||
if (!(lineNums = lineNums === 'true' || +lineNums)) {
|
||||
lineNums = className.match(/\blinenums\b(?::(\d+))?/);
|
||||
lineNums =
|
||||
lineNums
|
||||
? lineNums[1] && lineNums[1].length
|
||||
? +lineNums[1] : true
|
||||
: false;
|
||||
if (lineNums) { numberLines(cs, lineNums); }
|
||||
}
|
||||
if (lineNums) { numberLines(cs, lineNums, preformatted); }
|
||||
|
||||
// do the pretty printing
|
||||
prettyPrintingJob = {
|
||||
langExtension: langExtension,
|
||||
sourceNode: cs,
|
||||
numberLines: lineNums
|
||||
numberLines: lineNums,
|
||||
pre: preformatted
|
||||
};
|
||||
applyDecorator(prettyPrintingJob);
|
||||
}
|
||||
@ -1429,7 +1596,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
if (k < elements.length) {
|
||||
// finish up in a continuation
|
||||
setTimeout(doWork, 250);
|
||||
} else if (opt_whenDone) {
|
||||
} else if ('function' === typeof opt_whenDone) {
|
||||
opt_whenDone();
|
||||
}
|
||||
}
|
||||
@ -1437,26 +1604,11 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
doWork();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all the {@code <pre>} and {@code <code>} tags in the DOM with
|
||||
* {@code class=prettyprint} and prettify them.
|
||||
*
|
||||
* @param {Function?} opt_whenDone if specified, called when the last entry
|
||||
* has been finished.
|
||||
*/
|
||||
window['prettyPrintOne'] = prettyPrintOne;
|
||||
/**
|
||||
* Pretty print a chunk of code.
|
||||
*
|
||||
* @param {string} sourceCodeHtml code as html
|
||||
* @return {string} code as html, but prettier
|
||||
*/
|
||||
window['prettyPrint'] = prettyPrint;
|
||||
/**
|
||||
* Contains functions for creating and registering new language handlers.
|
||||
* @type {Object}
|
||||
*/
|
||||
window['PR'] = {
|
||||
var PR = win['PR'] = {
|
||||
'createSimpleLexer': createSimpleLexer,
|
||||
'registerLangHandler': registerLangHandler,
|
||||
'sourceDecorator': sourceDecorator,
|
||||
@ -1472,6 +1624,32 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&
|
||||
'PR_SOURCE': PR_SOURCE,
|
||||
'PR_STRING': PR_STRING,
|
||||
'PR_TAG': PR_TAG,
|
||||
'PR_TYPE': PR_TYPE
|
||||
'PR_TYPE': PR_TYPE,
|
||||
'prettyPrintOne':
|
||||
IN_GLOBAL_SCOPE
|
||||
? (win['prettyPrintOne'] = $prettyPrintOne)
|
||||
: (prettyPrintOne = $prettyPrintOne),
|
||||
'prettyPrint': prettyPrint =
|
||||
IN_GLOBAL_SCOPE
|
||||
? (win['prettyPrint'] = $prettyPrint)
|
||||
: (prettyPrint = $prettyPrint)
|
||||
};
|
||||
|
||||
// Make PR available via the Asynchronous Module Definition (AMD) API.
|
||||
// Per https://github.com/amdjs/amdjs-api/wiki/AMD:
|
||||
// The Asynchronous Module Definition (AMD) API specifies a
|
||||
// mechanism for defining modules such that the module and its
|
||||
// dependencies can be asynchronously loaded.
|
||||
// ...
|
||||
// To allow a clear indicator that a global define function (as
|
||||
// needed for script src browser loading) conforms to the AMD API,
|
||||
// any global define function SHOULD have a property called "amd"
|
||||
// whose value is an object. This helps avoid conflict with any
|
||||
// other existing JavaScript code that could have defined a define()
|
||||
// function that does not conform to the AMD API.
|
||||
if (typeof define === "function" && define['amd']) {
|
||||
define("google-code-prettify", [], function () {
|
||||
return PR;
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user