Image

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

Improve image syntax in Markdown to support color scheme and size.

# Config







 







module.exports = {
  plugins: [
    [
      "md-enhance",
      {
        // Enable image mark
        imageMark: true,
        // Enable image size
        imageSize: true,
      },
    ],
  ],
};
1
2
3
4
5
6
7
8
9
10
11
12
13

# Image Mark

GFM supports marking pictures by ID suffix so that pictures are only displayed in a specific mode. We support both GitHub’s markup and the easy markup #light and #dark.

You can enable it using imageMark option.

![GitHub Light](/assets/icon/github-light.png#gh-dark-mode-only)
![GitHub Dark](/assets/icon/github-dark.png#gh-light-mode-only)

![GitHub Light](/assets/icon/github-light.png#dark)
![GitHub Dark](/assets/icon/github-dark.png#light)
1
2
3
4
5
Case

The above demo will render the following result

GitHub Light GitHub Dark

GitHub Light GitHub Dark

# Advanced

You can pass an object to imageMark to config ID marks, available options are:

interface ImageMarkOptions {
  /** lightmode only IDs */
  light?: string[];
  /** darkmode only IDs */
  dark?: string[];
}
1
2
3
4
5
6

# Image Size

You can use =widthxheight to specify the image size when setting imageSize: true in plugin options.

![Alt](/example.png =200x300)

![Alt](/example.jpg "Image title" =200x)
![Alt](/example.bmp =x300)
1
2
3
4

The above markdown will be parsed as:

<img src="/example.png" width="200" height="300" />
<img src="/example.jpg" title="Image title" width="200" />
<img src="/example.bmp" height="300" />
1
2
3
Last update: June 4, 2022 13:16
Contributors: Mr.Hope