Skip to content

Commit

Permalink
Remove support for nested nodes
Browse files Browse the repository at this point in the history
Frontmatter nodes only exist on the mdast root.
  • Loading branch information
remcohaszing committed Nov 7, 2021
1 parent 7c7b001 commit 4e9d66f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"estree-util-is-identifier-name": "^1.0.0",
"estree-util-value-to-estree": "^1.0.0",
"js-yaml": "^4.0.0",
"toml": "^3.0.0",
"unist-util-visit": "^2.0.0"
"toml": "^3.0.0"
},
"devDependencies": {
"@mdx-js/mdx": "^2.0.0-rc.1",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Root, YAML } from 'mdast';
import { MDXJSEsm } from 'mdast-util-mdx';
import { parse } from 'toml';
import { Attacher } from 'unified';
import * as visit from 'unist-util-visit';

export interface RemarkMdxFrontmatterOptions {
/**
Expand Down Expand Up @@ -35,11 +34,12 @@ export const remarkMdxFrontmatter: Attacher<[RemarkMdxFrontmatterOptions?]> =
);
}

visit(mdast, (node) => {
for (const node of mdast.children) {
let data: unknown;
const { value } = node as YAML;
if (node.type === 'yaml') {
data = load(value);
// @ts-expect-error A custom node type may be registered for TOML frontmatter data.
} else if (node.type === 'toml') {
data = parse(value);
}
Expand Down Expand Up @@ -87,6 +87,6 @@ export const remarkMdxFrontmatter: Attacher<[RemarkMdxFrontmatterOptions?]> =
},
},
});
});
}
mdast.children.unshift(...imports);
};
22 changes: 0 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3472,11 +3472,6 @@ unist-util-generated@^2.0.0:
resolved "https://registry.yarnpkg.com/unist-util-generated/-/unist-util-generated-2.0.0.tgz#86fafb77eb6ce9bfa6b663c3f5ad4f8e56a60113"
integrity sha512-TiWE6DVtVe7Ye2QxOVW9kqybs6cZexNwTwSMVgkfjEReqy/xwGpAXb99OxktoWwmL+Z+Epb0Dn8/GNDYP1wnUw==

unist-util-is@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-4.1.0.tgz#976e5f462a7a5de73d94b706bac1b90671b57797"
integrity sha512-ZOQSsnce92GrxSqlnEEseX0gi7GH9zTJZ0p9dtu87WRb/37mMPO2Ilx1s/t9vBHrFhbgweUwb+t7cIn5dxPhZg==

unist-util-is@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-5.1.1.tgz#e8aece0b102fa9bc097b0fef8f870c496d4a6236"
Expand Down Expand Up @@ -3516,14 +3511,6 @@ unist-util-stringify-position@^3.0.0:
dependencies:
"@types/unist" "^2.0.0"

unist-util-visit-parents@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-3.1.1.tgz#65a6ce698f78a6b0f56aa0e88f13801886cdaef6"
integrity sha512-1KROIZWo6bcMrZEwiH2UrXDyalAa0uqzWCxCJj6lPOvTve2WkfgCytoDTPaMnodXh1WrXOq0haVYHj99ynJlsg==
dependencies:
"@types/unist" "^2.0.0"
unist-util-is "^4.0.0"

unist-util-visit-parents@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-4.1.1.tgz#e83559a4ad7e6048a46b1bdb22614f2f3f4724f2"
Expand All @@ -3540,15 +3527,6 @@ unist-util-visit-parents@^5.0.0:
"@types/unist" "^2.0.0"
unist-util-is "^5.0.0"

unist-util-visit@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-2.0.3.tgz#c3703893146df47203bb8a9795af47d7b971208c"
integrity sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==
dependencies:
"@types/unist" "^2.0.0"
unist-util-is "^4.0.0"
unist-util-visit-parents "^3.0.0"

unist-util-visit@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-3.1.0.tgz#9420d285e1aee938c7d9acbafc8e160186dbaf7b"
Expand Down

0 comments on commit 4e9d66f

Please sign in to comment.