# 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实例开发源码——社交系统 Jcow Lite中文版.zip
共445个文件
php:140个
gif:124个
png:81个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 135 浏览量
2021-11-25
09:33:57
上传
评论
收藏 980KB ZIP 举报
温馨提示
PHP实例开发源码——社交系统 Jcow Lite中文版
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码——社交系统 Jcow Lite中文版.zip (445个子文件)
style.css 35KB
documentation.css 5KB
page.css 5KB
layout.css 4KB
page.css 4KB
colorpicker.css 3KB
jquery.lightbox-0.5.css 2KB
galleryview.css 2KB
default.css 2KB
default.css 2KB
faceplant.css 2KB
facebox.css 1KB
jquery.popup.css 962B
jquery.rating.css 836B
loader.gif 11KB
undefined_song.gif 4KB
lightbox-ico-loading.gif 4KB
18.gif 3KB
loading.gif 3KB
user_levels.gif 2KB
21.gif 2KB
9.gif 2KB
preview.gif 2KB
user_fields.gif 2KB
translate.gif 2KB
applications.gif 2KB
users.gif 2KB
themes.gif 2KB
comments.gif 2KB
14.gif 2KB
categories.gif 2KB
cache.gif 2KB
texts.gif 2KB
member_quick_management.gif 2KB
paid_membership.gif 2KB
config.gif 2KB
20.gif 1KB
modules.gif 1KB
22.gif 1KB
forums.gif 1KB
6.gif 1KB
stories.gif 1KB
roles.gif 1KB
rss.gif 1KB
feed.gif 1KB
permissions.gif 1KB
2.gif 989B
5.gif 988B
closelabel.gif 979B
blacklist.gif 969B
ad_blocks.gif 846B
lightbox-btn-prev.gif 832B
24.gif 829B
4.gif 827B
16.gif 817B
star.gif 815B
lightbox-btn-next.gif 812B
twitter.gif 759B
delete.gif 752B
3.gif 737B
button_bg_right.gif 712B
lightbox-btn-close.gif 700B
17.gif 688B
menu.gif 680B
12.gif 661B
19.gif 637B
13.gif 625B
msn.gif 619B
11.gif 569B
music.gif 553B
15.gif 552B
23.gif 536B
10.gif 489B
pending_posts.gif 489B
stream_monitor.gif 473B
8.gif 467B
invite.gif 423B
topic_lock.gif 415B
topic_global.gif 407B
topic_sticky.gif 396B
1.gif 390B
topic_hot.gif 390B
button_bg_left.gif 386B
7.gif 381B
unblock.gif 374B
add_friend.gif 373B
block.gif 371B
profile.gif 368B
message.gif 365B
browse.gif 363B
ex.gif 350B
videos.gif 334B
guestbook.gif 320B
search_box_bg.gif 316B
title_bg.gif 276B
topic_standard.gif 272B
topbar_bg.gif 248B
ico.gif 246B
ico.gif 246B
photos.gif 245B
共 445 条
- 1
- 2
- 3
- 4
- 5
资源评论
易小侠
- 粉丝: 6469
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功