diff --git a/doc/rules.md b/doc/rules.md index 89ec8bfe..761b4df8 100644 --- a/doc/rules.md +++ b/doc/rules.md @@ -2,7 +2,7 @@ # List of Rules -This document describes all (59) +This document describes all (60) available rules, what they check for, examples of what they warn for, and how to fix their warnings. @@ -103,6 +103,7 @@ For example, as follows: - [no-file-name-outer-dashes](#no-file-name-outer-dashes) - [no-heading-content-indent](#no-heading-content-indent) - [no-heading-indent](#no-heading-indent) +- [no-heading-like-paragraph](#no-heading-like-paragraph) - [no-heading-punctuation](#no-heading-punctuation) - [no-html](#no-html) - [no-inline-padding](#no-inline-padding) @@ -1738,6 +1739,32 @@ When this rule is turned on, the following file 10:4: Remove 3 spaces before this heading ``` +## `no-heading-like-paragraph` + +Warn for h7+ “headings”. + +When this rule is turned on, the following file +`valid.md` is ok: + +```markdown +###### Alpha + +Bravo. +``` + +When this rule is turned on, the following file +`invalid.md` is **not** ok: + +```markdown +####### Charlie + +Delta. +``` + +```text +1:1-1:16: This looks like a heading but has too many hashes +``` + ## `no-heading-punctuation` Warn when a heading ends with a a group of characters. diff --git a/packages/remark-lint/lib/rules.js b/packages/remark-lint/lib/rules.js index 8f3e0778..47be8d49 100644 --- a/packages/remark-lint/lib/rules.js +++ b/packages/remark-lint/lib/rules.js @@ -38,6 +38,7 @@ module.exports = { 'no-file-name-outer-dashes': require('./rules/no-file-name-outer-dashes.js'), 'no-heading-content-indent': require('./rules/no-heading-content-indent.js'), 'no-heading-indent': require('./rules/no-heading-indent.js'), + 'no-heading-like-paragraph': require('./rules/no-heading-like-paragraph.js'), 'no-heading-punctuation': require('./rules/no-heading-punctuation.js'), 'no-html': require('./rules/no-html.js'), 'no-inline-padding': require('./rules/no-inline-padding.js'), diff --git a/packages/remark-lint/lib/rules/no-heading-like-paragraph.js b/packages/remark-lint/lib/rules/no-heading-like-paragraph.js new file mode 100644 index 00000000..9da336db --- /dev/null +++ b/packages/remark-lint/lib/rules/no-heading-like-paragraph.js @@ -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); + } + } +}