Skip to content

consistent-emphasis-style

🎨 Stylistic 🔧 Fixable ⭐ CommonMark 🌟 GFM

🔗 Rule Source 🔗 Test Source

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

md
<!-- eslint mark/consistent-emphasis-style: "error" -->

*foo*
_
bar
_
*baz* **
_
foo
_
**
__*bar*__
_
**foo**
_
*__bar__*
_
__foo__
_
***bar***
md
<!-- eslint mark/consistent-emphasis-style: "error" -->

_foo_
*
bar
*
_baz_ __
*
foo
*
__
**_bar_**
*
__foo__
*
_**bar**_
*
**foo**
*
___bar___

With { style: '*' } Option

md
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '*' }] -->

_
foo
_
**
_
bar
_
**
_
**baz**
_
_
__qux__
_

With { style: '_' } Option

md
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '_' }] -->

*
foo
*
__
*
bar
*
__
*
__baz__
*
*
**qux**
*

✅ Correct

Examples of correct code for this rule:

Default

md
<!-- eslint mark/consistent-emphasis-style: "error" -->

*foo*
__*bar*__
*__baz__*
***qux***
md
<!-- eslint mark/consistent-emphasis-style: "error" -->

_foo_
**_bar_**
_**baz**_
___qux___

With { style: '*' } Option

md
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '*' }] -->

*foo*
__*bar*__
*__baz__*
***qux***

With { style: '_' } Option

md
<!-- eslint mark/consistent-emphasis-style: ["error", { style: '_' }] -->

_foo_
**_bar_**
_**baz**_
___qux___

Options

js
'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.

Prior Art