# Highlight.js
Highlight.js highlights syntax in code examples on blogs, forums and,
in fact, on any web page. 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").
## Basic usage
Link the library and a stylesheet from your page and hook highlighting to
the page load event:
```html
<link rel="stylesheet" href="styles/default.css">
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
```
This will highlight all code on the page marked up as `<pre><code> .. </code></pre>`.
If you use different markup or need to apply highlighting dynamically, read
"Custom initialization" below.
- You can download your own customized version of "highlight.pack.js" or
use the hosted one as described on the download page:
<http://softwaremaniacs.org/soft/highlight/en/download/>
- Style themes are available in the download package or as hosted files.
To create a custom style for your site see the class reference in the file
[classref.txt][cr] from the downloaded package.
[cr]: http://github.com/isagalaev/highlight.js/blob/master/classref.txt
## node.js
Highlight.js can be used under node.js. The package with all supported languages is
installable from NPM:
npm install highlight.js
Alternatively, you can build it from the source with only languages you need:
python tools/build.py -tnode lang1 lang2 ..
Using the library:
```javascript
var hljs = require('highlight.js');
// If you know the language
hljs.highlight(lang, code).value;
// Automatic language detection
hljs.highlightAuto(code).value;
```
## Tab replacement
You can replace TAB ('\x09') characters used for indentation in your code
with some fixed number of spaces or with a `<span>` to give them special
styling:
```html
<script type="text/javascript">
hljs.tabReplace = ' '; // 4 spaces
// ... or
hljs.tabReplace = '<span class="indent">\t</span>';
hljs.initHighlightingOnLoad();
</script>
```
## Custom initialization
If you use different markup for code blocks you can initialize them manually
with `highlightBlock(code, tabReplace, useBR)` 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:
```javascript
$(document).ready(function() {
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
});
```
You can use `highlightBlock` to highlight blocks dynamically inserted into
the page. Just make sure you don't do it twice for already highlighted
blocks.
If your code container relies on `<br>` tags instead of line breaks (i.e. if
it's not `<pre>`) pass `true` into the third parameter of `highlightBlock`
to make highlight.js use `<br>` in the output:
```javascript
$('div.code').each(function(i, e) {hljs.highlightBlock(e, null, true)});
```
## Heuristics
Autodetection of a code's language is done using a simple heuristic:
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:
```html
<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:
```html
<pre><code class="no-highlight">...</code></pre>
```
## Export
File export.html contains a little program that allows you to paste in a code
snippet and then copy and paste the resulting HTML code generated by the
highlighter. This is useful in situations when you can't use the script itself
on a site.
## Meta
- Version: 7.3
- URL: http://softwaremaniacs.org/soft/highlight/en/
- Author: Ivan Sagalaev (<[email protected]>)
For the license terms see LICENSE files.
For the list of contributors see AUTHORS.en.txt file.
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码——YouYaX_Classic_Bilingual 开源PHP论坛系统源码 经典双语版(中文、英文).zip
共246个文件
gif:66个
php:57个
html:41个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 123 浏览量
2021-11-22
13:06:30
上传
评论
收藏 767KB ZIP 举报
温馨提示
PHP实例开发源码——YouYaX_Classic_Bilingual 开源PHP论坛系统源码 经典双语版(中文、英文)
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码——YouYaX_Classic_Bilingual 开源PHP论坛系统源码 经典双语版(中文、英文).zip (246个子文件)
install.css 3KB
arta.css 2KB
default.css 2KB
xcode.css 2KB
sunburst.css 2KB
edit.css 2KB
googlecode.css 2KB
school_book.css 2KB
magula.css 2KB
far.css 2KB
zenburn.css 2KB
monokai.css 2KB
Dialog.css 2KB
brown_paper.css 2KB
dark.css 2KB
idea.css 2KB
rainbow.css 2KB
github.css 2KB
pojoaque.css 2KB
tomorrow-night-blue.css 1KB
tomorrow-night.css 1KB
vs.css 1KB
tomorrow-night-eighties.css 1KB
tomorrow-night-bright.css 1KB
ir_black.css 1KB
tomorrow.css 1KB
solarized_light.css 1KB
solarized_dark.css 1KB
ascetic.css 763B
17.gif 31KB
31.gif 27KB
24.gif 19KB
16.gif 18KB
13.gif 17KB
26.gif 15KB
bg.gif 11KB
25.gif 11KB
29.gif 9KB
27.gif 9KB
05.gif 8KB
11.gif 8KB
22.gif 8KB
18.gif 8KB
06.gif 8KB
22.gif 7KB
12.gif 6KB
21.gif 6KB
05.gif 6KB
18.gif 6KB
07.gif 6KB
16.gif 6KB
20.gif 6KB
02.gif 6KB
08.gif 6KB
13.gif 6KB
03.gif 6KB
17.gif 5KB
10.gif 5KB
04.gif 5KB
01.gif 5KB
15.gif 5KB
20.gif 5KB
23.gif 5KB
14.gif 5KB
19.gif 5KB
19.gif 5KB
11.gif 5KB
06.gif 5KB
12.gif 5KB
09.gif 5KB
02.gif 4KB
00.gif 4KB
04.gif 4KB
03.gif 3KB
23.gif 3KB
21.gif 3KB
09.gif 3KB
08.gif 3KB
15.gif 3KB
00.gif 3KB
01.gif 3KB
07.gif 3KB
14.gif 3KB
10.gif 3KB
30.gif 2KB
28.gif 2KB
waiting.gif 2KB
message_red.gif 809B
load.gif 644B
edit.gif 631B
logo.gif 626B
add.gif 625B
menu_bg.gif 150B
ico_delete.gif 138B
message_green.gif 73B
index.html 25KB
index.html 19KB
index.html 12KB
reply.html 10KB
talk.html 10KB
共 246 条
- 1
- 2
- 3
资源评论
易小侠
- 粉丝: 6475
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功