mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD038/no-space-in-code to allow the "single leading and trailing space" scenario (fixes #271).
This commit is contained in:
parent
6ce426cf88
commit
65b19b703b
8 changed files with 102 additions and 79 deletions
13
doc/Rules.md
13
doc/Rules.md
|
|
@ -1401,23 +1401,28 @@ Tags: whitespace, code
|
|||
|
||||
Aliases: no-space-in-code
|
||||
|
||||
This rule is triggered on code span elements that have spaces right inside the
|
||||
This rule is triggered for code span elements that have spaces adjacent to the
|
||||
backticks:
|
||||
|
||||
```markdown
|
||||
`some text `
|
||||
|
||||
`some text `
|
||||
|
||||
` some text`
|
||||
```
|
||||
|
||||
To fix this, remove the spaces inside the codespan markers:
|
||||
To fix this, remove any spaces adjacent to the backticks:
|
||||
|
||||
```markdown
|
||||
`some text`
|
||||
```
|
||||
|
||||
Note: A single leading and trailing space is allowed by the specification and
|
||||
automatically trimmed (to allow for embedded backticks):
|
||||
|
||||
```markdown
|
||||
`` `backticks` ``
|
||||
```
|
||||
|
||||
Note: A single leading or trailing space is allowed if used to separate codespan
|
||||
markers from an embedded backtick:
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const { addErrorContext, filterTokens, forEachInlineCodeSpan, newLineRe } =
|
|||
|
||||
const leftSpaceRe = /^\s([^`]|$)/;
|
||||
const rightSpaceRe = /[^`]\s$/;
|
||||
const singleLeftRightSpaceRe = /^\s\S+\s$/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD038", "no-space-in-code" ],
|
||||
|
|
@ -32,7 +33,8 @@ module.exports = {
|
|||
rangeLineOffset = codeLines.length - 1;
|
||||
fixIndex = 0;
|
||||
}
|
||||
if (left || right) {
|
||||
const allowed = singleLeftRightSpaceRe.test(code);
|
||||
if ((left || right) && !allowed) {
|
||||
const codeLinesRange = codeLines[rangeLineOffset];
|
||||
if (codeLines.length > 1) {
|
||||
rangeLength = codeLinesRange.length + tickCount;
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@
|
|||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md038",
|
||||
"errorDetail": null,
|
||||
"errorContext": "` inside`",
|
||||
"errorRange": [ 7, 10 ]
|
||||
"errorRange": [ 7, 9 ]
|
||||
},
|
||||
{
|
||||
"lineNumber": 24,
|
||||
|
|
@ -132,7 +132,7 @@
|
|||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md038",
|
||||
"errorDetail": null,
|
||||
"errorContext": "`` inside``",
|
||||
"errorRange": [ 7, 12 ]
|
||||
"errorRange": [ 7, 11 ]
|
||||
},
|
||||
{
|
||||
"lineNumber": 25,
|
||||
|
|
|
|||
|
|
@ -95,3 +95,19 @@ Text [link](#link(link`link) text `code`. {MD038}
|
|||
Text [`link`](xref:custom.link`1) text `code`.
|
||||
|
||||
Text ``code [link](#link`link) code`` text `code`.
|
||||
|
||||
No space, start or end: `code`
|
||||
|
||||
Start space, no end space: ` code` {MD038}
|
||||
|
||||
No start space, end space: `code ` {MD038}
|
||||
|
||||
Single start and end space: ` code ` (explicitly allowed/trimmed by the specification)
|
||||
|
||||
All spaces: ` ` {MD038}
|
||||
|
||||
Double start and single end space: ` code ` {MD038}
|
||||
|
||||
Single start and double end spaces: ` code ` {MD038}
|
||||
|
||||
Double start and end spaces: ` code ` {MD038}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue