Code Demo

Mr.Hope ... 2022-6-1 Less than 1 minute

Let you insert code demos in your Markdown file.

# Config







 





module.exports = {
  plugins: [
    [
      "md-enhance",
      {
        // Enable Code Demo
        demo: true,
      },
    ],
  ],
};
1
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)
}
```

:::
1
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 and ls in code block.

Available CSS languages:

  • "css" (default)
  • "less"
  • "scss"
  • "sass"
  • "stylus"

You can also use styl in code block.

# Not Supported Language Demo

A demo using language not supported by browsers
# Title

is very powerful!
1
2
3
const message: string = "VuePress Theme Hope";

document.querySelector("h1").innerHTML = message;
1
2
3
h1 {
  font-style: italic;

  + p {
    color: red;
  }
}
1
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;
  }
}
```

:::
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Last update: June 4, 2022 13:16
Contributors: Mr.Hope