diff --git a/src/utils/front-matter.js b/src/utils/front-matter.js index 35c49125..2002486f 100644 --- a/src/utils/front-matter.js +++ b/src/utils/front-matter.js @@ -13,14 +13,17 @@ function parse(text) { .join("|"); const match = text.match( - new RegExp(`^(${delimiterRegex})\\n(?:([\\s\\S]*?)\\n)?\\1(\\n|$)`) + // trailing spaces after delimiters are allowed + new RegExp( + `^(${delimiterRegex})[^\\n\\S]*\\n(?:([\\s\\S]*?)\\n)?\\1[^\\n\\S]*(\\n|$)` + ) ); if (match === null) { return { frontMatter: null, content: text }; } - const raw = match[0].trimRight(); + const raw = match[0].replace(/\n$/, ""); const delimiter = match[1]; const value = match[2]; diff --git a/tests/markdown_yaml/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_yaml/__snapshots__/jsfmt.spec.js.snap index 48d89fc2..3d6aa39c 100644 --- a/tests/markdown_yaml/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_yaml/__snapshots__/jsfmt.spec.js.snap @@ -64,3 +64,22 @@ hello: world Content `; + +exports[`trailing-spaces.md - markdown-verify 1`] = ` +--- + v spaces +--- + +This paragraph should be considered part of the _markdown_ instead of *yaml*. + +--- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +--- +v spaces +--- + +This paragraph should be considered part of the _markdown_ instead of _yaml_. + +--- + +`; diff --git a/tests/markdown_yaml/trailing-spaces.md b/tests/markdown_yaml/trailing-spaces.md new file mode 100644 index 00000000..447c3272 --- /dev/null +++ b/tests/markdown_yaml/trailing-spaces.md @@ -0,0 +1,7 @@ +--- + v spaces +--- + +This paragraph should be considered part of the _markdown_ instead of *yaml*. + +---