From 072da48add16b7701f949864b58483b6543f6550 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sun, 29 Apr 2018 12:02:47 -0700 Subject: [PATCH] Relax MD041/first-line-h1 to allow blank links above the top level header (fixes #116). --- lib/md041.js | 15 ++++++--------- ...e.json => hugo-quickstart-example-blank.json} | 0 ...issue.md => hugo-quickstart-example-blank.md} | 16 ++++++++-------- .../md041-yaml-title-and-first-line-heading.json | 9 +++++++++ test/md041-yaml-title-and-first-line-heading.md | 7 +++++++ 5 files changed, 30 insertions(+), 17 deletions(-) rename test/{hugo-quickstart-example-issue.json => hugo-quickstart-example-blank.json} (100%) rename test/{hugo-quickstart-example-issue.md => hugo-quickstart-example-blank.md} (77%) create mode 100644 test/md041-yaml-title-and-first-line-heading.json create mode 100644 test/md041-yaml-title-and-first-line-heading.md diff --git a/lib/md041.js b/lib/md041.js index 1d29be53..c34b4950 100644 --- a/lib/md041.js +++ b/lib/md041.js @@ -14,17 +14,14 @@ module.exports = { const tag = "h" + level; const frontMatterTitleRe = new RegExp(frontMatterTitle || "^\\s*title\\s*[:=]", "i"); - params.tokens.every(function forToken(token, index) { - if (token.type === "heading_open") { - if (!((token.lineNumber === 1) || (index > 0)) || - (token.tag !== tag)) { + params.tokens.every(function forToken(token) { + if (token.type === "html_block") { + return true; + } else if (token.type === "heading_open") { + if (token.tag !== tag) { shared.addErrorContext(onError, token.lineNumber, token.line); } - return false; - } else if (token.type === "html_block") { - return true; - } - if (((frontMatterTitle !== undefined) && !frontMatterTitle) || + } else if (((frontMatterTitle !== undefined) && !frontMatterTitle) || !params.frontMatterLines.some(function forLine(line) { return frontMatterTitleRe.test(line); })) { diff --git a/test/hugo-quickstart-example-issue.json b/test/hugo-quickstart-example-blank.json similarity index 100% rename from test/hugo-quickstart-example-issue.json rename to test/hugo-quickstart-example-blank.json diff --git a/test/hugo-quickstart-example-issue.md b/test/hugo-quickstart-example-blank.md similarity index 77% rename from test/hugo-quickstart-example-issue.md rename to test/hugo-quickstart-example-blank.md index 1bfb15ba..a0e98dc9 100644 --- a/test/hugo-quickstart-example-issue.md +++ b/test/hugo-quickstart-example-blank.md @@ -1,8 +1,8 @@ -+++ -date = "2016-02-14T16:11:58+05:30" -draft = true -title = "Good to Great Book Review" - -+++ - -# Heading 1 {MD041} ++++ +date = "2016-02-14T16:11:58+05:30" +draft = true +title = "Good to Great Book Review" + ++++ + +# Heading 1 diff --git a/test/md041-yaml-title-and-first-line-heading.json b/test/md041-yaml-title-and-first-line-heading.json new file mode 100644 index 00000000..e8e56758 --- /dev/null +++ b/test/md041-yaml-title-and-first-line-heading.json @@ -0,0 +1,9 @@ +{ + "default": true, + "MD002": { + "level": 2 + }, + "MD041": { + "level": 2 + } +} diff --git a/test/md041-yaml-title-and-first-line-heading.md b/test/md041-yaml-title-and-first-line-heading.md new file mode 100644 index 00000000..8f512b19 --- /dev/null +++ b/test/md041-yaml-title-and-first-line-heading.md @@ -0,0 +1,7 @@ +--- +path: "/post" +date: "2012-06-21T10:14:00.000+02:00" +title: "First level heading" +--- + +## Second level heading