Code Demo
Let you insert code demos in your Markdown file.
# Config
module.exports = {
plugins: [
[
"md-enhance",
{
// Enable Code Demo
demo: true,
},
],
],
};
2
3
4
5
6
7
8
9
10
11
# Syntax
You should use the following syntax:
::: [type]-demo Optional title text
```html
<!-- ↑ use available ones -->
<!-- your code here -->
<!-- you can have multiple code block, but each language must appear only once. -->
```
```json
// json block is for config
{
// your config here (optional)
}
```
:::
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Tips
The json block is optional, for config please see config.
The plugin support three types:
- normal (default)
- vue
- react
# Available Languages
You can use different language in your demo block.
When you set language which can not run on browsers, since the plugin is not able to resolve them, so demo display will be disabled. The plugin will only show the code and provide you a button to open it in CodePen.
Available HTML languages:
"html"
(default)"slim"
"haml"
"markdown"
You can also use
md
in code block.
Available JS languages:
"javascript"
(default)"coffeescript"
"babel"
"livescript"
"typescript"
You can also use
js
,ts
,coffee
andls
in code block.
Available CSS languages:
"css"
(default)"less"
"scss"
"sass"
"stylus"
You can also use
styl
in code block.
# Not Supported Language Demo
# Title
is very powerful!
2
3
const message: string = "VuePress Theme Hope";
document.querySelector("h1").innerHTML = message;
2
3
h1 {
font-style: italic;
+ p {
color: red;
}
}
2
3
4
5
6
7
Code
::: normal-demo A normal demo
```md
# Title
is very powerful!
```
```ts
const message: string = "VuePress Theme Hope";
document.querySelector("h1").innerHTML = message;
```
```scss
h1 {
font-style: italic;
+ p {
color: red;
}
}
```
:::
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25