markdown-preferences/link-bracket-newline
enforce linebreaks after opening and before closing link brackets
- ⚙️ This rule is included in
plugin.configs.standard. - 🔧 The
--fixoption on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule enforces consistent linebreaks (newlines) immediately after the opening and/or before the closing brackets of links, images, link references, image references, and link definitions in Markdown documents. It helps maintain a uniform style for link and image syntax, improving readability and reducing accidental formatting inconsistencies.
What Does This Rule Check?
- Links: Checks for linebreaks just after
[and just before]in inline links, e.g.,[label](/url). - Images: Checks for linebreaks just after
![and just before]in images, e.g.,. - Link References: Checks for linebreaks in
[label][ref]and[label][]. - Image References: Checks for linebreaks in
![label][ref]and![label][]. - Link Definitions: Checks for linebreaks in
[label]: /url.
Why Is This Important?
Consistent bracket linebreaks:
- Make Markdown easier to read and maintain.
- Prevent accidental formatting issues, especially when editing or copying links/images.
- Align with team or project style preferences.
How Does It Work?
- By default, the rule is set to
newline: "never", disallowing linebreaks just inside the brackets. - You can set it to
newline: "always"to require a linebreak after the opening and before the closing bracket. - With
newline: "consistent", the rule enforces consistency within each bracketed label. - The
multilineoption allows you to require linebreaks only for multi-line labels.
When Should You Use This Rule?
- When you want all Markdown links and images to have a consistent bracket linebreak style.
- When enforcing a style guide for documentation or collaborative writing.
Examples
With never Option (Default)
md
<!-- eslint markdown-preferences/link-bracket-newline: 'error' -->
<!-- ✓ GOOD -->
[foo](/url)

[foo][ref]
[ref]: /url
<!-- ✗ BAD -->
[
foo
](/url)

[foo][
ref
]
[
ref
]: /url🔧 Options
json
{
"markdown-preferences/link-bracket-newline": [
"error",
{
"newline": "never", // or "always" or "consistent"
"multiline": false
}
]
}newline:"never"(Default) - No linebreaks allowed just inside the brackets."always"- Linebreaks required just inside the brackets."consistent"- Enforces consistency within each label.
multiline:false(Default) - Always apply the rule.true- Only require linebreaks for multi-line labels.
📚 Further Reading
👫 Related Rules
🚀 Version
This rule was introduced in eslint-plugin-markdown-preferences v0.22.0