Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.13 KB

language-highlight.md

File metadata and controls

53 lines (41 loc) · 1.13 KB

代码高亮

docsify内置的代码高亮工具是 Prism。Prism 默认支持的语言如下:

  • Markup - markup, html, xml, svg, mathml, ssml, atom, rss
  • CSS - css
  • C-like - clike
  • JavaScript - javascript, js

添加额外的语法支持需要通过CDN添加相应的语法文件 :

<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>

要使用语法高亮,需要在代码块第一行添加对应的语言声明,示例如下:

```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;
}
```

上面代码的渲染结果:

<p>This is a paragraph</p>
<a href="//docsify.js.org/">Docsify</a>
echo "hello"
function getAdder(int $x): int 
{
    return 123;
}