Skip to content

feat(editor): read image size and alignment from the alt - #198

Merged
gnacho merged 1 commit into
masterfrom
feat/194-image-size-alt
Nov 18, 2026
Merged

gnacho merged 1 commit into
masterfrom
feat/194-image-size-alt

Conversation

@gnacho

@gnacho gnacho commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Closes #194.

An image that is alone on its line now takes its size and alignment from the alt text, the form Obsidian uses:

![A photo|480](photo.png)
![A photo|480x320|center](photo.png)
![A photo|right](photo.png)

Other renderers either honour it or show the image at its natural size, so the file stays valid Markdown. The options are marked as syntax, so they shrink like the brackets and are revealed on the cursor line.

What changed:

  • markdown_render: ImageOptions, parse_alt_options, with_alt_options and rewrite_image_alt. Ornament::Image and ImageRef carry the options, and the alt they expose is already clean.
  • markdown_view: image_box decides the painted size and the gap. It honours the requested width and height, never goes wider than the column, and is capped at 900 px of height. Without a size nothing is enlarged, and the gap now fits the image instead of always reserving 150 px.
  • editor: the gap tag is applied per image height through the existing tag cache, and the right-click menu on an image offers Small, Medium, Large, Original size and the three alignments. Only the alt is rewritten, never the destination or the title.

Tests: unit tests for the parser, the rewriter and the geometry, plus tests/image_size.rs with a real texture, the measured gap, and the three menu actions. make check green. The Xvfb check shows a 480 px image next to a 216 px one with no size, and the menu writes |240 when Small is picked.

@gnacho
gnacho merged commit 17eb3c1 into master Nov 18, 2026
3 checks passed
@gnacho
gnacho deleted the feat/194-image-size-alt branch November 18, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image size and alignment from the alt text

1 participant