annotate console/lib/highlight/README.ru.md @ 109:cd1f57661439 default tip

Fix files permissions.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 01 Aug 2012 23:18:03 +0200
parents 5cb4733c5189
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
1 # Highlight.js
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
2
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
3 Highlight.js нужен для подсветки синтаксиса в примерах кода в блогах,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
4 форумах и вообще на любых веб-страницах. Пользоваться им очень просто,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
5 потому что работает он автоматически: сам находит блоки кода, сам
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
6 определяет язык, сам подсвечивает.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
7
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
8 Автоопределением языка можно управлять, когда оно не справляется само (см.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
9 дальше "Эвристика").
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
10
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
11
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
12 ## Простое использование
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
13
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
14 Подключите библиотеку и стиль на страницу и повесть вызов подсветки на
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
15 загрузку страницы:
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
16
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
17 ```html
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
18 <link rel="stylesheet" href="styles/default.css">
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
19 <script src="highlight.pack.js"></script>
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
20 <script>hljs.initHighlightingOnLoad();</script>
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
21 ```
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
22
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
23 Весь код на странице, обрамлённый в теги `<pre><code> .. </code></pre>`
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
24 будет автоматически подсвечен. Если вы используете другие теги или хотите
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
25 подсвечивать блоки кода динамически, читайте "Инициализацию вручную" ниже.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
26
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
27 - Вы можете скачать собственную версию "highlight.pack.js" или сослаться
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
28 на захостенный файл, как описано на странице загрузки:
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
29 <http://softwaremaniacs.org/soft/highlight/download/>
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
30
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
31 - Стилевые темы можно найти в загруженном архиве или также использовать
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
32 захостенные. Чтобы сделать собственный стиль для своего сайта, вам
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
33 будет полезен справочник классов в файле [classref.txt][cr], который тоже
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
34 есть в архиве.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
35
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
36 [cr]: http://github.com/isagalaev/highlight.js/blob/master/classref.txt
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
37
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
38
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
39 ## Замена TABов
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
40
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
41 Также вы можете заменить символы TAB ('\x09'), используемые для отступов, на
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
42 фиксированное количество пробелов или на отдельный `<span>`, чтобы задать ему
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
43 какой-нибудь специальный стиль:
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
44
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
45 ```html
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
46 <script type="text/javascript">
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
47 hljs.tabReplace = ' '; // 4 spaces
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
48 // ... or
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
49 hljs.tabReplace = '<span class="indent">\t</span>';
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
50
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
51 hljs.initHighlightingOnLoad();
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
52 </script>
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
53 ```
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
54
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
55
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
56 ## Инициализация вручную
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
57
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
58 Если вы используете другие теги для блоков кода, вы можете инициализировать их
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
59 явно с помощью функции `highlightBlock(code, tabReplace, useBR)`. Она принимает
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
60 DOM-элемент с текстом расцвечиваемого кода и опционально - строчку для замены
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
61 символов TAB.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
62
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
63 Например с использованием jQuery код инициализации может выглядеть так:
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
64
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
65 ```javascript
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
66 $(document).ready(function() {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
67 $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
68 });
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
69 ```
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
70
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
71 `highlightBlock` можно также использовать, чтобы подсветить блоки кода,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
72 добавленные на страницу динамически. Только убедитесь, что вы не делаете этого
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
73 повторно для уже раскрашенных блоков.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
74
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
75 Если ваш блок кода использует `<br>` вместо переводов строки (т.е. если это не
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
76 `<pre>`), передайте `true` третьим параметром в `highlightBlock`:
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
77
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
78 ```javascript
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
79 $('div.code').each(function(i, e) {hljs.highlightBlock(e, null, true)});
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
80 ```
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
81
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
82
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
83 ## Эвристика
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
84
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
85 Определение языка, на котором написан фрагмент, делается с помощью
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
86 довольно простой эвристики: программа пытается расцветить фрагмент всеми
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
87 языками подряд, и для каждого языка считает количество подошедших
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
88 синтаксически конструкций и ключевых слов. Для какого языка нашлось больше,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
89 тот и выбирается.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
90
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
91 Это означает, что в коротких фрагментах высока вероятность ошибки, что
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
92 периодически и случается. Чтобы указать язык фрагмента явно, надо написать
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
93 его название в виде класса к элементу `<code>`:
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
94
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
95 ```html
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
96 <pre><code class="html">...</code></pre>
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
97 ```
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
98
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
99 Можно использовать рекомендованные в HTML5 названия классов:
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
100 "language-html", "language-php". Также можно назначать классы на элемент
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
101 `<pre>`.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
102
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
103 Чтобы запретить расцветку фрагмента вообще, используется класс "no-highlight":
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
104
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
105 ```html
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
106 <pre><code class="no-highlight">...</code></pre>
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
107 ```
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
109
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
110 ## Экспорт
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
111
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
112 В файле export.html находится небольшая программка, которая показывает и дает
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
113 скопировать непосредственно HTML-код подсветки для любого заданного фрагмента кода.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
114 Это может понадобится например на сайте, на котором нельзя подключить сам скрипт
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
115 highlight.js.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
116
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
117
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
118 ## Координаты
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
119
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
120 - Версия: 7.0
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
121 - URL: http://softwaremaniacs.org/soft/highlight/
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
122 - Автор: Иван Сагалаев (<maniac@softwaremaniacs.org>)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
123
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
124 Лицензионное соглашение читайте в файле LICENSE.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents:
diff changeset
125 Список соавторов читайте в файле AUTHORS.ru.txt