Vuepress: Imagesize in Markdown

Created on 13 Jun 2018  路  7Comments  路  Source: vuejs/vuepress

Hey there!

I looked up the page on:
https://vuepress.vuejs.org/guide/assets.html
for referencing images. It works properly, but I cannot find any way to resize the image in markdown.

Non of these seem to work:

[Image](./img.png =100x)
[Image](./img.png =100x100)

https://stackoverflow.com/questions/14675913/changing-image-size-in-markdown/41169162

Google does also not provide any information. How does it come that noone wants to resize images via markdown in vuepress?

Thanks for help!

Most helpful comment

Markdown syntax doesn't support different set for different pictures.

If you want to do such fine-grained control, you can just write pure HTML:

<img src="./img.png" width="100" height="100">

All 7 comments

Markdown syntax doesn't support different set for different pictures.

If you want to do such fine-grained control, you can just write pure HTML:

<img src="./img.png" width="100" height="100">

Oh I see, thank you very much!

I tried the solution proposed by @exKAZUu but it does not seem to work.

I install the package locally, I declare it in the VuePress config file, and I add some code in the markdown:

image

And in the generated html file, I can read:

![image](image.svg =100x200)

In fact, the markdown is not interpreted at all...

@oupala I'm now using my solution and it works well. I list up possible things to fix your problem.

  • You should use a relative path, e.g., ![Screenshot](./set-language.png =600x600) (<- this is actual code fragment from my markdown)
  • You should add markdown-it-imsize as a dependency via yarn add -D markdown-it-imsize or npm install --save-dev markdown-it-imsize
  • You should tweak settings by modifying .vuepress/config.js like
module.exports = {
  ...
  markdown: {
    linkify: true,
    extendMarkdown: md => {
      md.use(require('markdown-it-imsize'));
    },
  },
  ...
};

I've seen where I've made an error. I enabled the plugin this way:

  markdown: {
    config: md => {
      md.use(require('markdown-it-deflist'))
      md.use(require('markdown-it-imsize'))
    }
  },

Where I should have enabled it this way:

  markdown: {
    config: md => {
      md.use(require('markdown-it-deflist'))
    },
    extendMarkdown: md => {
      md.use(require('markdown-it-imsize'))
    }
  },

Thanks for your help @exKAZUu, your were helpful.

Markdown syntax doesn't support different set for different pictures.

If you want to do such fine-grained control, you can just write pure HTML:

<img src="./img.png" width="100" height="100">

Works for me. Thx!

Was this page helpful?
0 / 5 - 0 ratings