mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add MD036 with tests.
This commit is contained in:
parent
762d8425ca
commit
bd7e712728
5 changed files with 102 additions and 3 deletions
|
@ -66,6 +66,7 @@ cases come directly from that project.
|
|||
* **MD033** - Inline HTML
|
||||
* **MD034** - Bare URL used
|
||||
* **MD035** - Horizontal rule style
|
||||
* **MD036** - Emphasis used instead of a header
|
||||
|
||||
See [Rules.md](doc/Rules.md) for more details.
|
||||
|
||||
|
@ -77,9 +78,10 @@ See [Rules.md](doc/Rules.md) for more details.
|
|||
* **blockquote** - MD027, MD028
|
||||
* **bullet** - MD004, MD005, MD006, MD007, MD032
|
||||
* **code** - MD014, MD031
|
||||
* **emphasis** - MD036
|
||||
* **hard_tab** - MD010
|
||||
* **headers** - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023,
|
||||
MD024, MD025, MD026
|
||||
MD024, MD025, MD026, MD036
|
||||
* **hr** - MD035
|
||||
* **html** - MD033
|
||||
* **indentation** - MD005, MD006, MD007, MD027
|
||||
|
|
29
doc/Rules.md
29
doc/Rules.md
|
@ -765,3 +765,32 @@ rules are different than the first one encountered in the document. If you
|
|||
want to configure the rule to match a specific style, the parameter given to
|
||||
the 'style' option is a string containing the exact horizontal rule text that
|
||||
is allowed.
|
||||
|
||||
## MD036 - Emphasis used instead of a header
|
||||
|
||||
Tags: headers, emphasis
|
||||
|
||||
This check looks for instances where emphasized (i.e. bold or italic) text is
|
||||
used to separate sections, where a header should be used instead:
|
||||
|
||||
**My document**
|
||||
|
||||
Lorem ipsum dolor sit amet...
|
||||
|
||||
_Another section_
|
||||
|
||||
Consectetur adipiscing elit, sed do eiusmod.
|
||||
|
||||
To fix this, use markdown headers instead of emphasized text to denote
|
||||
sections:
|
||||
|
||||
# My document
|
||||
|
||||
Lorem ipsum dolor sit amet...
|
||||
|
||||
## Another section
|
||||
|
||||
Consectetur adipiscing elit, sed do eiusmod.
|
||||
|
||||
Note: this rule looks for paragraphs that consist entirely of emphasized text.
|
||||
It won't fire on emphasis used within regular text.
|
||||
|
|
33
lib/rules.js
33
lib/rules.js
|
@ -667,5 +667,38 @@ module.exports = [
|
|||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD036",
|
||||
"desc": "Emphasis used instead of a header",
|
||||
"tags": [ "headers", "emphasis" ],
|
||||
"func": function MD036(params, errors) {
|
||||
var lineNumber = 0;
|
||||
function base(token) {
|
||||
lineNumber = token.lineNumber;
|
||||
if (token.type === "paragraph_open") {
|
||||
return function inParagraph(t) {
|
||||
if ((t.type === "inline") &&
|
||||
(t.children.length === 3) &&
|
||||
((t.children[0].type === "strong_open") ||
|
||||
(t.children[0].type === "em_open")) &&
|
||||
(t.children[1].type === "text")) {
|
||||
errors.push(lineNumber);
|
||||
}
|
||||
};
|
||||
} else if (token.type === "blockquote_open") {
|
||||
return function inBlockquote(t) {
|
||||
if (t.type !== "blockquote_close") {
|
||||
return inBlockquote;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
var state = base;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
state = state(token) || base;
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
35
test/emphasis_instead_of_headers.md
Normal file
35
test/emphasis_instead_of_headers.md
Normal file
|
@ -0,0 +1,35 @@
|
|||
**Section 1: the first section {MD036}**
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
||||
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
|
||||
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
|
||||
in culpa qui officia deserunt mollit anim id est laborum.
|
||||
|
||||
__Section 1.1: another section {MD036}__
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
||||
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
|
||||
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
|
||||
in culpa qui officia deserunt mollit anim id est laborum.
|
||||
|
||||
*Section 2: yet more sections {MD036}*
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
||||
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
|
||||
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
|
||||
in culpa qui officia deserunt mollit anim id est laborum.
|
||||
|
||||
_Section 3: oh no more sections {MD036}_
|
||||
|
||||
This is a normal paragraph
|
||||
**that just happens to have emphasized text in**
|
||||
even though the emphasized text is on its own line.
|
||||
|
||||
This is another **normal** paragraph with some text in it. This also should
|
||||
not trigger the rule.
|
|
@ -498,7 +498,7 @@ module.exports.badFileSync = function badFileSync(test) {
|
|||
};
|
||||
|
||||
module.exports.readme = function readme(test) {
|
||||
test.expect(83);
|
||||
test.expect(86);
|
||||
var tagToRules = {};
|
||||
rules.forEach(function forRule(rule) {
|
||||
rule.tags.forEach(function forTag(tag) {
|
||||
|
@ -555,7 +555,7 @@ module.exports.readme = function readme(test) {
|
|||
};
|
||||
|
||||
module.exports.doc = function doc(test) {
|
||||
test.expect(127);
|
||||
test.expect(131);
|
||||
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
||||
function readFile(err, contents) {
|
||||
test.ifError(err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue