|
| 1 | +# no-space-in-emphasis |
| 2 | + |
| 3 | +Disallow spaces around emphasis markers. |
| 4 | + |
| 5 | +## Background |
| 6 | + |
| 7 | +In Markdown, emphasis (bold and italic) is created using asterisks (`*`) or underscores (`_`), and a strikethrough is created using tildes (`~`). The emphasis markers must be directly adjacent to the text they're emphasizing, with no spaces between the markers and the text. When spaces are present, the emphasis is not rendered correctly. |
| 8 | + |
| 9 | +Please note that this rule does not check for spaces inside emphasis markers when the content is itself an emphasis (i.e., nested emphasis). For example, `**_ bold _**` and `_** italic **_` are not flagged, even though there are spaces inside the inner emphasis markers. |
| 10 | + |
| 11 | +## Rule Details |
| 12 | + |
| 13 | +This rule warns when it finds emphasis markers that have spaces between the markers and the text they're emphasizing. |
| 14 | + |
| 15 | +Examples of **incorrect** code for this rule: |
| 16 | + |
| 17 | +```markdown |
| 18 | +<!-- eslint markdown/no-space-in-emphasis: "error" --> |
| 19 | + |
| 20 | +Here is some ** bold ** text. |
| 21 | +Here is some * italic * text. |
| 22 | +Here is some __ bold __ text. |
| 23 | +Here is some _ italic _ text. |
| 24 | +Here is some *** bold italic *** text. |
| 25 | +Here is some ___ bold italic ___ text. |
| 26 | +``` |
| 27 | + |
| 28 | +Examples of **correct** code for this rule: |
| 29 | + |
| 30 | +```markdown |
| 31 | +<!-- eslint markdown/no-space-in-emphasis: "error" --> |
| 32 | + |
| 33 | +Here is some **bold** text. |
| 34 | +Here is some *italic* text. |
| 35 | +Here is some __bold__ text. |
| 36 | +Here is some _italic_ text. |
| 37 | +Here is some ***bold italic*** text. |
| 38 | +Here is some ___bold italic___ text. |
| 39 | +Here is some **_ bold _** text. |
| 40 | +Here is some _** italic **_ text. |
| 41 | +``` |
| 42 | + |
| 43 | +## Options |
| 44 | + |
| 45 | +The following options are available on this rule: |
| 46 | + |
| 47 | +* `checkStrikethrough: boolean` - when `true`, also check for spaces around strikethrough markers (`~` and `~~`). (default: `false`) |
| 48 | + |
| 49 | +> [!IMPORTANT] <!-- eslint-disable-line -- This should be fixed in https://github.com/eslint/markdown/issues/294 --> |
| 50 | +> |
| 51 | +> Use `checkStrikethrough` with `language: "markdown/gfm"`; in CommonMark, `~`/`~~` aren’t strikethrough (they’ll still be linted if enabled). |
| 52 | +
|
| 53 | +Examples of **incorrect** code when configured as `"no-space-in-emphasis": ["error", { checkStrikethrough: true }]`: |
| 54 | + |
| 55 | +```markdown |
| 56 | +<!-- eslint markdown/no-space-in-emphasis: ["error", { checkStrikethrough: true }] --> |
| 57 | + |
| 58 | +Here is some ~ strikethrough ~ text. |
| 59 | +Here is some ~~ strikethrough ~~ text. |
| 60 | +``` |
| 61 | + |
| 62 | +Examples of **correct** code when configured as `"no-space-in-emphasis": ["error", { checkStrikethrough: true }]`: |
| 63 | + |
| 64 | +```markdown |
| 65 | +<!-- eslint markdown/no-space-in-emphasis: ["error", { checkStrikethrough: true }] --> |
| 66 | + |
| 67 | +Here is some ~strikethrough~ text. |
| 68 | +Here is some ~~strikethrough~~ text. |
| 69 | +``` |
| 70 | + |
| 71 | +## When Not to Use It |
| 72 | + |
| 73 | +If you aren't concerned with proper emphasis rendering in your Markdown documents, you can safely disable this rule. |
| 74 | + |
| 75 | +## Prior Art |
| 76 | + |
| 77 | +* [MD037 - Spaces inside emphasis markers](https://github.com/DavidAnson/markdownlint/blob/main/doc/md037.md) |
0 commit comments