-
-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refine docs and sync language-highlight.md (#21)
- Loading branch information
Showing
3 changed files
with
60 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,53 @@ | ||
# 代码高亮 | ||
|
||
内置的代码高亮工具是 [Prism](https://github.com/PrismJS/prism),默认支持 CSS、JavaScript 和 HTML。如果需要高亮其他语言,例如`PHP`,可以手动引入代码高亮插件。 | ||
**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/docsify/lib/docsify.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-bash.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-php.min.js"></script> | ||
<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> | ||
``` | ||
|
||
?> 其他的语言高亮插件可以查看[Prims 仓库](https://github.com/PrismJS/prism/tree/gh-pages/components)。 | ||
要使用语法高亮,需要在代码块第一行添加对应的[语言声明](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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters