-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new rule
no-heading-like-paragraph
Closes GH-107.
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/remark-lint/lib/rules/no-heading-like-paragraph.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* @module no-heading-like-paragraph | ||
* @fileoverview | ||
* Warn for h7+ “headings”. | ||
* | ||
* @example {"name": "valid.md"} | ||
* | ||
* ###### Alpha | ||
* | ||
* Bravo. | ||
* | ||
* @example {"name": "invalid.md", "label": "input"} | ||
* | ||
* ####### Charlie | ||
* | ||
* Delta. | ||
* | ||
* @example {"name": "invalid.md", "label": "output"} | ||
* | ||
* 1:1-1:16: This looks like a heading but has too many hashes | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var visit = require('unist-util-visit'); | ||
var generated = require('unist-util-generated'); | ||
|
||
module.exports = noHeadingLikeParagraph; | ||
|
||
var fence = '#######'; | ||
|
||
function noHeadingLikeParagraph(tree, file) { | ||
visit(tree, 'paragraph', visitor); | ||
|
||
function visitor(node) { | ||
var head = node.children[0]; | ||
|
||
if ( | ||
head && | ||
head.type === 'text' && | ||
head.value.slice(0, fence.length) === fence && | ||
!generated(node) | ||
) { | ||
file.message('This looks like a heading but has too many hashes', node); | ||
} | ||
} | ||
} |