54 lines
1.1 KiB
Markdown
54 lines
1.1 KiB
Markdown
# 代码高亮
|
|
|
|
**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/) :
|
|
|
|
```html
|
|
<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>
|
|
```
|
|
|
|
要使用语法高亮,需要在代码块第一行添加对应的[语言声明](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;
|
|
}
|
|
```
|