2018-07-01 07:27:01 -04:00
|
|
|
# 代码高亮
|
|
|
|
|
2020-07-05 00:51:07 -04:00
|
|
|
**docsify**内置的代码高亮工具是 [Prism](https://github.com/PrismJS/prism)。Prism 默认支持的语言如下:
|
|
|
|
|
|
|
|
* Markup - `markup`, `html`, `xml`, `svg`, `mathml`, `ssml`, `atom`, `rss`
|
|
|
|
* CSS - `css`
|
|
|
|
* C-like - `clike`
|
|
|
|
* JavaScript - `javascript`, `js`
|
|
|
|
|
|
|
|
[添加额外的语法支持](https://prismjs.com/#supported-languages)需要通过CDN添加相应的[语法文件](https://cdn.jsdelivr.net/npm/prismjs@1/components/) :
|
2018-07-01 07:27:01 -04:00
|
|
|
|
|
|
|
```html
|
2020-07-05 00:51:07 -04:00
|
|
|
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
|
|
|
|
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-php.min.js"></script>
|
2018-07-01 07:27:01 -04:00
|
|
|
```
|
|
|
|
|
2020-07-05 00:51:07 -04:00
|
|
|
要使用语法高亮,需要在代码块第一行添加对应的[语言声明](https://prismjs.com/#supported-languages),示例如下:
|
|
|
|
|
|
|
|
````
|
|
|
|
```html
|
|
|
|
<p>This is a paragraph</p>
|
|
|
|
<a href="//docsify.js.org/">Docsify</a>
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
echo "hello"
|
|
|
|
```
|
|
|
|
|
|
|
|
```php
|
|
|
|
function getAdder(int $x): int
|
|
|
|
{
|
|
|
|
return 123;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
````
|
|
|
|
|
|
|
|
上面代码的渲染结果:
|
|
|
|
|
|
|
|
```html
|
|
|
|
<p>This is a paragraph</p>
|
|
|
|
<a href="//docsify.js.org/">Docsify</a>
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
echo "hello"
|
|
|
|
```
|
|
|
|
|
|
|
|
```php
|
|
|
|
function getAdder(int $x): int
|
|
|
|
{
|
|
|
|
return 123;
|
|
|
|
}
|
|
|
|
```
|