Markdown Obsidian Image Size
Adds Obsidian image size (
) support to VSCode's markdown preview.
Overview
The image-size plugin reads an image's size from its description, the way Obsidian does, and writes it as the image's width and height attributes. The rest of the description stays the alt text.

<img src="https://example.com/e.jpg" alt="Engelbart" width="100" height="145">
In renderers without the plugin, the image still shows, with the size left in its alt text (alt="Engelbart|100x145").
Syntax
End the description with |, a width, and optionally x and a height. The text before the | is the alt text.

Give a width alone and the height follows the image's own proportions:

A description that is only a size (240 or 240x160) sizes the image and leaves its alt text empty, which marks the image as decoration:

A reference image is sized the same way, ![Engelbart|100][portrait], and finds its definition by its own label. A collapsed or shortcut reference (![Engelbart|100][], ![Engelbart|100]) has none but the description, so its definition is written with the size: [Engelbart|100]: e.jpg.
What is a size
A width and a height are each one to five ASCII digits, not starting with 0, and the x between them is lower case. Nothing else is a size, and a description that does not end in one is left as it is:
| Description |
Why it is not a size |
a\|100px, a\|50% |
a unit |
a\|x145 |
no width |
a\|100x |
an x without a height |
a\|100X145 |
an upper-case X |
a\|0, a\|0100 |
starts with 0 |
a\|123456 |
six digits |
a\|100 x 145, a\| 100 |
a space inside |
a\|100 |
a space after it |
Only the last | is read:  has the alt text a|b. The alt text loses the whitespace before the | ( has the alt text Engelbart).
The description is its text
The size is read from the alt text, which is the description as plain text in every engine: formatting is dropped and code spans, escapes and character references are their text. So  has the alt text Engelbart, and a | is a | however it is written: \| and | read as the bar too.
That is what makes a size work in a table cell, where a bare | ends the cell: write the bar escaped there.
| Photo | Place |
| --- | --- |
|  | The lake |
It is also the cost: there is no way to write an alt text that ends in | and a number, or that is only a number, as such text is always read as a size.
Attribute blocks
With the attrs plugin, or Sätteri's attributes feature, a width or height written in a block wins over the description's, each on its own: {width=50} has width="50" and height="145". The size is written after the image's src, alt and title, and the block's other attributes after the size.
Other image plugins
- A lightbox image (
!) has the size on the page, where it is the thumbnail, and not in the dialog, which shows the image at full size. A host that resizes images from these attributes then makes a small thumbnail and leaves the full-size view alone. Two sizes of one image share a dialog.
- Captions, spoilers and unwrap-images take a sized image like any other.
- inline-svg replaces an
.svg image with the file's own <svg>, which keeps the size written in the file: the description's size is lost, and the alt text without it names the SVG.
- A spoiler written inside a description (
) differs by engine, as in any alt text: markdown-it drops its pipes and remark and Sätteri keep them. The size is read in all three.
- With the ruby plugin, a sized image cannot be a ruby's base: the ruby reads the first
| inside its braces as its separator, so {|reading} splits inside the image. A sized image in a ruby's reading ({base|}) is sized.
Obsidian's embeds, ![[image.png|100]], are a different syntax and not part of this plugin.
What a host does with the size
The plugin only writes the two attributes: it does not change the src, write a srcset or ship a stylesheet. The attributes are what a host's image pipeline reads:
- Astro passes every attribute of a Markdown image to its image pipeline, in both of its Markdown processors, and resizes the image to them at build time. A remote image needs its host in
image.domains or image.remotePatterns to be processed.
- A plain page uses them to reserve the image's space before it loads, so the text does not jump. When only a width is given, keep
height: auto in the page's CSS, so the height follows the image's own proportions.
About
Part of Markdown Preview Extended Syntax — a pack of Markdown preview syntax extensions you can install all at once.
Powered by @mirrordown/mdit-image-size · Source on GitHub.