mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-03 12:39:41 +08:00
b621e0e4e7
BREAKING: In a minority of cases syntax updates may break apps running in very old browsers (such as Internet Explorer), or apps that build Docsify in a custom way with old build tools. To upgrade, build Docsify for older browsers in a custom way, or update existing build tools to handle newer syntax. DEPRECATED: `$docsify.themeColor` is deprecated and will be eventually removed, use a `--theme-color` CSS variable in your style sheet.
1.7 KiB
1.7 KiB
Language highlighting
Docsify uses Prism to highlight code blocks in your pages. Prism supports the following languages by default:
- Markup -
markup
,html
,xml
,svg
,mathml
,ssml
,atom
,rss
- CSS -
css
- C-like -
clike
- JavaScript -
javascript
,js
Support for additional languages is available by loading the language-specific grammar files via 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>
!> This <script>
tag must be placed after the docisfy <script>
to work.
To enable syntax highlighting, wrap each code block in triple backticks with the language specified on the first line:
```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;
}
```
The above markdown will be rendered as:
<p>This is a paragraph</p>
<a href="//docsify.js.org/">Docsify</a>
echo "hello"
function getAdder(int $x): int
{
return 123;
}
Highlighting Dynamic Content
Code blocks dynamically created from javascript can be highlighted using the method Prism.highlightElement
like so:
const code = document.createElement("code");
code.innerHTML = "console.log('Hello World!')";
code.setAttribute("class", "lang-javascript");
Prism.highlightElement(code);