logo
努力加载中 ……

代码演示

原创Starzkg11/6/2021, 6:59:56 AM2741 分钟

Let you insert code demos in your Markdown file.

Configuration

module.exports = {
  plugins: [
    [
      "markdown-enhance",
      {
        // Enable Code Demo
        demo: true,
      },
    ],
  ],
};

Syntax

You should use the following syntax:

::: demo [type] Optional title text

```html
<!-- ↑ use available ones -->
<!-- your code here -->
<!-- you can have mutiple code block, but each language must appear only once. -->
```

```json
// json block is for config
{
  // your config here (optional)
}
```

:::

TIP

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

::: demo A demo using language not supoprted by browsers

# Title

is very handsome.
const message: string = "Mr.Hope";

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

  + p {
    color: red;
  }
}

:::

Code
::: demo A normal demo

```md
# Title

is very handsome.
```

```ts
const message: string = "Mr.Hope";

document.querySelector("h1").innerHTML = message;
```

```scss
h1 {
  font-style: italic;

  + p {
    color: red;
  }
}
```

:::