diff --git a/package.json b/package.json index fa2d558d..04c4d2c7 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "dateformat": "^1.0.12", "deep-equal": "^1.0.1", "fuzzy": "^0.1.1", + "gray-matter": "^3.0.3", "history": "^2.1.2", "immutability-helper": "^2.0.0", "immutable": "^3.7.6", @@ -121,9 +122,6 @@ "moment": "^2.11.2", "node-sass": "^3.10.0", "normalize.css": "^4.2.0", - "preliminaries": "^1.3.0", - "preliminaries-parser-toml": "^1.3.0", - "preliminaries-parser-yaml": "^1.3.0", "prismjs": "^1.5.1", "prop-types": "^15.5.10", "react": "^15.1.0", @@ -164,6 +162,7 @@ "slate-edit-table": "^0.10.1", "slate-soft-break": "^0.3.0", "slug": "^0.9.1", + "toml": "^2.3.3", "unified": "^6.1.4", "unist-builder": "^1.0.2", "unist-util-visit-parents": "^1.1.1", diff --git a/src/formats/frontmatter.js b/src/formats/frontmatter.js index 6006bc72..0043cdd0 100644 --- a/src/formats/frontmatter.js +++ b/src/formats/frontmatter.js @@ -1,28 +1,22 @@ -import preliminaries from 'preliminaries'; -import yamlParser from 'preliminaries-parser-yaml'; -import tomlParser from 'preliminaries-parser-toml'; +import matter from 'gray-matter'; +import tomlEng from 'toml'; import YAML from './yaml'; -// Automatically register parsers -preliminaries(true); -yamlParser(true); -tomlParser(true); - function inferFrontmatterFormat(str) { const firstLine = str.substr(0, str.indexOf('\n')).trim(); switch (firstLine) { case "---": - return { lang: "yaml", delims: "---" }; + return { language: "yaml", delimiters: "---" }; case "+++": - return { lang: "toml", delims: "+++" }; + return { language: "toml", delimiters: "+++", engines: { toml: tomlEng.parse.bind(tomlEng) } }; case "{": - return { lang: "json", delims: ["{", "}"] }; + return { language: "json", delimiters: ["{", "}"] }; } } export default class Frontmatter { fromFile(content) { - const result = preliminaries.parse(content, inferFrontmatterFormat(content)); + const result = matter(content, inferFrontmatterFormat(content)); const data = result.data; data.body = result.content; return data; @@ -45,6 +39,6 @@ export default class Frontmatter { return new YAML().toFile(metadata, sortedKeys); }, }; - return preliminaries.stringify(body, meta, { lang: "yaml", delims: "---", parser }); + return matter.stringify(body, meta, { language: "yaml", delimiters: "---", engines: { yaml: parser } }); } } diff --git a/yarn.lock b/yarn.lock index fe2aa47e..82daf1bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3513,6 +3513,14 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" +gray-matter@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-3.0.3.tgz#0451a7eacdcb4f13fcbe12b14725422bc86b1030" + dependencies: + js-yaml "^3.8.1" + kind-of "^5.0.0" + strip-bom-string "^1.0.0" + growly@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" @@ -4809,6 +4817,10 @@ kind-of@^4.0.0: dependencies: is-buffer "^1.1.5" +kind-of@^5.0.0: + version "5.0.2" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.0.2.tgz#f57bec933d9a2209ffa96c5c08343607b7035fda" + known-css-properties@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.2.0.tgz#899c94be368e55b42d7db8d5be7d73a4a4a41454" @@ -6754,23 +6766,6 @@ postcss@^6.0.1, postcss@^6.0.2: source-map "^0.5.6" supports-color "^4.2.1" -preliminaries-parser-toml@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/preliminaries-parser-toml/-/preliminaries-parser-toml-1.3.0.tgz#e62203c45d1c5bf5908b02fb8830336b59a0ebe6" - dependencies: - toml "^2.3.2" - toml-js "0.0.8" - -preliminaries-parser-yaml@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/preliminaries-parser-yaml/-/preliminaries-parser-yaml-1.3.0.tgz#72b5c69c930e322b07ed78a6696d4bf61de73585" - dependencies: - js-yaml "^3.8.1" - -preliminaries@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/preliminaries/-/preliminaries-1.3.0.tgz#da1602e704c36da5dde59b7f4aea2a5380ee6357" - prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" @@ -8257,6 +8252,10 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" +strip-bom-string@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/strip-bom-string/-/strip-bom-string-1.0.0.tgz#e5211e9224369fbb81d633a2f00044dc8cedad92" + strip-bom@3.0.0, strip-bom@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" @@ -8651,11 +8650,7 @@ to-fast-properties@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" -toml-js@0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/toml-js/-/toml-js-0.0.8.tgz#648ea6f1a4d63b19c0bb30b8ed03e40d09473b0a" - -toml@^2.3.2: +toml@^2.3.3: version "2.3.3" resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.3.tgz#8d683d729577cb286231dfc7a8affe58d31728fb"