consistent-emphasis-style
🎨 Stylistic
🔧 Fixable
⭐ CommonMark
🌟 GFM
Enforce consistent emphasis style.
Rule Details
This rule enforces a single, consistent style for emphasis (italic text) in Markdown files. Consistent formatting makes it easier to understand a document, and mixing different emphasis styles can reduce readability.
An emphasis is defined as text wrapped in either * (asterisks) or _ (underscores). While Markdown allows any of these styles, this rule ensures that only one is used throughout the document.
Examples
❌ Incorrect
Examples of incorrect code for this rule:
Default
<!-- eslint mark/consistent-emphasis-style: "error" -->
*foo*
_bar_
*baz*
**_foo_**
__*bar*__
_**foo**_
*__bar__*
___foo___
***bar***<!-- eslint mark/consistent-emphasis-style: "error" -->
_foo_
*bar*
_baz_
__*foo*__
**_bar_**
*__foo__*
_**bar**_
***foo***
___bar___With { style: '*' } Option
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '*' }] -->
_foo_
**_bar_**
_**baz**_
___qux___With { style: '_' } Option
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '_' }] -->
*foo*
__*bar*__
*__baz__*
***qux***✅ Correct
Examples of correct code for this rule:
Default
<!-- eslint mark/consistent-emphasis-style: "error" -->
*foo*
__*bar*__
*__baz__*
***qux***<!-- eslint mark/consistent-emphasis-style: "error" -->
_foo_
**_bar_**
_**baz**_
___qux___With { style: '*' } Option
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '*' }] -->
*foo*
__*bar*__
*__baz__*
***qux***With { style: '_' } Option
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '_' }] -->
_foo_
**_bar_**
_**baz**_
___qux___Options
'mark/consistent-emphasis-style': ['error', {
style: 'consistent',
}]style
Type:
'consistent' | '*' | '_'/ Default:'consistent'
When style is set to 'consistent', the rule enforces that all emphasis in the document use the same style as the first one encountered.
You can also specify a particular style by setting style to '*' or '_', which will enforce that all emphasis use the specified style.
Fix
This rule fixes the emphasis by replacing them with the configured style.