[GH-ISSUE #474] Add rule for image without line break #2237

Open
opened 2026-03-07 20:05:52 +03:00 by kerem · 1 comment
Owner

Originally created by @Marcono1234 on GitHub (Dec 29, 2021).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/474

Description

Often users want images to be displayed on a separate line. They then add a single line break and then the image reference, e.g.:

some text
[My image](image.png)

However, due to Markdown line break handling, this will actually be considered an image which is on the same line as the text. In most cases this renders as desired, but only because Markdown renderer tend to wrap images to the next line if there is not enough space. Viewing the Markdown file on a page with a different width or with a different screen size can suddenly show the image on the same line.

It might therefore be good to flag image references, which follow a non-empty line without a hard line break (e.g. trailing 2 spaces or trailing \).
Though, maybe there are corner cases where such behavior is desired.

Example

Test:
![Alt text](https://davidanson.gallerycdn.vsassets.io/extensions/davidanson/vscode-markdownlint/0.45.0/1635486276371/Microsoft.VisualStudio.Services.Icons.Default)

Rendered markdown screenshot

(Have included this as screenshot because GitHub Markdown does not require trailing 2 spaces for line breaks.)

Originally created by @Marcono1234 on GitHub (Dec 29, 2021). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/474 ### Description Often users want images to be displayed on a separate line. They then add a _single_ line break and then the image reference, e.g.: ```md some text [My image](image.png) ``` However, due to Markdown line break handling, this will actually be considered an image which is on the same line as the text. In most cases this renders as desired, but only because Markdown renderer tend to wrap images to the next line if there is not enough space. Viewing the Markdown file on a page with a different width or with a different screen size can suddenly show the image on the same line. It might therefore be good to flag image references, which follow a non-empty line without a [hard line break](https://spec.commonmark.org/0.30/#hard-line-breaks) (e.g. trailing 2 spaces or trailing `\`). Though, maybe there are corner cases where such behavior is desired. ### Example ```md Test: ![Alt text](https://davidanson.gallerycdn.vsassets.io/extensions/davidanson/vscode-markdownlint/0.45.0/1635486276371/Microsoft.VisualStudio.Services.Icons.Default) ``` ![Rendered markdown screenshot](https://user-images.githubusercontent.com/11685886/147679703-c20a96e9-fe1d-4eb6-b7a2-83cdff00e412.png) (Have included this as screenshot because GitHub Markdown does not require trailing 2 spaces for line breaks.)
Author
Owner

@miu007 commented on GitHub (Oct 10, 2023):

I would also like to have this feature. I cannot find it in the current version as of today. Thanks.

<!-- gh-comment-id:1755932122 --> @miu007 commented on GitHub (Oct 10, 2023): I would also like to have this feature. I cannot find it in the current version as of today. Thanks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#2237
No description provided.