# 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://highlightjs.org/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
[CSS classes reference][cr] from the downloaded package.
[cr]: http://highlightjs.readthedocs.org/en/latest/css-classes-reference.html
## 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:
python3 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;
```
## AMD
Highlight.js can be used with an AMD loader. You will need to build it from
source in order to do so:
```bash
$ python3 tools/build.py -tamd lang1 lang2 ..
```
Which will generate a `build/highlight.pack.js` which will load as an AMD
module with support for the built languages and can be used like so:
```javascript
require(["highlight.js/build/highlight.pack"], function(hljs){
// 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.configure({tabReplace: ' '}); // 4 spaces
// ... or
hljs.configure({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)` 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>`) set the `useBR` option to `true`:
```javascript
hljs.configure({useBR: true});
$('div.code').each(function(i, e) {hljs.highlightBlock(e)});
```
## 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: 8.0
- URL: http://highlightjs.org/
For the license terms see LICENSE files.
For authors and contributors see AUTHORS.en.txt file.
没有合适的资源?快使用搜索试试~ 我知道了~
Auto_tocuh.zip_5TTL_The Show_focuh_pictures_responsive
共116个文件
css:52个
js:31个
html:21个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 153 浏览量
2022-09-20
11:50:32
上传
评论
收藏 341KB ZIP 举报
温馨提示
A PC-side, IPAD, mobile phone and other responsive pictures show the special effects of the touch screen scroll plug-in Owl Carousel Web page.
资源推荐
资源详情
资源评论
收起资源包目录
Auto_tocuh.zip_5TTL_The Show_focuh_pictures_responsive (116个子文件)
foundation.css 146KB
foundation.min.css 114KB
animate.css 68KB
devices.css 9KB
normalize.css 7KB
owl.carousel.css 4KB
default.css 3KB
railscasts.css 2KB
monokai_sublime.css 2KB
demo.css 2KB
arta.css 2KB
obsidian.css 2KB
xcode.css 2KB
sunburst.css 2KB
googlecode.css 2KB
monokai.css 2KB
school_book.css 2KB
magula.css 2KB
far.css 2KB
zenburn.css 2KB
brown_paper.css 2KB
docco.css 2KB
atelier-lakeside.light.css 2KB
atelier-lakeside.dark.css 2KB
atelier-seaside.light.css 2KB
dark.css 2KB
atelier-seaside.dark.css 2KB
atelier-forest.light.css 2KB
atelier-forest.dark.css 2KB
atelier-heath.light.css 2KB
atelier-heath.dark.css 2KB
idea.css 2KB
atelier-dune.light.css 2KB
atelier-dune.dark.css 2KB
github.css 2KB
pojoaque.css 2KB
tomorrow-night-blue.css 2KB
solarized_light.css 2KB
solarized_dark.css 2KB
tomorrow-night.css 2KB
rainbow.css 2KB
foundation.css 2KB
vs.css 2KB
tomorrow-night-eighties.css 2KB
tomorrow-night-bright.css 1KB
paraiso.light.css 1KB
paraiso.dark.css 1KB
ir_black.css 1KB
tomorrow.css 1KB
owl.theme.css 1KB
mono-blue.css 899B
ascetic.css 806B
ajax-loader.gif 3KB
.gitkeep 1B
lazyContent.html 19KB
animate.html 9KB
callbacks.html 9KB
info.html 6KB
manipulations.html 6KB
thumbnails.html 6KB
nestedItemSelector.html 6KB
center.html 5KB
responsiveoptions.html 5KB
ajaxLazyContent.html 5KB
urlhash.html 5KB
videos.html 5KB
mousewheel.html 5KB
autoplay.html 5KB
ajax.html 5KB
merge.html 5KB
lazyload.html 5KB
autowidth.html 5KB
zepto.html 4KB
rtl.html 4KB
autoHeight.html 4KB
pojoaque.jpg 1KB
jquery-1.11.0.min.js 94KB
foundation.min.js 89KB
jquery.js 83KB
owl.carousel.js 76KB
foundation.joyride.js 27KB
zepto.min.js 24KB
foundation.orbit.js 20KB
foundation.js 17KB
foundation.clearing.js 15KB
foundation.topbar.js 13KB
foundation.reveal.js 13KB
foundation.abide.js 11KB
modernizr.js 11KB
highlight.pack.js 10KB
foundation.tooltip.js 10KB
foundation.dropdown.js 9KB
foundation.interchange.js 9KB
fastclick.js 8KB
foundation.tab.js 6KB
foundation.slider.js 6KB
foundation.magellan.js 6KB
jquery.mousewheel.js 3KB
zepto.data.js 3KB
placeholder.js 2KB
共 116 条
- 1
- 2
资源评论
我虽横行却不霸道
- 粉丝: 91
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功