mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Relax MD041/first-line-h1 to allow blank links above the top level header (fixes #116).
This commit is contained in:
parent
017fe127fa
commit
072da48add
5 changed files with 30 additions and 17 deletions
15
lib/md041.js
15
lib/md041.js
|
|
@ -14,17 +14,14 @@ module.exports = {
|
||||||
const tag = "h" + level;
|
const tag = "h" + level;
|
||||||
const frontMatterTitleRe =
|
const frontMatterTitleRe =
|
||||||
new RegExp(frontMatterTitle || "^\\s*title\\s*[:=]", "i");
|
new RegExp(frontMatterTitle || "^\\s*title\\s*[:=]", "i");
|
||||||
params.tokens.every(function forToken(token, index) {
|
params.tokens.every(function forToken(token) {
|
||||||
if (token.type === "heading_open") {
|
if (token.type === "html_block") {
|
||||||
if (!((token.lineNumber === 1) || (index > 0)) ||
|
return true;
|
||||||
(token.tag !== tag)) {
|
} else if (token.type === "heading_open") {
|
||||||
|
if (token.tag !== tag) {
|
||||||
shared.addErrorContext(onError, token.lineNumber, token.line);
|
shared.addErrorContext(onError, token.lineNumber, token.line);
|
||||||
}
|
}
|
||||||
return false;
|
} else if (((frontMatterTitle !== undefined) && !frontMatterTitle) ||
|
||||||
} else if (token.type === "html_block") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (((frontMatterTitle !== undefined) && !frontMatterTitle) ||
|
|
||||||
!params.frontMatterLines.some(function forLine(line) {
|
!params.frontMatterLines.some(function forLine(line) {
|
||||||
return frontMatterTitleRe.test(line);
|
return frontMatterTitleRe.test(line);
|
||||||
})) {
|
})) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
+++
|
+++
|
||||||
date = "2016-02-14T16:11:58+05:30"
|
date = "2016-02-14T16:11:58+05:30"
|
||||||
draft = true
|
draft = true
|
||||||
title = "Good to Great Book Review"
|
title = "Good to Great Book Review"
|
||||||
|
|
||||||
+++
|
+++
|
||||||
|
|
||||||
# Heading 1 {MD041}
|
# Heading 1
|
||||||
9
test/md041-yaml-title-and-first-line-heading.json
Normal file
9
test/md041-yaml-title-and-first-line-heading.json
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD002": {
|
||||||
|
"level": 2
|
||||||
|
},
|
||||||
|
"MD041": {
|
||||||
|
"level": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
7
test/md041-yaml-title-and-first-line-heading.md
Normal file
7
test/md041-yaml-title-and-first-line-heading.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
path: "/post"
|
||||||
|
date: "2012-06-21T10:14:00.000+02:00"
|
||||||
|
title: "First level heading"
|
||||||
|
---
|
||||||
|
|
||||||
|
## Second level heading
|
||||||
Loading…
Add table
Add a link
Reference in a new issue