Added ada syntax highlighting
This commit is contained in:
		| @ -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/common.css')?>" /> | ||||||
| <link type="text/css" rel="stylesheet" href="<?=base_url_make('/css/code.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/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-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-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-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-sql.js')?>"></script> | ||||||
| <script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-vb.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  | <?php  | ||||||
| $fileext = substr(strrchr($file['name'], '.'), 1); | $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'; | $prettyprint_linenums = 'linenums'; | ||||||
| if ($login['settings'] != NULL && | if ($login['settings'] != NULL && | ||||||
|     $login['settings']->code_hide_line_num == 'Y') $prettyprint_linenums = ''; |     $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 | <?php | ||||||
|  |  | ||||||
| 	$content = $file['content']; | 	$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/common.css')?>" /> | ||||||
| <link type="text/css" rel="stylesheet" href="<?=base_url_make('/css/code.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/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-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-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-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-sql.js')?>"></script> | ||||||
| <script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-vb.js')?>"></script> | <script type="text/javascript" src="<?=base_url_make('/js/prettify/lang-vb.js')?>"></script> | ||||||
|  |  | ||||||
| @ -176,14 +179,18 @@ $this->load->view ( | |||||||
|  |  | ||||||
| <?php  | <?php  | ||||||
| $fileext = substr(strrchr($file['name'], '.'), 1); | $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'; | $prettyprint_linenums = 'linenums'; | ||||||
| if ($login['settings'] != NULL && | if ($login['settings'] != NULL && | ||||||
|     $login['settings']->code_hide_line_num == 'Y') $prettyprint_linenums = ''; |     $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']); ?> | <?php print htmlspecialchars($file['content']); ?> | ||||||
| </pre> | </pre> | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,15 +1,34 @@ | |||||||
| wwwdir=$(WWWDIR)/js/prettify | wwwdir=$(WWWDIR)/js/prettify | ||||||
| www_DATA =  \ | www_DATA =  \ | ||||||
|  | 	lang-ada.js \ | ||||||
| 	lang-apollo.js \ | 	lang-apollo.js \ | ||||||
|  | 	lang-basic.js \ | ||||||
|  | 	lang-clj.js \ | ||||||
| 	lang-css.js \ | 	lang-css.js \ | ||||||
|  | 	lang-dart.js \ | ||||||
|  | 	lang-erlang.js \ | ||||||
|  | 	lang-go.js \ | ||||||
| 	lang-hs.js \ | 	lang-hs.js \ | ||||||
| 	lang-lisp.js \ | 	lang-lisp.js \ | ||||||
|  | 	lang-llvm.js \ | ||||||
| 	lang-lua.js \ | 	lang-lua.js \ | ||||||
|  | 	lang-matlab.js \ | ||||||
| 	lang-ml.js \ | 	lang-ml.js \ | ||||||
|  | 	lang-mumps.js \ | ||||||
|  | 	lang-n.js \ | ||||||
|  | 	lang-pascal.js \ | ||||||
| 	lang-proto.js \ | 	lang-proto.js \ | ||||||
|  | 	lang-r.js \ | ||||||
|  | 	lang-rd.js \ | ||||||
|  | 	lang-scala.js \ | ||||||
| 	lang-sql.js \ | 	lang-sql.js \ | ||||||
|  | 	lang-tcl.js \ | ||||||
|  | 	lang-tex.js \ | ||||||
| 	lang-vb.js \ | 	lang-vb.js \ | ||||||
|  | 	lang-vhdl.js \ | ||||||
| 	lang-wiki.js \ | 	lang-wiki.js \ | ||||||
|  | 	lang-xq.js \ | ||||||
|  | 	lang-yaml.js \ | ||||||
| 	prettify.css \ | 	prettify.css \ | ||||||
| 	prettify.js | 	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 |  * @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['registerLangHandler']( | ||||||
|     PR['createSimpleLexer']( |     PR['createSimpleLexer']( | ||||||
|  |         // Shortcut patterns. | ||||||
|         [ |         [ | ||||||
|          // The space production <s> |          // The space production <s> | ||||||
|          [PR['PR_PLAIN'],       /^[ \t\r\n\f]+/, null, ' \t\r\n\f'] |          [PR['PR_PLAIN'],       /^[ \t\r\n\f]+/, null, ' \t\r\n\f'] | ||||||
|         ], |         ], | ||||||
|  |         // Fall-through patterns. | ||||||
|         [ |         [ | ||||||
|          // Quoted strings.  <string1> and <string2> |          // Quoted strings.  <string1> and <string2> | ||||||
|          [PR['PR_STRING'], |          [PR['PR_STRING'], | ||||||
|           /^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/, null], |           /^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/, null], | ||||||
|          [PR['PR_STRING'], |          [PR['PR_STRING'], | ||||||
|           /^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/, null], |           /^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/, null], | ||||||
|          ['lang-css-str', /^url\(([^\)\"\']*)\)/i], |          ['lang-css-str', /^url\(([^\)\"\']+)\)/i], | ||||||
|          [PR['PR_KEYWORD'], |          [PR['PR_KEYWORD'], | ||||||
|           /^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i, |           /^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i, | ||||||
|           null], |           null], | ||||||
| @ -55,7 +131,7 @@ PR['registerLangHandler']( | |||||||
|          // A number possibly containing a suffix. |          // A number possibly containing a suffix. | ||||||
|          [PR['PR_LITERAL'], /^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i], |          [PR['PR_LITERAL'], /^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i], | ||||||
|          // A hex color |          // 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 |          // An identifier | ||||||
|          [PR['PR_PLAIN'], |          [PR['PR_PLAIN'], | ||||||
|           /^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i], |           /^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i], | ||||||
| @ -63,6 +139,8 @@ PR['registerLangHandler']( | |||||||
|          [PR['PR_PUNCTUATION'], /^[^\s\w\'\"]+/] |          [PR['PR_PUNCTUATION'], /^[^\s\w\'\"]+/] | ||||||
|         ]), |         ]), | ||||||
|     ['css']); |     ['css']); | ||||||
|  | // Above we use embedded languages to highlight property names (identifiers | ||||||
|  | // followed by a colon) differently from identifiers in values. | ||||||
| PR['registerLangHandler']( | PR['registerLangHandler']( | ||||||
|     PR['createSimpleLexer']([], |     PR['createSimpleLexer']([], | ||||||
|         [ |         [ | ||||||
| @ -70,6 +148,9 @@ PR['registerLangHandler']( | |||||||
|           /^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i] |           /^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i] | ||||||
|         ]), |         ]), | ||||||
|     ['css-kw']); |     ['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['registerLangHandler']( | ||||||
|     PR['createSimpleLexer']([], |     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-el - Emacs Lisp | ||||||
|  *     lang-lisp - Lisp |  *     lang-lisp - Lisp | ||||||
|  *     lang-scm - Scheme |  *     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 |  * 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 |          // A printable non-space non-special character | ||||||
|          [PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0()\"\\\';]+/] |          [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. |  * @author Zimin A.V. | ||||||
|  */ |  */ | ||||||
| (function () { | (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|' |   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|' |          + 'fun|implements|interface|internal|is|macro|match|matches|module|mutable|namespace|new|' | ||||||
|          + 'null|out|override|params|partial|private|protected|public|ref|sealed|static|struct|' |          + '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|' |          + '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'; |          + 'otherwise|regexp|repeat|requires|return|surroundwith|unchecked|unless|using|while|yield'; | ||||||
|  |  | ||||||
|   var shortcutStylePatterns = [ |   PR['registerLangHandler'](PR['createSimpleLexer']( | ||||||
|         [PR.PR_STRING, /^(?:\'(?:[^\\\'\r\n]|\\.)*\'|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/, null, '"'], |       // shortcutStylePatterns | ||||||
|         [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'] |         [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], |       // fallthroughStylePatterns | ||||||
|         [PR.PR_STRING, /^<#(?:[^#>])*(?:#>|$)/, null], |       [ | ||||||
|         [PR.PR_STRING, /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/, null], |         [PR['PR_STRING'], /^@\"(?:[^\"]|\"\")*(?:\"|$)/, null], | ||||||
|         [PR.PR_COMMENT, /^\/\/[^\r\n]*/, null], |         [PR['PR_STRING'], /^<#(?:[^#>])*(?:#>|$)/, null], | ||||||
|         [PR.PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null], |         [PR['PR_STRING'], /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/, null], | ||||||
|         [PR.PR_KEYWORD, new RegExp('^(?:' + keywords + ')\\b'), null], |         [PR['PR_COMMENT'], /^\/\/[^\r\n]*/, 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_COMMENT'], /^\/\*[\s\S]*?(?:\*\/|$)/, null], | ||||||
|         [PR.PR_LITERAL, /^@[a-z_$][a-z_$@0-9]*/i, null], |         [PR['PR_KEYWORD'], new RegExp('^(?:' + keywords + ')\\b'), null], | ||||||
|         [PR.PR_TYPE, /^@[A-Z]+[a-z][A-Za-z_$@0-9]*/, 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_PLAIN, /^'?[A-Za-z_$][a-z_$@0-9]*/i, null], |         [PR['PR_LITERAL'], /^@[a-z_$][a-z_$@0-9]*/i, null], | ||||||
|         [PR.PR_LITERAL, new RegExp( |         [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 |   // A hex number | ||||||
|              + '0x[a-f0-9]+' |              + '0x[a-f0-9]+' | ||||||
| @ -56,7 +59,7 @@ | |||||||
|   // with an optional modifier like UL for unsigned long |   // with an optional modifier like UL for unsigned long | ||||||
|              + '[a-z]*', 'i'), null, '0123456789'], |              + '[a-z]*', 'i'), null, '0123456789'], | ||||||
|  |  | ||||||
|         [PR.PR_PUNCTUATION, /^.[^\s\w\.$@\'\"\`\/\#]*/, null] |         [PR['PR_PUNCTUATION'], /^.[^\s\w\.$@\'\"\`\/\#]*/, null] | ||||||
|   ]; |       ]), | ||||||
|   PR.registerLangHandler(PR.createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns), ['n', 'nemerle']); |       ['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://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 |  * http://msdn.microsoft.com/en-us/library/aa238507(SQL.80).aspx and | ||||||
|  * for the keyword list. |  * http://meta.stackoverflow.com/q/92352/137403 as the bases for the keyword | ||||||
|  |  * list. | ||||||
|  * |  * | ||||||
|  * @author mikesamuel@gmail.com |  * @author mikesamuel@gmail.com | ||||||
|  */ |  */ | ||||||
| @ -44,7 +45,7 @@ PR['registerLangHandler']( | |||||||
|          // A comment is either a line comment that starts with two dashes, or |          // A comment is either a line comment that starts with two dashes, or | ||||||
|          // two dashes preceding a long bracketed block. |          // two dashes preceding a long bracketed block. | ||||||
|          [PR['PR_COMMENT'], /^(?:--[^\r\n]*|\/\*[\s\S]*?(?:\*\/|$))/], |          [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 |          // A number is a hex integer literal, a decimal real literal, or in | ||||||
|          // scientific notation. |          // scientific notation. | ||||||
|          [PR['PR_LITERAL'], |          [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. |  * @author Martin S. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| PR.registerLangHandler( | PR['registerLangHandler']( | ||||||
|     PR.createSimpleLexer( |     PR['createSimpleLexer']( | ||||||
|         [ |         [ | ||||||
|          // whitespace |          // 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 '%' |          // 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 |          // any command starting with a \ and contains | ||||||
|          // either only letters (a-z,A-Z), '@' (internal macros) |          // 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 |          // or contains only one character | ||||||
|          [PR.PR_KEYWORD, /^\\./], |          [PR['PR_KEYWORD'], /^\\./], | ||||||
|          // Highlight dollar for math mode and ampersam for tabular |          // Highlight dollar for math mode and ampersam for tabular | ||||||
|          [PR.PR_TYPE,    /^[$&]/], |          [PR['PR_TYPE'],    /^[$&]/], | ||||||
|          // numeric measurement values with attached units |          // numeric measurement values with attached units | ||||||
|          [PR.PR_LITERAL, |          [PR['PR_LITERAL'], | ||||||
|           /[+-]?(?:\.\d+|\d+(?:\.\d*)?)(cm|em|ex|in|pc|pt|bp|mm)/i], |           /[+-]?(?:\.\d+|\d+(?:\.\d*)?)(cm|em|ex|in|pc|pt|bp|mm)/i], | ||||||
|          // punctuation usually occurring within commands |          // punctuation usually occurring within commands | ||||||
|          [PR.PR_PUNCTUATION, /^[{}()\[\]=]+/] |          [PR['PR_PUNCTUATION'], /^[{}()\[\]=]+/] | ||||||
|         ]), |         ]), | ||||||
|     ['latex', 'tex']); |     ['latex', 'tex']); | ||||||
|  | |||||||
| @ -41,17 +41,22 @@ PR['registerLangHandler']( | |||||||
|           '"\u201C\u201D'], |           '"\u201C\u201D'], | ||||||
|          // A comment starts with a single quote and runs until the end of the |          // A comment starts with a single quote and runs until the end of the | ||||||
|          // line. |          // 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], |          [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 |          // 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. |          // A boolean, numeric, or date literal. | ||||||
|          [PR['PR_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], |           /^(?: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? |          // An identifier.  Keywords can be turned into identifers | ||||||
|          [PR['PR_PLAIN'], /^(?:(?:[a-z]|_\w)\w*|\[(?:[a-z]|_\w)\w*\])/i], |          // 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 |          // A run of punctuation | ||||||
|          [PR['PR_PUNCTUATION'], |          [PR['PR_PUNCTUATION'], | ||||||
|           /^[^\w\t\n\r \"\'\[\]\xA0\u2018\u2019\u201C\u201D\u2028\u2029]+/], |           /^[^\w\t\n\r \"\'\[\]\xA0\u2018\u2019\u201C\u201D\u2028\u2029]+/], | ||||||
|  | |||||||
| @ -53,7 +53,10 @@ | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| // JSLint declarations | // 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 |  * Split {@code prettyPrint} into multiple timeouts so as not to interfere with | ||||||
| @ -62,33 +65,57 @@ | |||||||
|  */ |  */ | ||||||
| window['PR_SHOULD_USE_CONTINUATION'] = true; | 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 () { | (function () { | ||||||
|  |   var win = window; | ||||||
|   // Keyword lists for various languages. |   // Keyword lists for various languages. | ||||||
|   // We use things that coerce to strings to make them compact when minified |   // We use things that coerce to strings to make them compact when minified | ||||||
|   // and to defeat aggressive optimizers that fold large string constants. |   // and to defeat aggressive optimizers that fold large string constants. | ||||||
|   var FLOW_CONTROL_KEYWORDS = ["break,continue,do,else,for,if,return,while"]; |   var FLOW_CONTROL_KEYWORDS = ["break,continue,do,else,for,if,return,while"]; | ||||||
|   var C_KEYWORDS = [FLOW_CONTROL_KEYWORDS,"auto,case,char,const,default," +  |   var C_KEYWORDS = [FLOW_CONTROL_KEYWORDS,"auto,case,char,const,default," +  | ||||||
|       "double,enum,extern,float,goto,int,long,register,short,signed,sizeof," + |       "double,enum,extern,float,goto,inline,int,long,register,short,signed," + | ||||||
|       "static,struct,switch,typedef,union,unsigned,void,volatile"]; |       "sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"]; | ||||||
|   var COMMON_KEYWORDS = [C_KEYWORDS,"catch,class,delete,false,import," + |   var COMMON_KEYWORDS = [C_KEYWORDS,"catch,class,delete,false,import," + | ||||||
|       "new,operator,private,protected,public,this,throw,true,try,typeof"]; |       "new,operator,private,protected,public,this,throw,true,try,typeof"]; | ||||||
|   var CPP_KEYWORDS = [COMMON_KEYWORDS,"alignof,align_union,asm,axiom,bool," + |   var CPP_KEYWORDS = [COMMON_KEYWORDS,"alignof,align_union,asm,axiom,bool," + | ||||||
|       "concept,concept_map,const_cast,constexpr,decltype," + |       "concept,concept_map,const_cast,constexpr,decltype,delegate," + | ||||||
|       "dynamic_cast,explicit,export,friend,inline,late_check," + |       "dynamic_cast,explicit,export,friend,generic,late_check," + | ||||||
|       "mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast," + |       "mutable,namespace,nullptr,property,reinterpret_cast,static_assert," + | ||||||
|       "template,typeid,typename,using,virtual,where"]; |       "static_cast,template,typeid,typename,using,virtual,where"]; | ||||||
|   var JAVA_KEYWORDS = [COMMON_KEYWORDS, |   var JAVA_KEYWORDS = [COMMON_KEYWORDS, | ||||||
|       "abstract,boolean,byte,extends,final,finally,implements,import," + |       "abstract,assert,boolean,byte,extends,final,finally,implements,import," + | ||||||
|       "instanceof,null,native,package,strictfp,super,synchronized,throws," + |       "instanceof,interface,null,native,package,strictfp,super,synchronized," + | ||||||
|       "transient"]; |       "throws,transient"]; | ||||||
|   var CSHARP_KEYWORDS = [JAVA_KEYWORDS, |   var CSHARP_KEYWORDS = [JAVA_KEYWORDS, | ||||||
|       "as,base,by,checked,decimal,delegate,descending,dynamic,event," + |       "as,base,by,checked,decimal,delegate,descending,dynamic,event," + | ||||||
|       "fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock," + |       "fixed,foreach,from,group,implicit,in,internal,into,is,let," + | ||||||
|       "object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed," + |       "lock,object,out,override,orderby,params,partial,readonly,ref,sbyte," + | ||||||
|       "stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"]; |       "sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort," + | ||||||
|  |       "var,virtual,where"]; | ||||||
|   var COFFEE_KEYWORDS = "all,and,by,catch,class,else,extends,false,finally," + |   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," + |       "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, |   var JSCRIPT_KEYWORDS = [COMMON_KEYWORDS, | ||||||
|       "debugger,eval,export,function,get,null,set,undefined,var,with," + |       "debugger,eval,export,function,get,null,set,undefined,var,with," + | ||||||
|       "Infinity,NaN"]; |       "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," + |       "def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo," + | ||||||
|       "rescue,retry,self,super,then,true,undef,unless,until,when,yield," + |       "rescue,retry,self,super,then,true,undef,unless,until,when,yield," + | ||||||
|       "BEGIN,END"]; |       "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," + |   var SH_KEYWORDS = [FLOW_CONTROL_KEYWORDS, "case,done,elif,esac,eval,fi," + | ||||||
|       "function,in,local,set,then,until"]; |       "function,in,local,set,then,until"]; | ||||||
|   var ALL_KEYWORDS = [ |   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]; |       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 |   // token style names.  correspond to css classes | ||||||
|   /** |   /** | ||||||
| @ -142,7 +172,7 @@ window['PR_SHOULD_USE_CONTINUATION'] = true; | |||||||
|    */ |    */ | ||||||
|   var PR_PUNCTUATION = 'pun'; |   var PR_PUNCTUATION = 'pun'; | ||||||
|   /** |   /** | ||||||
|    * token style for a punctuation string. |    * token style for plain text. | ||||||
|    * @const |    * @const | ||||||
|    */ |    */ | ||||||
|   var PR_PLAIN = 'pln'; |   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 |    * A set of tokens that can precede a regular expression literal in | ||||||
|    * javascript |    * javascript | ||||||
|    * http://web.archive.org/web/20070717142515/http://www.mozilla.org/js/language/js20/rationale/syntax.html |    * 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 |    * "in" keyword since it's not a keyword in many languages, and might be used | ||||||
|    * as a count of inches. |    * 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 |    * it fails to distinguish between (a=++/b/i) and (a++/b/i) but it works | ||||||
|    * very well in practice. |    * very well in practice. | ||||||
|    * |    * | ||||||
|    * @private |    * @private | ||||||
|    * @const |    * @const | ||||||
|    */ |    */ | ||||||
| var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*'; |   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. |  | ||||||
|    |    | ||||||
|  |   // 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 |    * 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); |         return (charCode < 0x10 ? '\\x0' : '\\x') + charCode.toString(16); | ||||||
|       } |       } | ||||||
|       var ch = String.fromCharCode(charCode); |       var ch = String.fromCharCode(charCode); | ||||||
|       if (ch === '\\' || ch === '-' || ch === '[' || ch === ']') { |       return (ch === '\\' || ch === '-' || ch === ']' || ch === '^') | ||||||
|         ch = '\\' + ch; |           ? "\\" + ch : ch; | ||||||
|       } |  | ||||||
|       return ch; |  | ||||||
|     } |     } | ||||||
|    |    | ||||||
|     function caseFoldCharset(charSet) { |     function caseFoldCharset(charSet) { | ||||||
| @ -284,13 +311,16 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|               + '|-' |               + '|-' | ||||||
|               + '|[^-\\\\]', |               + '|[^-\\\\]', | ||||||
|               'g')); |               'g')); | ||||||
|       var groups = []; |  | ||||||
|       var ranges = []; |       var ranges = []; | ||||||
|       var inverse = charsetParts[0] === '^'; |       var inverse = charsetParts[0] === '^'; | ||||||
|  |    | ||||||
|  |       var out = ['[']; | ||||||
|  |       if (inverse) { out.push('^'); } | ||||||
|  |    | ||||||
|       for (var i = inverse ? 1 : 0, n = charsetParts.length; i < n; ++i) { |       for (var i = inverse ? 1 : 0, n = charsetParts.length; i < n; ++i) { | ||||||
|         var p = charsetParts[i]; |         var p = charsetParts[i]; | ||||||
|         if (/\\[bdsw]/i.test(p)) {  // Don't muck with named groups. |         if (/\\[bdsw]/i.test(p)) {  // Don't muck with named groups. | ||||||
|           groups.push(p); |           out.push(p); | ||||||
|         } else { |         } else { | ||||||
|           var start = decodeEscape(p); |           var start = decodeEscape(p); | ||||||
|           var end; |           var end; | ||||||
| @ -320,7 +350,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|       // -> [[1, 12], [14, 14], [16, 17]] |       // -> [[1, 12], [14, 14], [16, 17]] | ||||||
|       ranges.sort(function (a, b) { return (a[0] - b[0]) || (b[1]  - a[1]); }); |       ranges.sort(function (a, b) { return (a[0] - b[0]) || (b[1]  - a[1]); }); | ||||||
|       var consolidatedRanges = []; |       var consolidatedRanges = []; | ||||||
|       var lastRange = [NaN, NaN]; |       var lastRange = []; | ||||||
|       for (var i = 0; i < ranges.length; ++i) { |       for (var i = 0; i < ranges.length; ++i) { | ||||||
|         var range = ranges[i]; |         var range = ranges[i]; | ||||||
|         if (range[0] <= lastRange[1] + 1) { |         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) { |       for (var i = 0; i < consolidatedRanges.length; ++i) { | ||||||
|         var range = consolidatedRanges[i]; |         var range = consolidatedRanges[i]; | ||||||
|         out.push(encodeEscape(range[0])); |         out.push(encodeEscape(range[0])); | ||||||
| @ -358,7 +385,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|               + '|\\\\[0-9]+'  // a back-reference or octal escape |               + '|\\\\[0-9]+'  // a back-reference or octal escape | ||||||
|               + '|\\\\[^ux0-9]'  // other escape sequence |               + '|\\\\[^ux0-9]'  // other escape sequence | ||||||
|               + '|\\(\\?[:!=]'  // start of a non-capturing group |               + '|\\(\\?[:!=]'  // 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 |               + '|[^\\x5B\\x5C\\(\\)\\^]+'  // run of other characters | ||||||
|               + ')', |               + ')', | ||||||
|               'g')); |               'g')); | ||||||
| @ -378,8 +405,15 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           ++groupIndex; |           ++groupIndex; | ||||||
|         } else if ('\\' === p.charAt(0)) { |         } else if ('\\' === p.charAt(0)) { | ||||||
|           var decimalValue = +p.substring(1); |           var decimalValue = +p.substring(1); | ||||||
|           if (decimalValue && decimalValue <= groupIndex) { |           if (decimalValue) { | ||||||
|  |             if (decimalValue <= groupIndex) { | ||||||
|               capturedGroups[decimalValue] = -1; |               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]; |         var p = parts[i]; | ||||||
|         if (p === '(') { |         if (p === '(') { | ||||||
|           ++groupIndex; |           ++groupIndex; | ||||||
|           if (capturedGroups[groupIndex] === undefined) { |           if (!capturedGroups[groupIndex]) { | ||||||
|             parts[i] = '(?:'; |             parts[i] = '(?:'; | ||||||
|           } |           } | ||||||
|         } else if ('\\' === p.charAt(0)) { |         } else if ('\\' === p.charAt(0)) { | ||||||
|           var decimalValue = +p.substring(1); |           var decimalValue = +p.substring(1); | ||||||
|           if (decimalValue && decimalValue <= groupIndex) { |           if (decimalValue && decimalValue <= groupIndex) { | ||||||
|             parts[i] = '\\' + capturedGroups[groupIndex]; |             parts[i] = '\\' + capturedGroups[decimalValue]; | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|    |    | ||||||
|       // Remove any prefix anchors so that the output will match anywhere. |       // Remove any prefix anchors so that the output will match anywhere. | ||||||
|       // ^^ really does mean an anchored match though. |       // ^^ 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] = ''; } |         if ('^' === parts[i] && '^' !== parts[i + 1]) { parts[i] = ''; } | ||||||
|       } |       } | ||||||
|    |    | ||||||
| @ -446,7 +480,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|     return new RegExp(rewritten.join('|'), ignoreCase ? 'gi' : 'g'); |     return new RegExp(rewritten.join('|'), ignoreCase ? 'gi' : 'g'); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Split markup into a string of source code and an array mapping ranges in |    * Split markup into a string of source code and an array mapping ranges in | ||||||
|    * that string to the text nodes in which they appear. |    * that string to the text nodes in which they appear. | ||||||
| @ -488,9 +521,11 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|    * </p> |    * </p> | ||||||
|    * |    * | ||||||
|    * @param {Node} node an HTML DOM subtree containing source-code. |    * @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. |    * @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 nocode = /(?:^|\s)nocode(?:\s|$)/; | ||||||
|    |    | ||||||
|     var chunks = []; |     var chunks = []; | ||||||
| @ -498,30 +533,20 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|     var spans = []; |     var spans = []; | ||||||
|     var k = 0; |     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) { |     function walk(node) { | ||||||
|       switch (node.nodeType) { |       var type = node.nodeType; | ||||||
|         case 1:  // Element |       if (type == 1) {  // Element | ||||||
|         if (nocode.test(node.className)) { return; } |         if (nocode.test(node.className)) { return; } | ||||||
|         for (var child = node.firstChild; child; child = child.nextSibling) { |         for (var child = node.firstChild; child; child = child.nextSibling) { | ||||||
|           walk(child); |           walk(child); | ||||||
|         } |         } | ||||||
|           var nodeName = node.nodeName; |         var nodeName = node.nodeName.toLowerCase(); | ||||||
|           if ('BR' === nodeName || 'LI' === nodeName) { |         if ('br' === nodeName || 'li' === nodeName) { | ||||||
|           chunks[k] = '\n'; |           chunks[k] = '\n'; | ||||||
|           spans[k << 1] = length++; |           spans[k << 1] = length++; | ||||||
|           spans[(k++ << 1) | 1] = node; |           spans[(k++ << 1) | 1] = node; | ||||||
|         } |         } | ||||||
|           break; |       } else if (type == 3 || type == 4) {  // Text | ||||||
|         case 3: case 4:  // Text |  | ||||||
|         var text = node.nodeValue; |         var text = node.nodeValue; | ||||||
|         if (text.length) { |         if (text.length) { | ||||||
|           if (!isPreformatted) { |           if (!isPreformatted) { | ||||||
| @ -535,7 +560,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           length += text.length; |           length += text.length; | ||||||
|           spans[(k++ << 1) | 1] = node; |           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 |    * Apply the given language handler to sourceCode and add the resulting | ||||||
|    * decorations to out. |    * decorations to out. | ||||||
| @ -812,12 +835,13 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|         } else { |         } else { | ||||||
|           // Stop C preprocessor declarations at an unclosed open comment |           // Stop C preprocessor declarations at an unclosed open comment | ||||||
|           shortcutStylePatterns.push( |           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, '#']); |                null, '#']); | ||||||
|         } |         } | ||||||
|  |         // #include <stdio.h> | ||||||
|         fallthroughStylePatterns.push( |         fallthroughStylePatterns.push( | ||||||
|             [PR_STRING, |             [PR_STRING, | ||||||
|              /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/, |              /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/, | ||||||
|              null]); |              null]); | ||||||
|       } else { |       } else { | ||||||
|         shortcutStylePatterns.push([PR_COMMENT, /^#[^\r\n]*/, null, '#']); |         shortcutStylePatterns.push([PR_COMMENT, /^#[^\r\n]*/, null, '#']); | ||||||
| @ -828,7 +852,18 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|       fallthroughStylePatterns.push( |       fallthroughStylePatterns.push( | ||||||
|           [PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null]); |           [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 |        * @const | ||||||
|        */ |        */ | ||||||
| @ -836,18 +871,19 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           // A regular expression literal starts with a slash that is |           // A regular expression literal starts with a slash that is | ||||||
|           // not followed by * or / so that it is not confused with |           // not followed by * or / so that it is not confused with | ||||||
|           // comments. |           // comments. | ||||||
|           '/(?=[^/*])' |           '/(?=[^/*' + regexExcls + '])' | ||||||
|           // and then contains any number of raw characters, |           // and then contains any number of raw characters, | ||||||
|           + '(?:[^/\\x5B\\x5C]' |           + '(?:[^/\\x5B\\x5C' + regexExcls + ']' | ||||||
|           // escape sequences (\x5C), |           // escape sequences (\x5C), | ||||||
|           +    '|\\x5C[\\s\\S]' |           +    '|\\x5C' + regexAny | ||||||
|           // or non-nesting character sets (\x5B\x5D); |           // 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 /. |           // finally closed by a /. | ||||||
|           + '/'); |           + '/'); | ||||||
|       fallthroughStylePatterns.push( |       fallthroughStylePatterns.push( | ||||||
|           ['lang-regex', |           ['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']); |     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( |     fallthroughStylePatterns.push( | ||||||
|         // TODO(mikesamuel): recognize non-latin letters and numerals in idents |         // TODO(mikesamuel): recognize non-latin letters and numerals in idents | ||||||
|         [PR_LITERAL,     /^@[a-z_$][a-z_$@0-9]*/i, null], |         [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 |              // with an optional modifier like UL for unsigned long | ||||||
|              + '[a-z]*', 'i'), |              + '[a-z]*', 'i'), | ||||||
|          null, '0123456789'], |          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_PLAIN,       /^\\[\s\S]?/, null], | ||||||
|         [PR_PUNCTUATION, /^.[^\s\w\.$@\'\"\`\/\#\\]*/, null]); |         [PR_PUNCTUATION, new RegExp(punctuation), null]); | ||||||
|  |  | ||||||
|     return createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns); |     return createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns); | ||||||
|   } |   } | ||||||
| @ -906,25 +985,16 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|    *     HTMLOListElement, and each line is moved into a separate list item. |    *     HTMLOListElement, and each line is moved into a separate list item. | ||||||
|    *     This requires cloning elements, so the input might not have unique |    *     This requires cloning elements, so the input might not have unique | ||||||
|    *     IDs after numbering. |    *     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 nocode = /(?:^|\s)nocode(?:\s|$)/; | ||||||
|     var lineBreak = /\r\n?|\n/; |     var lineBreak = /\r\n?|\n/; | ||||||
|    |    | ||||||
|     var document = node.ownerDocument; |     var document = node.ownerDocument; | ||||||
|    |    | ||||||
|     var whitespace; |     var li = document.createElement('li'); | ||||||
|     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'); |  | ||||||
|     while (node.firstChild) { |     while (node.firstChild) { | ||||||
|       li.appendChild(node.firstChild); |       li.appendChild(node.firstChild); | ||||||
|     } |     } | ||||||
| @ -933,10 +1003,9 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|     var listItems = [li]; |     var listItems = [li]; | ||||||
|    |    | ||||||
|     function walk(node) { |     function walk(node) { | ||||||
|       switch (node.nodeType) { |       var type = node.nodeType; | ||||||
|         case 1:  // Element |       if (type == 1 && !nocode.test(node.className)) {  // Element | ||||||
|           if (nocode.test(node.className)) { break; } |         if ('br' === node.nodeName) { | ||||||
|           if ('BR' === node.nodeName) { |  | ||||||
|           breakAfter(node); |           breakAfter(node); | ||||||
|           // Discard the <BR> since it is now flush against a </LI>. |           // Discard the <BR> since it is now flush against a </LI>. | ||||||
|           if (node.parentNode) { |           if (node.parentNode) { | ||||||
| @ -947,9 +1016,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|             walk(child); |             walk(child); | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|           break; |       } else if ((type == 3 || type == 4) && isPreformatted) {  // Text | ||||||
|         case 3: case 4:  // Text |  | ||||||
|           if (isPreformatted) { |  | ||||||
|         var text = node.nodeValue; |         var text = node.nodeValue; | ||||||
|         var match = text.match(lineBreak); |         var match = text.match(lineBreak); | ||||||
|         if (match) { |         if (match) { | ||||||
| @ -968,8 +1035,6 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|           break; |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|    |    | ||||||
|     // Split a line after the given node. |     // Split a line after the given node. | ||||||
| @ -1028,7 +1093,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|       listItems[0].setAttribute('value', opt_startLineNum); |       listItems[0].setAttribute('value', opt_startLineNum); | ||||||
|     } |     } | ||||||
|    |    | ||||||
|     var ol = document.createElement('OL'); |     var ol = document.createElement('ol'); | ||||||
|     ol.className = 'linenums'; |     ol.className = 'linenums'; | ||||||
|     var offset = Math.max(0, ((opt_startLineNum - 1 /* zero index */)) | 0) || 0; |     var offset = Math.max(0, ((opt_startLineNum - 1 /* zero index */)) | 0) || 0; | ||||||
|     for (var i = 0, n = listItems.length; i < n; ++i) { |     for (var i = 0, n = listItems.length; i < n; ++i) { | ||||||
| @ -1045,12 +1110,12 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|    |    | ||||||
|     node.appendChild(ol); |     node.appendChild(ol); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Breaks {@code job.sourceCode} around style boundaries in |    * Breaks {@code job.sourceCode} around style boundaries in | ||||||
|    * {@code job.decorations} and modifies {@code job.sourceNode} in place. |    * {@code job.decorations} and modifies {@code job.sourceNode} in place. | ||||||
|    * @param {Object} job like <pre>{ |    * @param {Object} job like <pre>{ | ||||||
|    *    sourceCode: {string} source as plain text, |    *    sourceCode: {string} source as plain text, | ||||||
|  |    *    sourceNode: {HTMLElement} the element containing the source, | ||||||
|    *    spans: {Array.<number|Node>} alternating span start indices into source |    *    spans: {Array.<number|Node>} alternating span start indices into source | ||||||
|    *       and the text node or element (e.g. {@code <BR>}) corresponding to that |    *       and the text node or element (e.g. {@code <BR>}) corresponding to that | ||||||
|    *       span. |    *       span. | ||||||
| @ -1060,7 +1125,8 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|    * @private |    * @private | ||||||
|    */ |    */ | ||||||
|   function recombineTagsAndDecorations(job) { |   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 newlineRe = /\n/g; | ||||||
|    |    | ||||||
|     var source = job.sourceCode; |     var source = job.sourceCode; | ||||||
| @ -1108,12 +1174,18 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|    |    | ||||||
|     nDecorations = decorations.length = decPos; |     nDecorations = decorations.length = decPos; | ||||||
|    |    | ||||||
|  |     var sourceNode = job.sourceNode; | ||||||
|  |     var oldDisplay; | ||||||
|  |     if (sourceNode) { | ||||||
|  |       oldDisplay = sourceNode.style.display; | ||||||
|  |       sourceNode.style.display = 'none'; | ||||||
|  |     } | ||||||
|  |     try { | ||||||
|       var decoration = null; |       var decoration = null; | ||||||
|       while (spanIndex < nSpans) { |       while (spanIndex < nSpans) { | ||||||
|         var spanStart = spans[spanIndex]; |         var spanStart = spans[spanIndex]; | ||||||
|         var spanEnd = spans[spanIndex + 2] || sourceLength; |         var spanEnd = spans[spanIndex + 2] || sourceLength; | ||||||
|    |    | ||||||
|       var decStart = decorations[decorationIndex]; |  | ||||||
|         var decEnd = decorations[decorationIndex + 2] || sourceLength; |         var decEnd = decorations[decorationIndex + 2] || sourceLength; | ||||||
|    |    | ||||||
|         var end = Math.min(spanEnd, decEnd); |         var end = Math.min(spanEnd, decEnd); | ||||||
| @ -1128,10 +1200,12 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           // Emitting Windows standard issue linebreaks (CRLF) causes a blank |           // Emitting Windows standard issue linebreaks (CRLF) causes a blank | ||||||
|           // space to appear at the beginning of every line but the first. |           // space to appear at the beginning of every line but the first. | ||||||
|           // Emitting an old Mac OS 9 line separator makes everything spiffy. |           // 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; |           textNode.nodeValue = styledText; | ||||||
|           var document = textNode.ownerDocument; |           var document = textNode.ownerDocument; | ||||||
|         var span = document.createElement('SPAN'); |           var span = document.createElement('span'); | ||||||
|           span.className = decorations[decorationIndex + 1]; |           span.className = decorations[decorationIndex + 1]; | ||||||
|           var parentNode = textNode.parentNode; |           var parentNode = textNode.parentNode; | ||||||
|           parentNode.replaceChild(span, textNode); |           parentNode.replaceChild(span, textNode); | ||||||
| @ -1153,8 +1227,12 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           decorationIndex += 2; |           decorationIndex += 2; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|  |     } finally { | ||||||
|  |       if (sourceNode) { | ||||||
|  |         sourceNode.style.display = oldDisplay; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   /** Maps language-specific file extensions to handlers. */ |   /** Maps language-specific file extensions to handlers. */ | ||||||
|   var langHandlerRegistry = {}; |   var langHandlerRegistry = {}; | ||||||
| @ -1179,7 +1257,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|       var ext = fileExtensions[i]; |       var ext = fileExtensions[i]; | ||||||
|       if (!langHandlerRegistry.hasOwnProperty(ext)) { |       if (!langHandlerRegistry.hasOwnProperty(ext)) { | ||||||
|         langHandlerRegistry[ext] = handler; |         langHandlerRegistry[ext] = handler; | ||||||
|       } else if (window['console']) { |       } else if (win['console']) { | ||||||
|         console['warn']('cannot override language handler %s', ext); |         console['warn']('cannot override language handler %s', ext); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| @ -1259,30 +1337,30 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           'keywords': SH_KEYWORDS, |           'keywords': SH_KEYWORDS, | ||||||
|           'hashComments': true, |           'hashComments': true, | ||||||
|           'multiLineStrings': true |           'multiLineStrings': true | ||||||
|         }), ['bsh', 'csh', 'sh']); |         }), ['bash', 'bsh', 'csh', 'sh']); | ||||||
|   registerLangHandler(sourceDecorator({ |   registerLangHandler(sourceDecorator({ | ||||||
|           'keywords': PYTHON_KEYWORDS, |           'keywords': PYTHON_KEYWORDS, | ||||||
|           'hashComments': true, |           'hashComments': true, | ||||||
|           'multiLineStrings': true, |           'multiLineStrings': true, | ||||||
|           'tripleQuotedStrings': true |           'tripleQuotedStrings': true | ||||||
|         }), ['cv', 'py']); |         }), ['cv', 'py', 'python']); | ||||||
|   registerLangHandler(sourceDecorator({ |   registerLangHandler(sourceDecorator({ | ||||||
|           'keywords': PERL_KEYWORDS, |           'keywords': PERL_KEYWORDS, | ||||||
|           'hashComments': true, |           'hashComments': true, | ||||||
|           'multiLineStrings': true, |           'multiLineStrings': true, | ||||||
|           'regexLiterals': true |           'regexLiterals': 2  // multiline regex literals | ||||||
|         }), ['perl', 'pl', 'pm']); |         }), ['perl', 'pl', 'pm']); | ||||||
|   registerLangHandler(sourceDecorator({ |   registerLangHandler(sourceDecorator({ | ||||||
|           'keywords': RUBY_KEYWORDS, |           'keywords': RUBY_KEYWORDS, | ||||||
|           'hashComments': true, |           'hashComments': true, | ||||||
|           'multiLineStrings': true, |           'multiLineStrings': true, | ||||||
|           'regexLiterals': true |           'regexLiterals': true | ||||||
|         }), ['rb']); |         }), ['rb', 'ruby']); | ||||||
|   registerLangHandler(sourceDecorator({ |   registerLangHandler(sourceDecorator({ | ||||||
|           'keywords': JSCRIPT_KEYWORDS, |           'keywords': JSCRIPT_KEYWORDS, | ||||||
|           'cStyleComments': true, |           'cStyleComments': true, | ||||||
|           'regexLiterals': true |           'regexLiterals': true | ||||||
|         }), ['js']); |         }), ['javascript', 'js']); | ||||||
|   registerLangHandler(sourceDecorator({ |   registerLangHandler(sourceDecorator({ | ||||||
|           'keywords': COFFEE_KEYWORDS, |           'keywords': COFFEE_KEYWORDS, | ||||||
|           'hashComments': 3,  // ### style block comments |           'hashComments': 3,  // ### style block comments | ||||||
| @ -1291,14 +1369,20 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|           'tripleQuotedStrings': true, |           'tripleQuotedStrings': true, | ||||||
|           'regexLiterals': true |           'regexLiterals': true | ||||||
|         }), ['coffee']); |         }), ['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) { |   function applyDecorator(job) { | ||||||
|     var opt_langExtension = job.langExtension; |     var opt_langExtension = job.langExtension; | ||||||
|  |  | ||||||
|     try { |     try { | ||||||
|       // Extract tags, and convert the source code to plain text. |       // 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} */ |       /** Plain text. @type {string} */ | ||||||
|       var source = sourceAndSpans.sourceCode; |       var source = sourceAndSpans.sourceCode; | ||||||
|       job.sourceCode = source; |       job.sourceCode = source; | ||||||
| @ -1312,40 +1396,58 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|       // modifying the sourceNode in place. |       // modifying the sourceNode in place. | ||||||
|       recombineTagsAndDecorations(job); |       recombineTagsAndDecorations(job); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       if ('console' in window) { |       if (win['console']) { | ||||||
|         console['log'](e && e['stack'] ? e['stack'] : e); |         console['log'](e && e['stack'] || e); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|  |    * Pretty print a chunk of code. | ||||||
|    * @param sourceCodeHtml {string} The HTML to pretty print. |    * @param sourceCodeHtml {string} The HTML to pretty print. | ||||||
|    * @param opt_langExtension {string} The language name to use. |    * @param opt_langExtension {string} The language name to use. | ||||||
|    *     Typically, a filename extension like 'cpp' or 'java'. |    *     Typically, a filename extension like 'cpp' or 'java'. | ||||||
|    * @param opt_numberLines {number|boolean} True to number lines, |    * @param opt_numberLines {number|boolean} True to number lines, | ||||||
|    *     or the 1-indexed number of the first line in sourceCodeHtml. |    *     or the 1-indexed number of the first line in sourceCodeHtml. | ||||||
|    */ |    */ | ||||||
|   function prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines) { |   function $prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines) { | ||||||
|     var container = document.createElement('PRE'); |     var container = document.createElement('div'); | ||||||
|     // This could cause images to load and onload listeners to fire. |     // This could cause images to load and onload listeners to fire. | ||||||
|     // E.g. <img onerror="alert(1337)" src="nosuchimage.png">. |     // E.g. <img onerror="alert(1337)" src="nosuchimage.png">. | ||||||
|     // We assume that the inner HTML is from a trusted source. |     // 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) { |     if (opt_numberLines) { | ||||||
|       numberLines(container, opt_numberLines); |       numberLines(container, opt_numberLines, true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     var job = { |     var job = { | ||||||
|       langExtension: opt_langExtension, |       langExtension: opt_langExtension, | ||||||
|       numberLines: opt_numberLines, |       numberLines: opt_numberLines, | ||||||
|       sourceNode: container |       sourceNode: container, | ||||||
|  |       pre: 1 | ||||||
|     }; |     }; | ||||||
|     applyDecorator(job); |     applyDecorator(job); | ||||||
|     return container.innerHTML; |     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 |     // fetch a list of nodes to rewrite | ||||||
|     var codeSegments = [byTagName('pre'), byTagName('code'), byTagName('xmp')]; |     var codeSegments = [byTagName('pre'), byTagName('code'), byTagName('xmp')]; | ||||||
|     var elements = []; |     var elements = []; | ||||||
| @ -1368,59 +1470,124 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|  |  | ||||||
|     var langExtensionRe = /\blang(?:uage)?-([\w.]+)(?!\S)/; |     var langExtensionRe = /\blang(?:uage)?-([\w.]+)(?!\S)/; | ||||||
|     var prettyPrintRe = /\bprettyprint\b/; |     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() { |     function doWork() { | ||||||
|       var endTime = (window['PR_SHOULD_USE_CONTINUATION'] ? |       var endTime = (win['PR_SHOULD_USE_CONTINUATION'] ? | ||||||
|                      clock['now']() + 250 /* ms */ : |                      clock['now']() + 250 /* ms */ : | ||||||
|                      Infinity); |                      Infinity); | ||||||
|       for (; k < elements.length && clock['now']() < endTime; k++) { |       for (; k < elements.length && clock['now']() < endTime; k++) { | ||||||
|         var cs = elements[k]; |         var cs = elements[k]; | ||||||
|         var className = cs.className; |  | ||||||
|         if (className.indexOf('prettyprint') >= 0) { |         // Look for a preceding comment like | ||||||
|           // If the classes includes a language extensions, use it. |         // <?prettify lang="..." linenums="..."?> | ||||||
|           // Language extensions can be specified like |         var attrs = EMPTY; | ||||||
|           //     <pre class="prettyprint lang-cpp"> |         { | ||||||
|           // the language extension "cpp" is used to find a language handler as |           for (var preceder = cs; (preceder = preceder.previousSibling);) { | ||||||
|           // passed to PR.registerLangHandler. |             var nt = preceder.nodeType; | ||||||
|           // HTML5 recommends that a language be specified using "language-" |             // <?foo?> is parsed by HTML 5 to a comment node (8) | ||||||
|           // as the prefix instead.  Google Code Prettify supports both. |             // like <!--?foo?-->, but in XML is a processing instruction | ||||||
|           // http://dev.w3.org/html5/spec-author-view/the-code-element.html |             var value = (nt === 7 || nt === 8) && preceder.nodeValue; | ||||||
|           var langExtension = className.match(langExtensionRe); |             if (value | ||||||
|           // Support <pre class="prettyprint"><code class="language-c"> |                 ? !/^\??prettify\b/.test(value) | ||||||
|           var wrapper; |                 : (nt !== 3 || /\S/.test(preceder.nodeValue))) { | ||||||
|           if (!langExtension && (wrapper = childContentWrapper(cs)) |               // Skip over white-space text nodes but not others. | ||||||
|               && "CODE" === wrapper.tagName) { |               break; | ||||||
|             langExtension = wrapper.className.match(langExtensionRe); |             } | ||||||
|  |             if (value) { | ||||||
|  |               attrs = {}; | ||||||
|  |               value.replace( | ||||||
|  |                   /\b(\w+)=([\w:.%+-]+)/g, | ||||||
|  |                 function (_, name, value) { attrs[name] = value; }); | ||||||
|  |               break; | ||||||
|  |             } | ||||||
|  |           } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|           if (langExtension) { |         var className = cs.className; | ||||||
|             langExtension = langExtension[1]; |         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 |           // make sure this is not nested in an already prettified element | ||||||
|           var nested = false; |           var nested = false; | ||||||
|           for (var p = cs.parentNode; p; p = p.parentNode) { |           for (var p = cs.parentNode; p; p = p.parentNode) { | ||||||
|             if ((p.tagName === 'pre' || p.tagName === 'code' || |             var tn = p.tagName; | ||||||
|                  p.tagName === 'xmp') && |             if (preCodeXmpRe.test(tn) | ||||||
|                 p.className && p.className.indexOf('prettyprint') >= 0) { |                 && p.className && prettyPrintRe.test(p.className)) { | ||||||
|               nested = true; |               nested = true; | ||||||
|               break; |               break; | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|           if (!nested) { |           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 |             // Look for a class like linenums or linenums:<n> where <n> is the | ||||||
|             // 1-indexed number of the first line. |             // 1-indexed number of the first line. | ||||||
|             var lineNums = cs.className.match(/\blinenums\b(?::(\d+))?/); |             var lineNums = attrs['linenums']; | ||||||
|             lineNums = lineNums |             if (!(lineNums = lineNums === 'true' || +lineNums)) { | ||||||
|                   ? lineNums[1] && lineNums[1].length ? +lineNums[1] : true |               lineNums = className.match(/\blinenums\b(?::(\d+))?/); | ||||||
|  |               lineNums = | ||||||
|  |                 lineNums | ||||||
|  |                 ? lineNums[1] && lineNums[1].length | ||||||
|  |                   ? +lineNums[1] : true | ||||||
|                 : false; |                 : false; | ||||||
|             if (lineNums) { numberLines(cs, lineNums); } |             } | ||||||
|  |             if (lineNums) { numberLines(cs, lineNums, preformatted); } | ||||||
|  |  | ||||||
|             // do the pretty printing |             // do the pretty printing | ||||||
|             prettyPrintingJob = { |             prettyPrintingJob = { | ||||||
|               langExtension: langExtension, |               langExtension: langExtension, | ||||||
|               sourceNode: cs, |               sourceNode: cs, | ||||||
|               numberLines: lineNums |               numberLines: lineNums, | ||||||
|  |               pre: preformatted | ||||||
|             }; |             }; | ||||||
|             applyDecorator(prettyPrintingJob); |             applyDecorator(prettyPrintingJob); | ||||||
|           } |           } | ||||||
| @ -1429,7 +1596,7 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|       if (k < elements.length) { |       if (k < elements.length) { | ||||||
|         // finish up in a continuation |         // finish up in a continuation | ||||||
|         setTimeout(doWork, 250); |         setTimeout(doWork, 250); | ||||||
|       } else if (opt_whenDone) { |       } else if ('function' === typeof opt_whenDone) { | ||||||
|         opt_whenDone(); |         opt_whenDone(); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| @ -1437,26 +1604,11 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|     doWork(); |     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. |    * Contains functions for creating and registering new language handlers. | ||||||
|    * @type {Object} |    * @type {Object} | ||||||
|    */ |    */ | ||||||
|   window['PR'] = { |   var PR = win['PR'] = { | ||||||
|         'createSimpleLexer': createSimpleLexer, |         'createSimpleLexer': createSimpleLexer, | ||||||
|         'registerLangHandler': registerLangHandler, |         'registerLangHandler': registerLangHandler, | ||||||
|         'sourceDecorator': sourceDecorator, |         'sourceDecorator': sourceDecorator, | ||||||
| @ -1472,6 +1624,32 @@ var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|& | |||||||
|         'PR_SOURCE': PR_SOURCE, |         'PR_SOURCE': PR_SOURCE, | ||||||
|         'PR_STRING': PR_STRING, |         'PR_STRING': PR_STRING, | ||||||
|         'PR_TAG': PR_TAG, |         '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;  | ||||||
|  |     }); | ||||||
|  |   } | ||||||
| })(); | })(); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user