Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated highlight.js to latest

  • Loading branch information...
commit 907a91ceffc54364035bc58e8c968fcd5f8325f0 1 parent 48388be
@andris9 authored
Showing with 4,767 additions and 3,095 deletions.
  1. +42 −33 lib/highlight.js
  2. +8 −0 lib/vendor/highlight.js/AUTHORS.en.txt
  3. +8 −0 lib/vendor/highlight.js/AUTHORS.ru.txt
  4. +122 −0 lib/vendor/highlight.js/README.md
  5. +128 −0 lib/vendor/highlight.js/README.ru.md
  6. +437 −0 lib/vendor/highlight.js/classref.txt
  7. +1 −29 lib/vendor/highlight.js/export.html
  8. +211 −228 lib/vendor/highlight.js/highlight.js
  9. +1 −1  lib/vendor/highlight.js/highlight.pack.js
  10. +185 −203 lib/vendor/highlight.js/highlight_src.js
  11. +56 −86 lib/vendor/highlight.js/languages/1c.js
  12. +424 −437 lib/vendor/highlight.js/languages/apache.js
  13. +29 −46 lib/vendor/highlight.js/languages/avrasm.js
  14. +31 −43 lib/vendor/highlight.js/languages/axapta.js
  15. +49 −71 lib/vendor/highlight.js/languages/bash.js
  16. +25 −0 lib/vendor/highlight.js/languages/cmake.js
  17. +53 −35 lib/vendor/highlight.js/languages/cpp.js
  18. +30 −38 lib/vendor/highlight.js/languages/cs.js
  19. +100 −82 lib/vendor/highlight.js/languages/css.js
  20. +55 −71 lib/vendor/highlight.js/languages/delphi.js
  21. +58 −61 lib/vendor/highlight.js/languages/diff.js
  22. +54 −46 lib/vendor/highlight.js/languages/django.js
  23. +15 −22 lib/vendor/highlight.js/languages/dos.js
  24. +82 −0 lib/vendor/highlight.js/languages/erlang-repl.js
  25. +202 −0 lib/vendor/highlight.js/languages/erlang.js
  26. +56 −0 lib/vendor/highlight.js/languages/go.js
  27. +69 −0 lib/vendor/highlight.js/languages/haskell.js
  28. +28 −38 lib/vendor/highlight.js/languages/ini.js
  29. +40 −55 lib/vendor/highlight.js/languages/java.js
  30. +44 −44 lib/vendor/highlight.js/languages/javascript.js
  31. +77 −88 lib/vendor/highlight.js/languages/lisp.js
  32. +49 −58 lib/vendor/highlight.js/languages/lua.js
  33. +32 −46 lib/vendor/highlight.js/languages/mel.js
  34. +220 −97 lib/vendor/highlight.js/languages/nginx.js
  35. +95 −0 lib/vendor/highlight.js/languages/objectivec.js
  36. +48 −53 lib/vendor/highlight.js/languages/parser3.js
  37. +125 −145 lib/vendor/highlight.js/languages/perl.js
  38. +49 −50 lib/vendor/highlight.js/languages/php.js
  39. +42 −47 lib/vendor/highlight.js/languages/profile.js
  40. +68 −74 lib/vendor/highlight.js/languages/python.js
  41. +34 −46 lib/vendor/highlight.js/languages/renderman.js
  42. +184 −178 lib/vendor/highlight.js/languages/ruby.js
  43. +56 −62 lib/vendor/highlight.js/languages/scala.js
  44. +46 −46 lib/vendor/highlight.js/languages/smalltalk.js
  45. +86 −104 lib/vendor/highlight.js/languages/sql.js
  46. +56 −55 lib/vendor/highlight.js/languages/tex.js
  47. +76 −0 lib/vendor/highlight.js/languages/vala.js
  48. +18 −27 lib/vendor/highlight.js/languages/vbscript.js
  49. +31 −0 lib/vendor/highlight.js/languages/vhdl.js
  50. +104 −0 lib/vendor/highlight.js/languages/xml.js
  51. +3 −3 lib/vendor/highlight.js/styles/ascetic.css
  52. +9 −17 lib/vendor/highlight.js/styles/brown_paper.css
  53. +9 −15 lib/vendor/highlight.js/styles/dark.css
  54. +17 −19 lib/vendor/highlight.js/styles/default.css
  55. +7 −12 lib/vendor/highlight.js/styles/far.css
  56. +6 −5 lib/vendor/highlight.js/styles/github.css
  57. +3 −2 lib/vendor/highlight.js/styles/idea.css
  58. +6 −8 lib/vendor/highlight.js/styles/ir_black.css
  59. +8 −7 lib/vendor/highlight.js/styles/magula.css
  60. +9 −15 lib/vendor/highlight.js/styles/school_book.css
  61. +8 −9 lib/vendor/highlight.js/styles/sunburst.css
  62. +11 −2 lib/vendor/highlight.js/styles/vs.css
  63. +8 −14 lib/vendor/highlight.js/styles/zenburn.css
  64. +523 −121 lib/vendor/highlight.js/test.html
  65. +1 −1  package.json
View
75 lib/highlight.js
@@ -3,41 +3,50 @@
/* NB! You also need to include a CSS file from vendor/highlight.js/styles */
// load syntax highlighter
-var hljs = require("./vendor/highlight.js/highlight.js").hljs;
+var hljs = require("./vendor/highlight.js/highlight").hljs;
// load langs
-require("./vendor/highlight.js/languages/cs.js").lang(hljs);
-require("./vendor/highlight.js/languages/python.js").lang(hljs);
-require("./vendor/highlight.js/languages/mel.js").lang(hljs);
-require("./vendor/highlight.js/languages/perl.js").lang(hljs);
-require("./vendor/highlight.js/languages/axapta.js").lang(hljs);
-require("./vendor/highlight.js/languages/cpp.js").lang(hljs);
-require("./vendor/highlight.js/languages/sql.js").lang(hljs);
-require("./vendor/highlight.js/languages/smalltalk.js").lang(hljs);
-require("./vendor/highlight.js/languages/profile.js").lang(hljs);
-require("./vendor/highlight.js/languages/bash.js").lang(hljs);
-require("./vendor/highlight.js/languages/lua.js").lang(hljs);
-require("./vendor/highlight.js/languages/html-xml.js").lang(hljs);
-require("./vendor/highlight.js/languages/renderman.js").lang(hljs);
-require("./vendor/highlight.js/languages/1c.js").lang(hljs);
-require("./vendor/highlight.js/languages/delphi.js").lang(hljs);
-require("./vendor/highlight.js/languages/dos.js").lang(hljs);
-require("./vendor/highlight.js/languages/django.js").lang(hljs);
-require("./vendor/highlight.js/languages/vbscript.js").lang(hljs);
-require("./vendor/highlight.js/languages/ini.js").lang(hljs);
-require("./vendor/highlight.js/languages/apache.js").lang(hljs);
-require("./vendor/highlight.js/languages/nginx.js").lang(hljs);
-require("./vendor/highlight.js/languages/ruby.js").lang(hljs);
-require("./vendor/highlight.js/languages/css.js").lang(hljs);
-require("./vendor/highlight.js/languages/lisp.js").lang(hljs);
-require("./vendor/highlight.js/languages/java.js").lang(hljs);
-require("./vendor/highlight.js/languages/javascript.js").lang(hljs);
-require("./vendor/highlight.js/languages/php.js").lang(hljs);
-require("./vendor/highlight.js/languages/diff.js").lang(hljs);
-require("./vendor/highlight.js/languages/avrasm.js").lang(hljs);
-require("./vendor/highlight.js/languages/parser3.js").lang(hljs);
-require("./vendor/highlight.js/languages/scala.js").lang(hljs);
-require("./vendor/highlight.js/languages/tex.js").lang(hljs);
+require("./vendor/highlight.js/languages/xml")(hljs);
+require("./vendor/highlight.js/languages/1c")(hljs);
+require("./vendor/highlight.js/languages/apache")(hljs);
+require("./vendor/highlight.js/languages/avrasm")(hljs);
+require("./vendor/highlight.js/languages/axapta")(hljs);
+require("./vendor/highlight.js/languages/bash")(hljs);
+require("./vendor/highlight.js/languages/cmake")(hljs);
+require("./vendor/highlight.js/languages/cpp")(hljs);
+require("./vendor/highlight.js/languages/cs")(hljs);
+require("./vendor/highlight.js/languages/css")(hljs);
+require("./vendor/highlight.js/languages/delphi")(hljs);
+require("./vendor/highlight.js/languages/diff")(hljs);
+require("./vendor/highlight.js/languages/django")(hljs);
+require("./vendor/highlight.js/languages/dos")(hljs);
+require("./vendor/highlight.js/languages/erlang-repl")(hljs);
+require("./vendor/highlight.js/languages/erlang")(hljs);
+require("./vendor/highlight.js/languages/go")(hljs);
+require("./vendor/highlight.js/languages/haskell")(hljs);
+require("./vendor/highlight.js/languages/ini")(hljs);
+require("./vendor/highlight.js/languages/java")(hljs);
+require("./vendor/highlight.js/languages/javascript")(hljs);
+require("./vendor/highlight.js/languages/lisp")(hljs);
+require("./vendor/highlight.js/languages/lua")(hljs);
+require("./vendor/highlight.js/languages/mel")(hljs);
+require("./vendor/highlight.js/languages/nginx")(hljs);
+require("./vendor/highlight.js/languages/objectivec")(hljs);
+require("./vendor/highlight.js/languages/parser3")(hljs);
+require("./vendor/highlight.js/languages/perl")(hljs);
+require("./vendor/highlight.js/languages/php")(hljs);
+require("./vendor/highlight.js/languages/profile")(hljs);
+require("./vendor/highlight.js/languages/python")(hljs);
+require("./vendor/highlight.js/languages/renderman")(hljs);
+require("./vendor/highlight.js/languages/ruby")(hljs);
+require("./vendor/highlight.js/languages/scala")(hljs);
+require("./vendor/highlight.js/languages/smalltalk")(hljs);
+require("./vendor/highlight.js/languages/sql")(hljs);
+require("./vendor/highlight.js/languages/tex")(hljs);
+require("./vendor/highlight.js/languages/vala")(hljs);
+require("./vendor/highlight.js/languages/vbscript")(hljs);
+require("./vendor/highlight.js/languages/vhdl")(hljs);
+
/**
View
8 lib/vendor/highlight.js/AUTHORS.en.txt
@@ -35,3 +35,11 @@ Contributors:
- Vladimir Moskva <vladmos@gmail.com>
- Loren Segal <lsegal@soen.ca>
- Andrew Fedorov <dmmdrs@mail.ru>
+- Igor Kalnitsky <igor.kalnitsky@gmail.com>
+- Jeremy Hull <sourdrums@gmail.com>
+- Valerii Hiora <valerii.hiora@gmail.com>
+- Nikolay Zakharov <nikolay.desh@gmail.com>
+- Dmitry Kovega <arhibot@gmail.com>
+- Sergey Ignatov <sergey@ignatov.spb.su>
+- Antono Vasiljev <self@antono.info>
+- Stephan Kountso <steplg@gmail.com>
View
8 lib/vendor/highlight.js/AUTHORS.ru.txt
@@ -35,3 +35,11 @@ URL: http://softwaremaniacs.org/soft/highlight/
- Владимир Москва <vladmos@gmail.com>
- Лорен Сегал <lsegal@soen.ca>
- Андрей Фёдоров <dmmdrs@mail.ru>
+- Игорь Кальницкий <igor.kalnitsky@gmail.com>
+- Джереми Халл <sourdrums@gmail.com>
+- Валерий Хиора <valerii.hiora@gmail.com>
+- Николай Захаров <nikolay.desh@gmail.com>
+- Дмитрий Ковега <arhibot@gmail.com>
+- Сергей Игнатов <sergey@ignatov.spb.su>
+- Антоно Васильев <self@antono.info>
+- Степан Кунцьо <steplg@gmail.com>
View
122 lib/vendor/highlight.js/README.md
@@ -0,0 +1,122 @@
+# Highlight.js
+
+Highlight.js highlights syntax in code examples on blogs, forums and
+in fact on any web pages. It's very easy to use because it works
+automatically: finds blocks of code, detects a language, highlights it.
+
+Autodetection can be fine tuned when it fails by itself (see "Heuristics").
+
+
+## Installation and usage
+
+Downloaded package includes file "highlight.pack.js" which is a full compressed
+version of the library intended to use in production. All uncompressed source
+files are also available, feel free to look into them!
+
+The script is installed by linking to a single file and making a single
+initialization call:
+
+ <script type="text/javascript" src="highlight.pack.js"></script>
+ <script type="text/javascript">
+ hljs.initHighlightingOnLoad();
+ </script>
+
+Also you can replaces TAB ('\x09') characters used for indentation in your code
+with some fixed number of spaces or with a `<span>` to set them special styling:
+
+ <script type="text/javascript">
+ hljs.tabReplace = ' '; // 4 spaces
+ // ... or
+ hljs.tabReplace = '<span class="indent">\t</span>';
+
+ hljs.initHighlightingOnLoad();
+ </script>
+
+Then the script looks in your page for fragments `<pre><code>...</code></pre>`
+that are used traditionally to mark up code examples. Their content is
+marked up by logical pieces with defined class names.
+
+
+### Custom initialization
+
+If you use different markup for code blocks you can initialize them manually
+with `highlightBlock(code, tabReplace)` function. It takes a DOM element
+containing the code to highlight and optionally a string with which to replace
+TAB characters.
+
+Initialization using for example jQuery might look like this:
+
+ $(document).ready(function() {
+ $('pre code').each(function(i, e) {hljs.highlightBlock(e, ' ')});
+ });
+
+If your code container relies on `<br>` tags instead of line breaks (i.e. if
+it's not `<pre>`) pass `true` into third parameter of `highlightBlock`:
+
+ $('div.code').each(function(i, e) {hljs.highlightBlock(e, null, true)});
+
+
+### Styling
+
+Elements of code marked up with classes can be styled as desired:
+
+ .comment {
+ color: gray;
+ }
+
+ .keyword {
+ font-weight: bold;
+ }
+
+ .python .string {
+ color: blue;
+ }
+
+ .html .atribute .value {
+ color: green;
+ }
+
+Highligt.js comes with several style themes located in "styles" directory that
+can be used directly or as a base for your own experiments.
+
+For full reference list of classes see [classref.txt][cr].
+
+[cr]: http://github.com/isagalaev/highlight.js/blob/master/classref.txt
+
+
+## Export
+
+File export.html contains a little program that shows and allows to copy and paste
+an HTML code generated by the highlighter for any code snippet. This can be useful
+in situations when one can't use the script itself on a site.
+
+
+## Heuristics
+
+Autodetection of a code's language is done with a simple heuristics:
+the program tries to highlight a fragment with all available languages and
+counts all syntactic structures that it finds along the way. The language
+with greatest count wins.
+
+This means that in short fragments the probability of an error is high
+(and it really happens sometimes). In this cases you can set the fragment's
+language explicitly by assigning a class to the `<code>` element:
+
+ <pre><code class="html">...</code></pre>
+
+You can use class names recommended in HTML5: "language-html",
+"language-php". Classes also can be assigned to the `<pre>` element.
+
+To disable highlighting of a fragment altogether use "no-highlight" class:
+
+ <pre><code class="no-highlight">...</code></pre>
+
+
+## Meta
+
+- Version: 6.0
+- URL: http://softwaremaniacs.org/soft/highlight/en/
+- Author: Ivan Sagalaev (<Maniac@SoftwareManiacs.Org>)
+
+For the license terms see LICENSE files.
+For the list of contributors see AUTHORS.en.txt file.
View
128 lib/vendor/highlight.js/README.ru.md
@@ -0,0 +1,128 @@
+# Highlight.js
+
+Highlight.js нужен для подсветки синтаксиса в примерах кода в блогах,
+форумах и вообще на любых веб-страницах. Пользоваться им очень просто,
+потому что работает он автоматически: сам находит блоки кода, сам
+определяет язык, сам подсвечивает.
+
+Автоопределением языка можно управлять, когда оно не справляется само (см.
+дальше "Эвристика").
+
+
+## Подключение и использование
+
+В загруженном архиве лежит файл "highlight.pack.js" -- полная сжатая версия
+библиотеки для работы. Все несжатые исходные файлы также есть в пакете, поэтому
+не стесняйтесь в них смотреть!
+
+Скрипт подключается одним файлом и одним вызовом инициализирующей
+функции:
+
+ <script type="text/javascript" src="highlight.pack.js"></script>
+ <script type="text/javascript">
+ hljs.initHighlightingOnLoad();
+ </script>
+
+Также вы можете заменить символы TAB ('\x09'), используемые для отступов, на
+фиксированное количество пробелов или на отдельный `<span>`, чтобы задать ему
+какой-нибудь специальный стиль:
+
+ <script type="text/javascript">
+ hljs.tabReplace = ' '; // 4 spaces
+ // ... or
+ hljs.tabReplace = '<span class="indent">\t</span>';
+
+ hljs.initHighlightingOnLoad();
+ </script>
+
+Дальше скрипт ищет на странице конструкции `<pre><code>...</code></pre>`,
+которые традиционно используются для написания кода, и код в них
+размечается на куски, помеченные разными значениями классов.
+
+
+### Инициализация вручную
+
+Если вы используете другие теги для блоков кода, вы можете инициализировать их
+явно с помощью функции `highlightBlock(code, tabReplace)`. Она принимает
+DOM-элемент с текстом расцвечиваемого кода и опционально - строчку для замены
+символов TAB.
+
+Например с использованием jQuery код инициализации может выглядеть так:
+
+ $(document).ready(function() {
+ $('pre code').each(function(i, e) {hljs.highlightBlock(e, ' ')});
+ });
+
+Если ваш блок кода использует `<br>` вместо переводов строки (т.е. если это не
+`<pre>`), передайте `true` третьим параметром в `highlightBlock`:
+
+ $('div.code').each(function(i, e) {hljs.highlightBlock(e, null, true)});
+
+
+### Выбор стилей
+
+Размеченным классами элементам кода можно задать желаемые стили например так:
+
+ .comment {
+ color: gray;
+ }
+
+ .keyword {
+ font-weight: bold;
+ }
+
+ .python .string {
+ color: blue;
+ }
+
+ .html .atribute .value {
+ color: green;
+ }
+
+В комплекте с highlight.js идут несколько стилевых тем в директории styles,
+которые можно использовать напрямую или как основу для собственных экспериментов.
+
+Полный список классов приведён в файле [crossref.txt][cr].
+
+[cr]: http://github.com/isagalaev/highlight.js/blob/master/classref.txt
+
+
+## Экспорт
+
+В файле export.html находится небольшая программка, которая показывает и дает
+скопировать непосредственно HTML-код подсветки для любого заданного фрагмента кода.
+Это может понадобится например на сайте, на котором нельзя подключить сам скрипт
+highlight.js.
+
+
+## Эвристика
+
+Определение языка, на котором написан фрагмент, делается с помощью
+довольно простой эвристики: программа пытается расцветить фрагмент всеми
+языками подряд, и для каждого языка считает количество подошедших
+синтаксически конструкций и ключевых слов. Для какого языка нашлось больше,
+тот и выбирается.
+
+Это означает, что в коротких фрагментах высока вероятность ошибки, что
+периодически и случается. Чтобы указать язык фрагмента явно, надо написать
+его название в виде класса к элементу `<code>`:
+
+ <pre><code class="html">...</code></pre>
+
+Можно использовать рекомендованные в HTML5 названия классов:
+"language-html", "language-php". Также можно назначать классы на элемент
+`<pre>`.
+
+Чтобы запретить расцветку фрагмента вообще, используется класс "no-highlight":
+
+ <pre><code class="no-highlight">...</code></pre>
+
+
+## Координаты
+
+- Версия: 6.0
+- URL: http://softwaremaniacs.org/soft/highlight/
+- Автор: Иван Сагалаев (<Maniac@SoftwareManiacs.Org>)
+
+Лицензионное соглашение читайте в файле LICENSE.
+Список соавторов читайте в файле AUTHORS.ru.txt
View
437 lib/vendor/highlight.js/classref.txt
@@ -0,0 +1,437 @@
+This is a full list of available classes corresponding to languages'
+syntactic structures. The parentheses after language name contain identifiers
+used as class names in `<code>` element.
+
+Python ("python"):
+
+ keyword keyword
+ built_in built-in objects (None, False, True and Ellipsis)
+ number number
+ string string (of any type)
+ comment comment
+ decorator @-decorator for functions
+ function function header "def some_name(...):"
+ class class header "class SomeName(...):"
+ title name of a function or a class inside a header
+ params everything inside parentheses in a function's or class' header
+
+Python profiler results ("profile"):
+
+ number number
+ string string
+ builtin builtin function entry
+ filename filename in an entry
+ summary profiling summary
+ header header of table of results
+ keyword column header
+ function function name in an entry (including parentheses)
+ title actual name of a function in an entry (excluding parentheses)
+
+Ruby ("ruby"):
+
+ keyword keyword
+ string string
+ subst in-string substitution (#{...})
+ comment comment
+ yardoctag YARD tag
+ function function header "def some_name(...):"
+ class class header "class SomeName(...):"
+ title name of a function or a class inside a header
+ parent name of a parent class
+ symbol symbol
+ instancevar instance variable
+
+Perl ("perl"):
+
+ keyword keyword
+ comment comment
+ number number
+ string string
+ regexp regular expression
+ sub subroutine header (from "sub" till "{")
+ variable variable starting with "$", "%", "@"
+ operator operator
+ pod plain old doc
+
+PHP ("php"):
+
+ keyword keyword
+ number number
+ string string (of any type)
+ comment comment
+ phpdoc phpdoc params in comments
+ variable variable starting with "$"
+ preprocessor preprocessor marks: "<?php" and "?>"
+
+Scala ("scala"):
+
+ keyword keyword
+ number number
+ string string
+ comment comment
+ annotaion annotation
+ javadoc javadoc comment
+ javadoctag @-tag in javadoc
+ class class header
+ title class name inside a header
+ params everything in parentheses inside a class header
+ inheritance keywords "extends" and "with" inside class header
+
+Go language ("go"):
+ comment comment
+ string string constant
+ number number
+ keyword language keywords
+ constant true false nil iota
+ typename built-in plain types (int, string etc.)
+ built_in built-in functions
+
+XML ("xml"):
+
+ tag any tag from "<" till ">"
+ comment comment
+ pi processing instruction (<? ... ?>)
+ cdata CDATA section
+ attribute attribute
+ value attribute's value
+
+HTML ("html"):
+
+ keyword HTML tag
+ tag any tag from "<" till ">"
+ comment comment
+ doctype <!DOCTYPE ... > declaration
+ attribute tag's attribute with or without value
+ value attribute's value
+
+CSS ("css"):
+
+ tag HTML tag in selectors
+ id #some_name in selectors
+ class .some_name in selectors
+ at_rule @-rule till first "{" or ";"
+ attr_selector attribute selector (square brackets in a[href^=http://])
+ pseudo pseudo classes and elemens (:after, ::after etc.)
+ comment comment
+ rules everything from "{" till "}"
+ property property name inside a rule
+ value property value inside a rule, from ":" till ";" or
+ till the end of rule block
+ number number within a value
+ string string within a value
+ hexcolor hex color (#FFFFFF) within a value
+ function CSS function within a value
+ params everything between "(" and ")" within a function
+ important "!important" symbol
+
+Django ("django"):
+
+ keyword HTML tag in HTML, default tags and default filters in templates
+ tag any tag from "<" till ">"
+ comment comment
+ doctype <!DOCTYPE ... > declaration
+ attribute tag's attribute with or withou value
+ value attribute's value
+ template_tag template tag {% .. %}
+ variable template variable {{ .. }}
+ template_comment template comment, both {# .. #} and {% comment %}
+ filter filter from "|" till the next filter or the end of tag
+ argument filter argument
+
+Javascript ("javascript"):
+
+ keyword keyword
+ comment comment
+ number number
+ literal special literal: "true", "false" and "null"
+ string string
+ regexp regular expression
+ function header of a function
+ title name of a function inside a header
+ params everything inside parentheses in a function's header
+
+VBScript ("vbscript"):
+
+ keyword keyword
+ number number
+ string string
+ comment comment
+ built_in built-in function
+
+Lua ("lua"):
+
+ keyword keyword
+ number number
+ string string
+ comment comment
+ built_in built-in operator
+ function header of a function
+ title name of a function inside a header
+ params everything inside parentheses in a function's header
+ long_brackets multiline string in [=[ .. ]=]
+
+Delphi ("delphi"):
+
+ keyword keyword
+ comment comment (of any type)
+ number number
+ string string
+ function header of a function, procedure, constructor and destructor
+ title name of a function, procedure, constructor or destructor
+ inside a header
+ params everything inside parentheses in a function's header
+ class class' body from "= class" till "end;"
+
+Java ("java"):
+
+ keyword keyword
+ number number
+ string string
+ comment commment
+ annotaion annotation
+ javadoc javadoc comment
+ class class header from "class" till "{"
+ title class name inside a header
+ params everything in parentheses inside a class header
+ inheritance keywords "extends" and "implements" inside class header
+
+C++ ("cpp"):
+
+ keyword keyword
+ number number
+ string string and character
+ comment comment
+ preprocessor preprocessor directive
+ stl_container instantiation of STL containers ("vector<...>")
+
+Objective C ("objectivec"):
+ keyword keyword
+ built_in Cocoa/Cocoa Touch constants and classes
+ number number
+ string string
+ comment comment
+ preprocessor preprocessor directive
+ class interface/implementation, protocol and forward class declaration
+
+Vala ("vala"):
+
+ keyword keyword
+ number number
+ string string
+ comment comment
+ class class definitions
+ title in class definition
+ constant ALL_UPPER_CASE
+
+C# ("cs"):
+
+ keyword keyword
+ number number
+ string string
+ comment commment
+ xmlDocTag xmldoc tag ("///", "<!--", "-->", "<..>")
+
+RenderMan RSL ("rsl"):
+
+ keyword keyword
+ number number
+ string string (including @"..")
+ comment comment
+ preprocessor preprocessor directive
+ shader sahder keywords
+ shading shading keywords
+ built_in built-in function
+
+RenderMan RIB ("rib"):
+
+ keyword keyword
+ number number
+ string string
+ comment comment
+ commands command
+
+Maya Embedded Language ("mel"):
+
+ keyword keyword
+ number number
+ string string
+ comment comment
+ variable variable
+
+SQL ("sql"):
+
+ keyword keyword (mostly SQL'92 and SQL'99)
+ number number
+ string string (of any type: "..", '..', `..`)
+ comment comment
+ aggregate aggregate function
+
+Smalltalk ("smalltalk"):
+
+ keyword keyword
+ number number
+ string string
+ comment commment
+ symbol symbol
+ array array
+ class name of a class
+ char char
+ localvars block of local variables
+
+Lisp ("lisp"):
+
+ keyword keyword
+ number number
+ string string
+ comment commment
+ variable variable
+ literal b, t and nil
+ list non-quoted list
+ title first symbol in a non-quoted list
+ body remainder of the non-quoted list
+ quoted quoted list, both "(quote .. )" and "'(..)"
+
+Ini ("ini"):
+
+ title title of a section
+ value value of a setting of any type
+ string string
+ number number
+ keyword boolean value keyword
+
+Apache ("apache"):
+
+ keyword keyword
+ number number
+ comment commment
+ literal On and Off
+ sqbracket variables in rewrites "%{..}"
+ cbracket options in rewrites "[..]"
+ tag begin and end of a configuration section
+
+Nginx ("nginx"):
+
+ keyword keyword
+ string string
+ number number
+ comment comment
+ built_in built-in constant
+ variable $-variable
+
+Diff ("diff"):
+
+ header file header
+ chunk chunk header within a file
+ addition added lines
+ deletion deleted lines
+ change changed lines
+
+DOS ("dos"):
+
+ keyword keyword
+ flow batch control keyword
+ stream DOS special files ("con", "prn", ...)
+ winutils some commands (see dos.js specifically)
+ envvar environment variables
+
+Bash ("bash"):
+
+ keyword keyword
+ string string
+ number number
+ comment comment
+ literal special literal: "true" и "false"
+ variable variable
+ shebang script interpreter header
+
+CMake ("cmake")
+
+ keyword keyword
+ number number
+ string string
+ comment commment
+ envvar $-variable
+
+Axapta ("axapta"):
+
+ keyword keyword
+ number number
+ string string
+ comment commment
+ class class header from "class" till "{"
+ title class name inside a header
+ params everything in parentheses inside a class header
+ inheritance keywords "extends" and "implements" inside class header
+ preprocessor preprocessor directive
+
+1C ("1c"):
+
+ keyword keyword
+ number number
+ date date
+ string string
+ comment commment
+ function header of function or procudure
+ title function name inside a header
+ params everything in parentheses inside a function header
+ preprocessor preprocessor directive
+
+AVR assembler ("avrasm"):
+
+ keyword keyword
+ built_in pre-defined register
+ number number
+ string string
+ comment commment
+ label label
+ preprocessor preprocessor directive
+ localvars substitution in .macro
+
+VHDL ("vhdl")
+
+ keyword keyword
+ number number
+ string string
+ comment commment
+ literal signal logical value
+
+Parser3 ("parser3"):
+
+ keyword keyword
+ number number
+ comment commment
+ variable variable starting with "$"
+ preprocessor preprocessor directive
+ title user-defined name starting with "@"
+
+TeX ("tex"):
+
+ comment comment
+ number number
+ command command
+ parameter parameter
+ formula formula
+ special special symbol
+
+Haskell ("haskell"):
+
+ keyword keyword
+ built_in built-in typeclass/functions (Bool, Int)
+ number number
+ string string
+ comment comment
+ class type classes and other data types
+ title function name
+ label type class name
+
+Erlang ("erlang"):
+
+ comment comment
+ string string
+ number number
+ keyword keyword
+ record_name record access (#record_name)
+ title name of declaration function
+ variable variable (starts with capital letter or with _)
+ pp.keywords module's attribute (-attribute)
+ function_name atom or atom:atom in case of function call
View
30 lib/vendor/highlight.js/export.html
@@ -17,35 +17,7 @@
tr { vertical-align: top; }
address { margin-top: 4em; }
</style>
- <script src="highlight.js"></script>
- <script src="languages/cs.js"></script>
- <script src="languages/python.js"></script>
- <script src="languages/mel.js"></script>
- <script src="languages/perl.js"></script>
- <script src="languages/axapta.js"></script>
- <script src="languages/cpp.js"></script>
- <script src="languages/sql.js"></script>
- <script src="languages/smalltalk.js"></script>
- <script src="languages/profile.js"></script>
- <script src="languages/bash.js"></script>
- <script src="languages/html-xml.js"></script>
- <script src="languages/renderman.js"></script>
- <script src="languages/1c.js"></script>
- <script src="languages/delphi.js"></script>
- <script src="languages/dos.js"></script>
- <script src="languages/django.js"></script>
- <script src="languages/vbscript.js"></script>
- <script src="languages/ini.js"></script>
- <script src="languages/apache.js"></script>
- <script src="languages/ruby.js"></script>
- <script src="languages/css.js"></script>
- <script src="languages/lisp.js"></script>
- <script src="languages/java.js"></script>
- <script src="languages/javascript.js"></script>
- <script src="languages/php.js"></script>
- <script src="languages/diff.js"></script>
- <script src="languages/avrasm.js"></script>
- <script src="languages/parser3.js"></script>
+ <script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
View
439 lib/vendor/highlight.js/highlight.js
@@ -3,53 +3,46 @@ Syntax highlighting with language autodetection.
http://softwaremaniacs.org/soft/highlight/
*/
-this.hljs = new function() {
- var LANGUAGES = {}
- // selected_languages is used to support legacy mode of selecting languages
- // available for highlighting by passing them as arguments into
- // initHighlighting function. Currently the whole library is expected to
- // contain only those language definitions that are actually get used.
- var selected_languages = {};
+var hljs = module.exports.hljs = new function() {
/* Utility functions */
function escape(value) {
- return value.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
- }
-
- function contains(array, item) {
- if (!array)
- return false;
- for (var i = 0; i < array.length; i++)
- if (array[i] == item)
- return true;
- return false;
+ return value.replace(/&/gm, '&amp;').replace(/</gm, '&lt;');
}
function langRe(language, value, global) {
- var mode = 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '');
- return new RegExp(value, mode);
+ return RegExp(
+ value,
+ 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')
+ );
}
function findCode(pre) {
for (var i = 0; i < pre.childNodes.length; i++) {
- node = pre.childNodes[i];
+ var node = pre.childNodes[i];
if (node.nodeName == 'CODE')
return node;
if (!(node.nodeType == 3 && node.nodeValue.match(/\s+/)))
- return null;
+ break;
}
}
- function blockText(block) {
+ function blockText(block, ignoreNewLines) {
var result = '';
for (var i = 0; i < block.childNodes.length; i++)
- if (block.childNodes[i].nodeType == 3)
- result += block.childNodes[i].nodeValue;
- else if (block.childNodes[i].nodeName == 'BR')
+ if (block.childNodes[i].nodeType == 3) {
+ var chunk = block.childNodes[i].nodeValue;
+ if (ignoreNewLines)
+ chunk = chunk.replace(/\n/g, '');
+ result += chunk;
+ } else if (block.childNodes[i].nodeName == 'BR')
result += '\n';
else
result += blockText(block.childNodes[i]);
+ // Thank you, MSIE...
+ if (/MSIE [678]/.test(navigator.userAgent))
+ result = result.replace(/\r/g, '\n');
return result;
}
@@ -58,10 +51,7 @@ this.hljs = new function() {
classes = classes.concat(block.parentNode.className.split(/\s+/));
for (var i = 0; i < classes.length; i++) {
var class_ = classes[i].replace(/^language-/, '');
- if (class_ == 'no-highlight') {
- throw 'No highlight'
- }
- if (LANGUAGES[class_]) {
+ if (languages[class_] || class_ == 'no-highlight') {
return class_;
}
}
@@ -105,8 +95,24 @@ this.hljs = new function() {
if (stream1.length && stream2.length) {
if (stream1[0].offset != stream2[0].offset)
return (stream1[0].offset < stream2[0].offset) ? stream1 : stream2;
- else
- return (stream1[0].event == 'start' && stream2[0].event == 'stop') ? stream2 : stream1;
+ else {
+ /*
+ To avoid starting the stream just before it should stop the order is
+ ensured that stream1 always starts first and closes last:
+
+ if (event1 == 'start' && event2 == 'start')
+ return stream1;
+ if (event1 == 'start' && event2 == 'stop')
+ return stream2;
+ if (event1 == 'stop' && event2 == 'start')
+ return stream1;
+ if (event1 == 'stop' && event2 == 'stop')
+ return stream2;
+
+ ... which is collapsed to:
+ */
+ return stream2[0].event == 'start' ? stream1 : stream2;
+ }
} else {
return stream1.length ? stream1 : stream2;
}
@@ -124,10 +130,6 @@ this.hljs = new function() {
return result + '>';
}
- function close(node) {
- return '</' + node.nodeName.toLowerCase() + '>';
- }
-
while (stream1.length || stream2.length) {
var current = selectStream().splice(0, 1)[0];
result += escape(value.substr(processed, current.offset - processed));
@@ -140,7 +142,7 @@ this.hljs = new function() {
do {
i--;
var node = nodeStack[i];
- result += close(node);
+ result += ('</' + node.nodeName.toLowerCase() + '>');
} while (node != current.node);
nodeStack.splice(i, 1);
while (i < nodeStack.length) {
@@ -156,30 +158,13 @@ this.hljs = new function() {
/* Core highlighting function */
function highlight(language_name, value) {
- function compileSubModes(mode, language) {
- mode.sub_modes = [];
- for (var i = 0; i < mode.contains.length; i++) {
- for (var j = 0; j < language.modes.length; j++) {
- if (language.modes[j].className == mode.contains[i]) {
- mode.sub_modes[mode.sub_modes.length] = language.modes[j];
- }
- }
- }
- }
function subMode(lexem, mode) {
- if (!mode.contains) {
- return null;
- }
- if (!mode.sub_modes) {
- compileSubModes(mode, language);
- }
- for (var i = 0; i < mode.sub_modes.length; i++) {
- if (mode.sub_modes[i].beginRe.test(lexem)) {
- return mode.sub_modes[i];
+ for (var i = 0; i < mode.contains.length; i++) {
+ if (mode.contains[i].beginRe.test(lexem)) {
+ return mode.contains[i];
}
}
- return null;
}
function endOfMode(mode_index, lexem) {
@@ -199,36 +184,23 @@ this.hljs = new function() {
function compileTerminators(mode, language) {
var terminators = [];
- function addTerminator(re) {
- if (!contains(terminators, re)) {
- terminators[terminators.length] = re;
- }
+ for (var i = 0; i < mode.contains.length; i++) {
+ terminators.push(mode.contains[i].begin);
}
- if (mode.contains)
- for (var i = 0; i < language.modes.length; i++) {
- if (contains(mode.contains, language.modes[i].className)) {
- addTerminator(language.modes[i].begin);
- }
- }
-
var index = modes.length - 1;
do {
if (modes[index].end) {
- addTerminator(modes[index].end);
+ terminators.push(modes[index].end);
}
index--;
} while (modes[index + 1].endsWithParent);
if (mode.illegal) {
- addTerminator(mode.illegal);
+ terminators.push(mode.illegal);
}
- var terminator_re = '(' + terminators[0];
- for (var i = 0; i < terminators.length; i++)
- terminator_re += '|' + terminators[i];
- terminator_re += ')';
- return langRe(language, terminator_re);
+ return langRe(language, '(' + terminators.join('|') + ')', true);
}
function eatModeChunk(value, index) {
@@ -236,14 +208,12 @@ this.hljs = new function() {
if (!mode.terminators) {
mode.terminators = compileTerminators(mode, language);
}
- value = value.substr(index);
+ mode.terminators.lastIndex = index;
var match = mode.terminators.exec(value);
- if (!match)
- return [value, '', true];
- if (match.index == 0)
- return ['', match[0], false];
+ if (match)
+ return [value.substr(index, match.index - index), match[0], false];
else
- return [value.substr(0, match.index), match[0], false];
+ return [value.substr(index), '', true];
}
function keywordMatch(mode, match) {
@@ -259,15 +229,8 @@ this.hljs = new function() {
}
function processKeywords(buffer, mode) {
- if (!mode.keywords || !mode.lexems)
+ if (!mode.keywords)
return escape(buffer);
- if (!mode.lexemsRe) {
- var lexems_re = '(' + mode.lexems[0];
- for (var i = 1; i < mode.lexems.length; i++)
- lexems_re += '|' + mode.lexems[i];
- lexems_re += ')';
- mode.lexemsRe = langRe(language, lexems_re, true);
- }
var result = '';
var last_index = 0;
mode.lexemsRe.lastIndex = 0;
@@ -289,10 +252,9 @@ this.hljs = new function() {
}
function processBuffer(buffer, mode) {
- if (mode.subLanguage && selected_languages[mode.subLanguage]) {
+ if (mode.subLanguage && languages[mode.subLanguage]) {
var result = highlight(mode.subLanguage, buffer);
keyword_count += result.keyword_count;
- relevance += result.relevance;
return result.value;
} else {
return processKeywords(buffer, mode);
@@ -300,7 +262,7 @@ this.hljs = new function() {
}
function startNewMode(mode, lexem) {
- var markup = mode.noMarkup?'':'<span class="' + mode.displayClassName + '">';
+ var markup = mode.className?'<span class="' + mode.className + '">':'';
if (mode.returnBegin) {
result += markup;
mode.buffer = '';
@@ -311,7 +273,8 @@ this.hljs = new function() {
result += markup;
mode.buffer = lexem;
}
- modes[modes.length] = mode;
+ modes.push(mode);
+ relevance += mode.relevance;
}
function processModeInfo(buffer, lexem, end) {
@@ -325,13 +288,12 @@ this.hljs = new function() {
if (new_mode) {
result += processBuffer(current_mode.buffer + buffer, current_mode);
startNewMode(new_mode, lexem);
- relevance += new_mode.relevance;
return new_mode.returnBegin;
}
var end_level = endOfMode(modes.length - 1, lexem);
if (end_level) {
- var markup = current_mode.noMarkup?'':'</span>';
+ var markup = current_mode.className?'</span>':'';
if (current_mode.returnEnd) {
result += processBuffer(current_mode.buffer + buffer, current_mode) + markup;
} else if (current_mode.excludeEnd) {
@@ -340,20 +302,16 @@ this.hljs = new function() {
result += processBuffer(current_mode.buffer + buffer + lexem, current_mode) + markup;
}
while (end_level > 1) {
- markup = modes[modes.length - 2].noMarkup?'':'</span>';
+ markup = modes[modes.length - 2].className?'</span>':'';
result += markup;
end_level--;
modes.length--;
}
+ var last_ended_mode = modes[modes.length - 1];
modes.length--;
modes[modes.length - 1].buffer = '';
- if (current_mode.starts) {
- for (var i = 0; i < language.modes.length; i++) {
- if (language.modes[i].className == current_mode.starts) {
- startNewMode(language.modes[i], '');
- break;
- }
- }
+ if (last_ended_mode.starts) {
+ startNewMode(last_ended_mode.starts, '');
}
return current_mode.returnEnd;
}
@@ -362,7 +320,7 @@ this.hljs = new function() {
throw 'Illegal';
}
- var language = LANGUAGES[language_name];
+ var language = languages[language_name];
var modes = [language.defaultMode];
var relevance = 0;
var keyword_count = 0;
@@ -381,6 +339,7 @@ this.hljs = new function() {
if(modes.length > 1)
throw 'Illegal';
return {
+ language: language_name,
relevance: relevance,
keyword_count: keyword_count,
value: result
@@ -388,6 +347,7 @@ this.hljs = new function() {
} catch (e) {
if (e == 'Illegal') {
return {
+ language: null,
relevance: 0,
keyword_count: 0,
value: escape(value)
@@ -401,53 +361,51 @@ this.hljs = new function() {
/* Initialization */
function compileModes() {
- for (var i in LANGUAGES) {
- if (!LANGUAGES.hasOwnProperty(i))
- continue;
- var language = LANGUAGES[i];
- for (var j = 0; j < language.modes.length; j++) {
- var mode = language.modes[j];
- if (mode.begin)
- mode.beginRe = langRe(language, '^' + mode.begin);
+
+ function compileMode(mode, language, is_default) {
+ if (mode.compiled)
+ return;
+
+ if (!is_default) {
+ mode.beginRe = langRe(language, mode.begin ? mode.begin : '\\B|\\b');
+ if (!mode.end && !mode.endsWithParent)
+ mode.end = '\\B|\\b'
if (mode.end)
- mode.endRe = langRe(language, '^' + mode.end);
- if (mode.illegal)
- mode.illegalRe = langRe(language, '^(?:' + mode.illegal + ')');
- language.defaultMode.illegalRe = langRe(language, '^(?:' + language.defaultMode.illegal + ')');
- if (mode.relevance == undefined) {
- mode.relevance = 1;
- }
- if (!mode.displayClassName) {
- mode.displayClassName = mode.className;
- }
+ mode.endRe = langRe(language, mode.end);
+ }
+ if (mode.illegal)
+ mode.illegalRe = langRe(language, mode.illegal);
+ if (mode.relevance == undefined)
+ mode.relevance = 1;
+ if (mode.keywords)
+ mode.lexemsRe = langRe(language, mode.lexems || hljs.IDENT_RE, true);
+ for (var key in mode.keywords) {
+ if (!mode.keywords.hasOwnProperty(key))
+ continue;
+ if (mode.keywords[key] instanceof Object)
+ mode.keywordGroups = mode.keywords;
+ else
+ mode.keywordGroups = {'keyword': mode.keywords};
+ break;
}
- }
- }
-
- function compileKeywords() {
-
- function compileModeKeywords(mode) {
- if (!mode.keywordGroups) {
- for (var key in mode.keywords) {
- if (!mode.keywords.hasOwnProperty(key))
- continue;
- if (mode.keywords[key] instanceof Object)
- mode.keywordGroups = mode.keywords;
- else
- mode.keywordGroups = {'keyword': mode.keywords};
- break;
- }
+ if (!mode.contains) {
+ mode.contains = [];
+ }
+ // compiled flag is set before compiling submodes to avoid self-recursion
+ // (see lisp where quoted_list contains quoted_list)
+ mode.compiled = true;
+ for (var i = 0; i < mode.contains.length; i++) {
+ compileMode(mode.contains[i], language, false);
+ }
+ if (mode.starts) {
+ compileMode(mode.starts, language, false);
}
}
- for (var i in LANGUAGES) {
- if (!LANGUAGES.hasOwnProperty(i))
+ for (var i in languages) {
+ if (!languages.hasOwnProperty(i))
continue;
- var language = LANGUAGES[i];
- compileModeKeywords(language.defaultMode);
- for (var j = 0; j < language.modes.length; j++) {
- compileModeKeywords(language.modes[j]);
- }
+ compileMode(languages[i].defaultMode, languages[i], true);
}
}
@@ -456,107 +414,119 @@ this.hljs = new function() {
return;
initialize.called = true;
compileModes();
- compileKeywords();
- selected_languages = LANGUAGES;
}
/* Public library functions */
- function highlightBlock(block, tabReplace) {
+ function highlightBlock(block, tabReplace, useBR) {
initialize();
- try {
- var text = blockText(block);
- var language = blockLanguage(block);
- } catch (e) {
- if (e == 'No highlight')
+ var text = blockText(block, useBR);
+ var language = blockLanguage(block);
+ if (language == 'no-highlight')
return;
- }
-
if (language) {
- var result = highlight(language, text).value;
+ var result = highlight(language, text);
} else {
- var max_relevance = 0;
- for (var key in selected_languages) {
- if (!selected_languages.hasOwnProperty(key))
+ var result = {language: '', keyword_count: 0, relevance: 0, value: escape(text)};
+ var second_best = result;
+ for (var key in languages) {
+ if (!languages.hasOwnProperty(key))
continue;
- var lang_result = highlight(key, text);
- var relevance = lang_result.keyword_count + lang_result.relevance;
- if (relevance > max_relevance) {
- max_relevance = relevance;
- var result = lang_result.value;
- language = key;
+ var current = highlight(key, text);
+ if (current.keyword_count + current.relevance > second_best.keyword_count + second_best.relevance) {
+ second_best = current;
+ }
+ if (current.keyword_count + current.relevance > result.keyword_count + result.relevance) {
+ second_best = result;
+ result = current;
}
}
}
- if (result) {
- var class_name = block.className;
- if (!class_name.match(language)) {
- class_name += ' ' + language;
- }
- var original = nodeStream(block);
- if (original.length) {
- var pre = document.createElement('pre');
- pre.innerHTML = result;
- result = mergeStreams(original, nodeStream(pre), text);
- }
- if (tabReplace) {
- result = result.replace(/^((<[^>]+>|\t)+)/gm, function(match, p1, offset, s) {
- return p1.replace(/\t/g, tabReplace);
- })
- }
- // See these 4 lines? This is IE's notion of "block.innerHTML = result". Love this browser :-/
+ var class_name = block.className;
+ if (!class_name.match(result.language)) {
+ class_name = class_name ? (class_name + ' ' + result.language) : result.language;
+ }
+ var original = nodeStream(block);
+ if (original.length) {
+ var pre = document.createElement('pre');
+ pre.innerHTML = result.value;
+ result.value = mergeStreams(original, nodeStream(pre), text);
+ }
+ if (tabReplace) {
+ result.value = result.value.replace(/^((<[^>]+>|\t)+)/gm, function(match, p1, offset, s) {
+ return p1.replace(/\t/g, tabReplace);
+ })
+ }
+ if (useBR) {
+ result.value = result.value.replace(/\n/g, '<br>');
+ }
+ if (/MSIE [678]/.test(navigator.userAgent) && block.tagName == 'CODE' && block.parentNode.tagName == 'PRE') {
+ // This is for backwards compatibility only. IE needs this strange
+ // hack becasue it cannot just cleanly replace <code> block contents.
+ var pre = block.parentNode;
var container = document.createElement('div');
- container.innerHTML = '<pre><code class="' + class_name + '">' + result + '</code></pre>';
- var environment = block.parentNode.parentNode;
- environment.replaceChild(container.firstChild, block.parentNode);
+ container.innerHTML = '<pre><code>' + result.value + '</code></pre>';
+ block = container.firstChild.firstChild;
+ container.firstChild.className = pre.className;
+ pre.parentNode.replaceChild(container.firstChild, pre);
+ } else {
+ block.innerHTML = result.value;
+ }
+ block.className = class_name;
+ block.dataset = {};
+ block.dataset.result = {
+ language: result.language,
+ kw: result.keyword_count,
+ re: result.relevance
+ };
+ if (second_best && second_best.language) {
+ block.dataset.second_best = {
+ language: second_best.language,
+ kw: second_best.keyword_count,
+ re: second_best.relevance
+ };
}
}
-
- function highlightText(text, tabReplace) {
+
+ function highlightText(block, tabReplace, useBR) {
initialize();
- var language = undefined,
- max_relevance = key = 0,
- lang_result, relevance, result;
-
- for (key in selected_languages) {
- if (!selected_languages.hasOwnProperty(key))
+ var text = block;
+ var language;
+
+ var result = {language: '', keyword_count: 0, relevance: 0, value: escape(text)};
+ var second_best = result;
+ for (var key in languages) {
+ if (!languages.hasOwnProperty(key))
continue;
- lang_result = highlight(key, text);
- relevance = lang_result.keyword_count + lang_result.relevance;
- if (relevance > max_relevance) {
- max_relevance = relevance;
- result = lang_result.value;
- language = key;
+ var current = highlight(key, text);
+ if (current.keyword_count + current.relevance > second_best.keyword_count + second_best.relevance) {
+ second_best = current;
+ }
+ if (current.keyword_count + current.relevance > result.keyword_count + result.relevance) {
+ second_best = result;
+ result = current;
}
}
- if (result) {
- if (tabReplace) {
- result = result.replace(/^((<[^>]+>|\t)+)/gm, function(match, p1, offset, s) {
- return p1.replace(/\t/g, tabReplace);
- })
- }
- return result;
+ if (tabReplace) {
+ result.value = result.value.replace(/^((<[^>]+>|\t)+)/gm, function(match, p1, offset, s) {
+ return p1.replace(/\t/g, tabReplace);
+ })
}
- return text;
+ if (useBR) {
+ result.value = result.value.replace(/\n/g, '<br>');
+ }
+ return result.value;
}
-
function initHighlighting() {
if (initHighlighting.called)
return;
initHighlighting.called = true;
initialize();
- if (arguments.length) {
- for (var i = 0; i < arguments.length; i++) {
- if (LANGUAGES[arguments[i]]) {
- selected_languages[arguments[i]] = LANGUAGES[arguments[i]];
- }
- }
- }
var pres = document.getElementsByTagName('pre');
for (var i = 0; i < pres.length; i++) {
var code = findCode(pres[i]);
@@ -577,13 +547,15 @@ this.hljs = new function() {
window.onload = handler;
}
+ var languages = {}; // a shortcut to avoid writing "this." everywhere
+
/* Interface definition */
- this.LANGUAGES = LANGUAGES;
+ this.LANGUAGES = languages;
this.initHighlightingOnLoad = initHighlightingOnLoad;
this.highlightBlock = highlightBlock;
- this.highlightText = highlightText;
this.initHighlighting = initHighlighting;
+ this.highlightText = highlightText;
// Common regexps
this.IDENT_RE = '[a-zA-Z][a-zA-Z0-9_]*';
@@ -593,29 +565,26 @@ this.hljs = new function() {
this.RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';
// Common modes
+ this.BACKSLASH_ESCAPE = {
+ begin: '\\\\.', relevance: 0
+ };
this.APOS_STRING_MODE = {
className: 'string',
begin: '\'', end: '\'',
illegal: '\\n',
- contains: ['escape'],
+ contains: [this.BACKSLASH_ESCAPE],
relevance: 0
};
this.QUOTE_STRING_MODE = {
className: 'string',
begin: '"', end: '"',
illegal: '\\n',
- contains: ['escape'],
- relevance: 0
- };
- this.BACKSLASH_ESCAPE = {
- className: 'escape',
- begin: '\\\\.', end: '^', noMarkup: true,
+ contains: [this.BACKSLASH_ESCAPE],
relevance: 0
};
this.C_LINE_COMMENT_MODE = {
className: 'comment',
- begin: '//', end: '$',
- relevance: 0
+ begin: '//', end: '$'
};
this.C_BLOCK_COMMENT_MODE = {
className: 'comment',
@@ -625,11 +594,25 @@ this.hljs = new function() {
className: 'comment',
begin: '#', end: '$'
};
+ this.NUMBER_MODE = {
+ className: 'number',
+ begin: this.NUMBER_RE,
+ relevance: 0
+ };
this.C_NUMBER_MODE = {
className: 'number',
- begin: this.C_NUMBER_RE, end: '^',
+ begin: this.C_NUMBER_RE,
relevance: 0
};
-}();
-// var initHighlightingOnLoad = hljs.initHighlightingOnLoad;
+ // Utility functions
+ this.inherit = function(parent, obj) {
+ var result = {}
+ for (var key in parent)
+ result[key] = parent[key];
+ if (obj)
+ for (var key in obj)
+ result[key] = obj[key];
+ return result;
+ }
+}();
View
2  lib/vendor/highlight.js/highlight.pack.js
1 addition, 1 deletion not shown
View
388 lib/vendor/highlight.js/highlight_src.js
@@ -4,52 +4,45 @@ http://softwaremaniacs.org/soft/highlight/
*/
var hljs = new function() {
- var LANGUAGES = {}
- // selected_languages is used to support legacy mode of selecting languages
- // available for highlighting by passing them as arguments into
- // initHighlighting function. Currently the whole library is expected to
- // contain only those language definitions that are actually get used.
- var selected_languages = {};
/* Utility functions */
function escape(value) {
- return value.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
- }
-
- function contains(array, item) {
- if (!array)
- return false;
- for (var i = 0; i < array.length; i++)
- if (array[i] == item)
- return true;
- return false;
+ return value.replace(/&/gm, '&amp;').replace(/</gm, '&lt;');
}
function langRe(language, value, global) {
- var mode = 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '');
- return new RegExp(value, mode);
+ return RegExp(
+ value,
+ 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')
+ );
}
function findCode(pre) {
for (var i = 0; i < pre.childNodes.length; i++) {
- node = pre.childNodes[i];
+ var node = pre.childNodes[i];
if (node.nodeName == 'CODE')
return node;
if (!(node.nodeType == 3 && node.nodeValue.match(/\s+/)))
- return null;
+ break;
}
}
- function blockText(block) {
+ function blockText(block, ignoreNewLines) {
var result = '';
for (var i = 0; i < block.childNodes.length; i++)
- if (block.childNodes[i].nodeType == 3)
- result += block.childNodes[i].nodeValue;
- else if (block.childNodes[i].nodeName == 'BR')
+ if (block.childNodes[i].nodeType == 3) {
+ var chunk = block.childNodes[i].nodeValue;
+ if (ignoreNewLines)
+ chunk = chunk.replace(/\n/g, '');
+ result += chunk;
+ } else if (block.childNodes[i].nodeName == 'BR')
result += '\n';
else
result += blockText(block.childNodes[i]);
+ // Thank you, MSIE...
+ if (/MSIE [678]/.test(navigator.userAgent))
+ result = result.replace(/\r/g, '\n');
return result;
}
@@ -58,10 +51,7 @@ var hljs = new function() {
classes = classes.concat(block.parentNode.className.split(/\s+/));
for (var i = 0; i < classes.length; i++) {
var class_ = classes[i].replace(/^language-/, '');
- if (class_ == 'no-highlight') {
- throw 'No highlight'
- }
- if (LANGUAGES[class_]) {
+ if (languages[class_] || class_ == 'no-highlight') {
return class_;
}
}
@@ -105,8 +95,24 @@ var hljs = new function() {
if (stream1.length && stream2.length) {
if (stream1[0].offset != stream2[0].offset)
return (stream1[0].offset < stream2[0].offset) ? stream1 : stream2;
- else
- return (stream1[0].event == 'start' && stream2[0].event == 'stop') ? stream2 : stream1;
+ else {
+ /*
+ To avoid starting the stream just before it should stop the order is
+ ensured that stream1 always starts first and closes last:
+
+ if (event1 == 'start' && event2 == 'start')
+ return stream1;
+ if (event1 == 'start' && event2 == 'stop')
+ return stream2;
+ if (event1 == 'stop' && event2 == 'start')
+ return stream1;
+ if (event1 == 'stop' && event2 == 'stop')
+ return stream2;
+
+ ... which is collapsed to:
+ */
+ return stream2[0].event == 'start' ? stream1 : stream2;
+ }
} else {
return stream1.length ? stream1 : stream2;
}
@@ -124,10 +130,6 @@ var hljs = new function() {
return result + '>';
}
- function close(node) {
- return '</' + node.nodeName.toLowerCase() + '>';
- }
-
while (stream1.length || stream2.length) {
var current = selectStream().splice(0, 1)[0];
result += escape(value.substr(processed, current.offset - processed));
@@ -140,7 +142,7 @@ var hljs = new function() {
do {
i--;
var node = nodeStack[i];
- result += close(node);
+ result += ('</' + node.nodeName.toLowerCase() + '>');
} while (node != current.node);
nodeStack.splice(i, 1);
while (i < nodeStack.length) {
@@ -156,30 +158,13 @@ var hljs = new function() {
/* Core highlighting function */
function highlight(language_name, value) {
- function compileSubModes(mode, language) {
- mode.sub_modes = [];
- for (var i = 0; i < mode.contains.length; i++) {
- for (var j = 0; j < language.modes.length; j++) {
- if (language.modes[j].className == mode.contains[i]) {
- mode.sub_modes[mode.sub_modes.length] = language.modes[j];
- }
- }
- }
- }
function subMode(lexem, mode) {
- if (!mode.contains) {
- return null;
- }
- if (!mode.sub_modes) {
- compileSubModes(mode, language);
- }
- for (var i = 0; i < mode.sub_modes.length; i++) {
- if (mode.sub_modes[i].beginRe.test(lexem)) {
- return mode.sub_modes[i];
+ for (var i = 0; i < mode.contains.length; i++) {
+ if (mode.contains[i].beginRe.test(lexem)) {
+ return mode.contains[i];
}
}
- return null;
}
function endOfMode(mode_index, lexem) {
@@ -199,36 +184,23 @@ var hljs = new function() {
function compileTerminators(mode, language) {
var terminators = [];
- function addTerminator(re) {
- if (!contains(terminators, re)) {
- terminators[terminators.length] = re;
- }
+ for (var i = 0; i < mode.contains.length; i++) {
+ terminators.push(mode.contains[i].begin);
}
- if (mode.contains)
- for (var i = 0; i < language.modes.length; i++) {
- if (contains(mode.contains, language.modes[i].className)) {
- addTerminator(language.modes[i].begin);
- }
- }
-
var index = modes.length - 1;
do {
if (modes[index].end) {
- addTerminator(modes[index].end);
+ terminators.push(modes[index].end);
}
index--;
} while (modes[index + 1].endsWithParent);
if (mode.illegal) {
- addTerminator(mode.illegal);
+ terminators.push(mode.illegal);
}
- var terminator_re = '(' + terminators[0];
- for (var i = 0; i < terminators.length; i++)
- terminator_re += '|' + terminators[i];
- terminator_re += ')';
- return langRe(language, terminator_re);
+ return langRe(language, '(' + terminators.join('|') + ')', true);
}
function eatModeChunk(value, index) {
@@ -236,14 +208,12 @@ var hljs = new function() {
if (!mode.terminators) {
mode.terminators = compileTerminators(mode, language);
}
- value = value.substr(index);
+ mode.terminators.lastIndex = index;
var match = mode.terminators.exec(value);
- if (!match)
- return [value, '', true];
- if (match.index == 0)
- return ['', match[0], false];
+ if (match)
+ return [value.substr(index, match.index - index), match[0], false];
else
- return [value.substr(0, match.index), match[0], false];
+ return [value.substr(index), '', true];
}
function keywordMatch(mode, match) {
@@ -259,15 +229,8 @@ var hljs = new function() {
}
function processKeywords(buffer, mode) {
- if (!mode.keywords || !mode.lexems)
+ if (!mode.keywords)
return escape(buffer);
- if (!mode.lexemsRe) {
- var lexems_re = '(' + mode.lexems[0];
- for (var i = 1; i < mode.lexems.length; i++)
- lexems_re += '|' + mode.lexems[i];
- lexems_re += ')';
- mode.lexemsRe = langRe(language, lexems_re, true);
- }
var result = '';
var last_index = 0;
mode.lexemsRe.lastIndex = 0;
@@ -289,10 +252,9 @@ var hljs = new function() {
}
function processBuffer(buffer, mode) {
- if (mode.subLanguage && selected_languages[mode.subLanguage]) {
+ if (mode.subLanguage && languages[mode.subLanguage]) {
var result = highlight(mode.subLanguage, buffer);
keyword_count += result.keyword_count;
- relevance += result.relevance;
return result.value;
} else {
return processKeywords(buffer, mode);
@@ -300,7 +262,7 @@ var hljs = new function() {
}
function startNewMode(mode, lexem) {
- var markup = mode.noMarkup?'':'<span class="' + mode.displayClassName + '">';
+ var markup = mode.className?'<span class="' + mode.className + '">':'';
if (mode.returnBegin) {
result += markup;
mode.buffer = '';
@@ -311,7 +273,8 @@ var hljs = new function() {
result += markup;
mode.buffer = lexem;
}
- modes[modes.length] = mode;
+ modes.push(mode);
+ relevance += mode.relevance;
}
function processModeInfo(buffer, lexem, end) {
@@ -325,13 +288,12 @@ var hljs = new function() {
if (new_mode) {
result += processBuffer(current_mode.buffer + buffer, current_mode);
startNewMode(new_mode, lexem);
- relevance += new_mode.relevance;
return new_mode.returnBegin;
}
var end_level = endOfMode(modes.length - 1, lexem);
if (end_level) {
- var markup = current_mode.noMarkup?'':'</span>';
+ var markup = current_mode.className?'</span>':'';
if (current_mode.returnEnd) {
result += processBuffer(current_mode.buffer + buffer, current_mode) + markup;
} else if (current_mode.excludeEnd) {
@@ -340,20 +302,16 @@ var hljs = new function() {
result += processBuffer(current_mode.buffer + buffer + lexem, current_mode) + markup;
}
while (end_level > 1) {
- markup = modes[modes.length - 2].noMarkup?'':'</span>';
+ markup = modes[modes.length - 2].className?'</span>':'';
result += markup;
end_level--;
modes.length--;
}
+ var last_ended_mode = modes[modes.length - 1];
modes.length--;
modes[modes.length - 1].buffer = '';
- if (current_mode.starts) {
- for (var i = 0; i < language.modes.length; i++) {
- if (language.modes[i].className == current_mode.starts) {
- startNewMode(language.modes[i], '');
- break;
- }
- }
+ if (last_ended_mode.starts) {
+ startNewMode(last_ended_mode.starts, '');
}
return current_mode.returnEnd;
}
@@ -362,7 +320,7 @@ var hljs = new function() {
throw 'Illegal';
}
- var language = LANGUAGES[language_name];
+ var language = languages[language_name];
var modes = [language.defaultMode];
var relevance = 0;
var keyword_count = 0;
@@ -381,6 +339,7 @@ var hljs = new function() {
if(modes.length > 1)
throw 'Illegal';
return {
+ language: language_name,
relevance: relevance,
keyword_count: keyword_count,
value: result
@@ -388,6 +347,7 @@ var hljs = new function() {
} catch (e) {
if (e == 'Illegal') {
return {
+ language: null,
relevance: 0,
keyword_count: 0,
value: escape(value)
@@ -401,53 +361,51 @@ var hljs = new function() {
/* Initialization */
function compileModes() {
- for (var i in LANGUAGES) {
- if (!LANGUAGES.hasOwnProperty(i))
- continue;
- var language = LANGUAGES[i];
- for (var j = 0; j < language.modes.length; j++) {
- var mode = language.modes[j];
- if (mode.begin)
- mode.beginRe = langRe(language, '^' + mode.begin);
+
+ function compileMode(mode, language, is_default) {
+ if (mode.compiled)
+ return;
+
+ if (!is_default) {
+ mode.beginRe = langRe(language, mode.begin ? mode.begin : '\\B|\\b');
+ if (!mode.end && !mode.endsWithParent)
+ mode.end = '\\B|\\b'
if (mode.end)
- mode.endRe = langRe(language, '^' + mode.end);
- if (mode.illegal)
- mode.illegalRe = langRe(language, '^(?:' + mode.illegal + ')');
- language.defaultMode.illegalRe = langRe(language, '^(?:' + language.defaultMode.illegal + ')');
- if (mode.relevance == undefined) {
- mode.relevance = 1;
- }
- if (!mode.displayClassName) {
- mode.displayClassName = mode.className;
- }
+ mode.endRe = langRe(language, mode.end);
+ }
+ if (mode.illegal)
+ mode.illegalRe = langRe(language, mode.illegal);
+ if (mode.relevance == undefined)
+ mode.relevance = 1;
+ if (mode.keywords)
+ mode.lexemsRe = langRe(language, mode.lexems || hljs.IDENT_RE, true);
+ for (var key in mode.keywords) {
+ if (!mode.keywords.hasOwnProperty(key))
+ continue;
+ if (mode.keywords[key] instanceof Object)
+ mode.keywordGroups = mode.keywords;
+ else
+ mode.keywordGroups = {'keyword': mode.keywords};
+ break;