[GH-ISSUE #1481] MD038: Code span containing only spaces #2543

Closed
opened 2026-03-07 20:08:45 +03:00 by kerem · 1 comment
Owner

Originally created by @straight-shoota on GitHub (Feb 1, 2025).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1481

When a code span contains only spaces, I think MD038 should not apply.

CommonMark describes that case to be taken as is without chopping off leading or trailing spaces (https://spec.commonmark.org/0.31.2/#code-spans).

When there are only spaces, it's very likely that they're intentional. That premise for MD038 is to avoid unintentional whitespace.
And it's even more likely that the automatic fix is much less intentional: markdownlint --fix removes all spaces.
This results in an empty code span, which is not even a valid code span. Thus the fix definitely changes semantics.
In my opinion the fix behaviour is wrong. The rule violation maybe not as clearly wrong, but I'd suggest to exempt code spans with only spaces from MD038.

Original:

` `

`  `

`   `

Original, rendered in GitHub:

Result of markdownlint --fix:

``

``

``

Result of markdownlint --fix, rendered in GitHub:

``

``

``

Originally created by @straight-shoota on GitHub (Feb 1, 2025). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1481 When a code span contains only spaces, I think MD038 should not apply. CommonMark describes that case to be taken as is without chopping off leading or trailing spaces (https://spec.commonmark.org/0.31.2/#code-spans). When there are only spaces, it's very likely that they're intentional. That premise for MD038 is to avoid unintentional whitespace. And it's even more likely that the automatic fix is much less intentional: `markdownlint --fix` removes _all_ spaces. This results in an empty code span, which is not even a valid code span. Thus the fix definitely changes semantics. In my opinion the fix behaviour is _wrong_. The rule violation maybe not as clearly wrong, but I'd suggest to exempt code spans with only spaces from MD038. Original: ```md ` ` ` ` ` ` ``` Original, rendered in GitHub: > ` ` > > ` ` > > ` ` Result of `markdownlint --fix`: ```md `` `` `` ``` Result of `markdownlint --fix`, rendered in GitHub: > `` > > `` > > ``
kerem 2026-03-07 20:08:45 +03:00
Author
Owner

@DavidAnson commented on GitHub (May 1, 2025):

[Deleted obvious SPAM comment]

<!-- gh-comment-id:2845171800 --> @DavidAnson commented on GitHub (May 1, 2025): [Deleted obvious SPAM comment]
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#2543
No description provided.