From 0c38635afe5fc75bf6b0f51742945f887e3e3dff Mon Sep 17 00:00:00 2001 From: David Anson Date: Tue, 24 Oct 2017 22:15:03 -0700 Subject: [PATCH] Add TOML title syntax to MD041/first-line-h1 default RegExp (fixes #77). --- lib/rules.js | 2 +- schema/build-config-schema.js | 2 +- schema/markdownlint-config-schema.json | 4 ++-- test/front-matter-alt-title-toml.json | 6 ++++++ test/front-matter-alt-title-toml.md | 6 ++++++ test/front-matter-title-toml.json | 4 ++++ test/front-matter-title-toml.md | 6 ++++++ 7 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test/front-matter-alt-title-toml.json create mode 100644 test/front-matter-alt-title-toml.md create mode 100644 test/front-matter-title-toml.json create mode 100644 test/front-matter-title-toml.md diff --git a/lib/rules.js b/lib/rules.js index ab03f448..9f2c6904 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -1045,7 +1045,7 @@ module.exports = [ var frontMatterTitle = params.options.front_matter_title; var tag = "h" + level; var frontMatterTitleRe = - new RegExp(frontMatterTitle || "^\\s*title:", "i"); + 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)) || diff --git a/schema/build-config-schema.js b/schema/build-config-schema.js index 6ed88199..1d84c4a6 100644 --- a/schema/build-config-schema.js +++ b/schema/build-config-schema.js @@ -224,7 +224,7 @@ rules.forEach(function forRule(rule) { "front_matter_title": { "description": "RegExp for matching title in front matter", "type": "string", - "default": "^\\s*title:" + "default": "^\\s*title\\s*[:=]" } }; break; diff --git a/schema/markdownlint-config-schema.json b/schema/markdownlint-config-schema.json index b6da4001..da53e01b 100644 --- a/schema/markdownlint-config-schema.json +++ b/schema/markdownlint-config-schema.json @@ -832,7 +832,7 @@ "front_matter_title": { "description": "RegExp for matching title in front matter", "type": "string", - "default": "^\\s*title:" + "default": "^\\s*title\\s*[:=]" } }, "additionalProperties": false @@ -853,7 +853,7 @@ "front_matter_title": { "description": "RegExp for matching title in front matter", "type": "string", - "default": "^\\s*title:" + "default": "^\\s*title\\s*[:=]" } }, "additionalProperties": false diff --git a/test/front-matter-alt-title-toml.json b/test/front-matter-alt-title-toml.json new file mode 100644 index 00000000..907306f9 --- /dev/null +++ b/test/front-matter-alt-title-toml.json @@ -0,0 +1,6 @@ +{ + "default": true, + "MD041": { + "front_matter_title": "^\\s*alternate\\s*=" + } +} diff --git a/test/front-matter-alt-title-toml.md b/test/front-matter-alt-title-toml.md new file mode 100644 index 00000000..6bbc8cf5 --- /dev/null +++ b/test/front-matter-alt-title-toml.md @@ -0,0 +1,6 @@ ++++ +date = "2017-01-26T22:17:00+02:00" +alternate = "My document title and header" ++++ + +Some plain text here. diff --git a/test/front-matter-title-toml.json b/test/front-matter-title-toml.json new file mode 100644 index 00000000..054e8566 --- /dev/null +++ b/test/front-matter-title-toml.json @@ -0,0 +1,4 @@ +{ + "default": true, + "MD041": true +} diff --git a/test/front-matter-title-toml.md b/test/front-matter-title-toml.md new file mode 100644 index 00000000..ed3eae53 --- /dev/null +++ b/test/front-matter-title-toml.md @@ -0,0 +1,6 @@ ++++ +date = "2017-01-26T22:17:00+02:00" +title = "My document title and header" ++++ + +Some plain text here.