diff --git a/README.md b/README.md index 03ede739..0dc71bf1 100644 --- a/README.md +++ b/README.md @@ -429,11 +429,12 @@ ignores common forms of "front matter". To match differently, specify a custom The default value: ```js -/((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$))(\r\n|\r|\n|$)/m +/((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$)|(^\{\s*$[^]*?^\}\s*$))(\r\n|\r|\n|$)/m ``` -Ignores [YAML](https://en.wikipedia.org/wiki/YAML) and -[TOML](https://en.wikipedia.org/wiki/TOML) such as: +Ignores [YAML](https://en.wikipedia.org/wiki/YAML), +[TOML](https://en.wikipedia.org/wiki/TOML), and +[JSON](https://en.wikipedia.org/wiki/JSON) front matter such as: ```text --- diff --git a/doc/Rules.md b/doc/Rules.md index 742eb099..646df852 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -848,7 +848,7 @@ Tags: headings, headers Aliases: single-title, single-h1 -Parameters: level, front_matter_title (number; default 1, string; default "^\s*title:") +Parameters: level, front_matter_title (number; default 1, string; default "^\s*"?title"?\s*[:=]") This rule is triggered when a top level heading is in use (the first line of the file is a h1 heading), and more than one h1 heading is in use in the @@ -1565,7 +1565,7 @@ Tags: headings, headers Aliases: first-line-heading, first-line-h1 -Parameters: level, front_matter_title (number; default 1, string; default "^\s*title:") +Parameters: level, front_matter_title (number; default 1, string; default "^\s*"?title"?\s*[:=]") This rule is intended to ensure documents have a title and is triggered when the first line in the file isn't a top level (h1) heading: diff --git a/helpers/helpers.js b/helpers/helpers.js index 1fc53a20..ad6e9b6d 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -12,7 +12,7 @@ module.exports.newLineRe = newLineRe; // Regular expression for matching common front matter (YAML and TOML) module.exports.frontMatterRe = // eslint-disable-next-line max-len - /((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$))(\r\n|\r|\n|$)/m; + /((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$)|(^\{\s*$[^]*?^\}\s*$))(\r\n|\r|\n|$)/m; // Regular expression for matching inline disable/enable comments const inlineCommentRe = @@ -502,7 +502,10 @@ module.exports.frontMatterHasTitle = const ignoreFrontMatter = (frontMatterTitlePattern !== undefined) && !frontMatterTitlePattern; const frontMatterTitleRe = - new RegExp(String(frontMatterTitlePattern || "^\\s*title\\s*[:=]"), "i"); + new RegExp( + String(frontMatterTitlePattern || "^\\s*\"?title\"?\\s*[:=]"), + "i" + ); return !ignoreFrontMatter && frontMatterLines.some((line) => frontMatterTitleRe.test(line)); }; diff --git a/test/front-matter-alt-title-json.json b/test/front-matter-alt-title-json.json new file mode 100644 index 00000000..917abe7a --- /dev/null +++ b/test/front-matter-alt-title-json.json @@ -0,0 +1,6 @@ +{ + "default": true, + "MD041": { + "front_matter_title": "^\\s*\"alternate\"\\s*:" + } +} diff --git a/test/front-matter-alt-title-json.md b/test/front-matter-alt-title-json.md new file mode 100644 index 00000000..148f28a2 --- /dev/null +++ b/test/front-matter-alt-title-json.md @@ -0,0 +1,6 @@ +{ +"date": "2017-01-26T22:17:00+02:00", +"alternate": "My document title and heading" +} + +Some plain text here. diff --git a/test/front-matter-title-json-spaces.json b/test/front-matter-title-json-spaces.json new file mode 100644 index 00000000..054e8566 --- /dev/null +++ b/test/front-matter-title-json-spaces.json @@ -0,0 +1,4 @@ +{ + "default": true, + "MD041": true +} diff --git a/test/front-matter-title-json-spaces.md b/test/front-matter-title-json-spaces.md new file mode 100644 index 00000000..44be0339 --- /dev/null +++ b/test/front-matter-title-json-spaces.md @@ -0,0 +1,6 @@ +{ +"date": "2017-01-26T22:17:00+02:00", +"title": "My document title and heading" +} + +Some plain text here. diff --git a/test/front-matter-title-json.json b/test/front-matter-title-json.json new file mode 100644 index 00000000..054e8566 --- /dev/null +++ b/test/front-matter-title-json.json @@ -0,0 +1,4 @@ +{ + "default": true, + "MD041": true +} diff --git a/test/front-matter-title-json.md b/test/front-matter-title-json.md new file mode 100644 index 00000000..a7b171c3 --- /dev/null +++ b/test/front-matter-title-json.md @@ -0,0 +1,6 @@ +{ +"date": "2017-01-26T22:17:00+02:00", +"title": "My document title and heading" +} + +Some plain text here. diff --git a/test/hugo-quickstart-example-json.json b/test/hugo-quickstart-example-json.json new file mode 100644 index 00000000..054e8566 --- /dev/null +++ b/test/hugo-quickstart-example-json.json @@ -0,0 +1,4 @@ +{ + "default": true, + "MD041": true +} diff --git a/test/hugo-quickstart-example-json.md b/test/hugo-quickstart-example-json.md new file mode 100644 index 00000000..44a21b39 --- /dev/null +++ b/test/hugo-quickstart-example-json.md @@ -0,0 +1,13 @@ +{ + "title": "Another Hugo Post", + "description": "Nothing special, but one post is boring.", + "date": "2014-09-02", + "categories": [ "example", "configuration" ], + "tags": [ + "example", + "hugo", + "toml" + ], +} + +# Heading {MD025}