diff --git a/package-lock.json b/package-lock.json index e54cd500..1c8c7f8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@eslint/css": "^0.2.0", "@eslint/js": "^9.9.0", "@eslint/json": "^0.4.1", - "@eslint/markdown": "^6.1.1", + "@eslint/markdown": "^6.4.0", "@lezer/highlight": "^1.2.1", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-dialog": "^1.1.1", @@ -1162,6 +1162,18 @@ "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, + "node_modules/@eslint/core": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.10.0.tgz", + "integrity": "sha512-gFHJ+xBOo4G3WRlR1e/3G8A6/KZAH6zcE/hkLRCZTi/B9avAG365QhFA8uOGzTMqgTghpn7/fSnscW++dpMSAw==", + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/css": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@eslint/css/-/css-0.2.0.tgz", @@ -1260,14 +1272,17 @@ } }, "node_modules/@eslint/markdown": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/@eslint/markdown/-/markdown-6.1.1.tgz", - "integrity": "sha512-Z+1js5AeqidwhNBbnIPM6Fn4eY9D5i1NleamS0UBW6BG0J4lpvhIVOKVIi22kmH5gvxDmHUp5MHkkkjda0TehA==", + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@eslint/markdown/-/markdown-6.4.0.tgz", + "integrity": "sha512-J07rR8uBSNFJ9iliNINrchilpkmCihPmTVotpThUeKEn5G8aBBZnkjNBy/zovhJA5LBk1vWU9UDlhqKSc/dViQ==", "license": "MIT", "dependencies": { - "@eslint/plugin-kit": "^0.2.0", - "mdast-util-from-markdown": "^2.0.1", + "@eslint/core": "^0.10.0", + "@eslint/plugin-kit": "^0.2.5", + "mdast-util-from-markdown": "^2.0.2", + "mdast-util-frontmatter": "^2.0.1", "mdast-util-gfm": "^3.0.0", + "micromark-extension-frontmatter": "^2.0.0", "micromark-extension-gfm": "^3.0.0" }, "engines": { @@ -1275,17 +1290,30 @@ } }, "node_modules/@eslint/markdown/node_modules/@eslint/plugin-kit": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.0.tgz", - "integrity": "sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==", + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.8.tgz", + "integrity": "sha512-ZAoA40rNMPwSm+AeHpCq8STiNAwzWLJuP8Xv4CHIc9wv/PSuExjMrmjfYNj682vW0OOiZ1HKxzvjQr9XZIisQA==", "license": "Apache-2.0", "dependencies": { + "@eslint/core": "^0.13.0", "levn": "^0.4.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/markdown/node_modules/@eslint/plugin-kit/node_modules/@eslint/core": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.13.0.tgz", + "integrity": "sha512-yfkgDw1KR66rkT5A8ci4irzDysN7FRpq3ttJolR88OqQikAWqwA8j5VZyas+vjyBNFIJ7MfybJ9plMILI2UrCw==", + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/plugin-kit": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", @@ -2910,7 +2938,6 @@ "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", - "dev": true, "license": "MIT" }, "node_modules/@types/mdast": { @@ -5055,6 +5082,19 @@ "reusify": "^1.0.4" } }, + "node_modules/fault": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fault/-/fault-2.0.1.tgz", + "integrity": "sha512-WtySTkS4OKev5JtpHXnib4Gxiurzh5NCGvWrFaZ34m6JehfTUhKZvn9njTfw48t6JumVQOmrKqpmGcdwxnhqBQ==", + "license": "MIT", + "dependencies": { + "format": "^0.2.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -5162,6 +5202,14 @@ "node": ">= 18" } }, + "node_modules/format": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/format/-/format-0.2.2.tgz", + "integrity": "sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==", + "engines": { + "node": ">=0.4.x" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -6885,9 +6933,10 @@ } }, "node_modules/mdast-util-from-markdown": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/mdast-util-from-markdown/-/mdast-util-from-markdown-2.0.1.tgz", - "integrity": "sha512-aJEUyzZ6TzlsX2s5B4Of7lN7EQtAxvtradMMglCQDyaTFgse6CmtmdJ15ElnVRlCg1vpNyVtbem0PWzlNieZsA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/mdast-util-from-markdown/-/mdast-util-from-markdown-2.0.2.tgz", + "integrity": "sha512-uZhTV/8NBuw0WHkPTrCqDOl0zVe1BIng5ZtHoDk49ME1qqcjYmmLmOf0gELgcRMxN4w2iuIeVso5/6QymSrgmA==", + "license": "MIT", "dependencies": { "@types/mdast": "^4.0.0", "@types/unist": "^3.0.0", @@ -6907,6 +6956,36 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/mdast-util-frontmatter": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/mdast-util-frontmatter/-/mdast-util-frontmatter-2.0.1.tgz", + "integrity": "sha512-LRqI9+wdgC25P0URIJY9vwocIzCcksduHQ9OF2joxQoyTNVduwLAFUzjoopuRJbJAReaKrNQKAZKL3uCMugWJA==", + "license": "MIT", + "dependencies": { + "@types/mdast": "^4.0.0", + "devlop": "^1.0.0", + "escape-string-regexp": "^5.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0", + "micromark-extension-frontmatter": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdast-util-frontmatter/node_modules/escape-string-regexp": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", + "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/mdast-util-gfm": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/mdast-util-gfm/-/mdast-util-gfm-3.0.0.tgz", @@ -7143,6 +7222,22 @@ "micromark-util-types": "^2.0.0" } }, + "node_modules/micromark-extension-frontmatter": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/micromark-extension-frontmatter/-/micromark-extension-frontmatter-2.0.0.tgz", + "integrity": "sha512-C4AkuM3dA58cgZha7zVnuVxBhDsbttIMiytjgsM2XbHAB2faRVaHRle40558FBN+DJcrLNCoqG5mlrpdU4cRtg==", + "license": "MIT", + "dependencies": { + "fault": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/micromark-extension-gfm": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/micromark-extension-gfm/-/micromark-extension-gfm-3.0.0.tgz", diff --git a/package.json b/package.json index 59d74ed5..94aaeafd 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@eslint/css": "^0.2.0", "@eslint/js": "^9.9.0", "@eslint/json": "^0.4.1", - "@eslint/markdown": "^6.1.1", + "@eslint/markdown": "^6.4.0", "@lezer/highlight": "^1.2.1", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-dialog": "^1.1.1", diff --git a/src/components/options.tsx b/src/components/options.tsx index 4171f3fa..681b9d33 100644 --- a/src/components/options.tsx +++ b/src/components/options.tsx @@ -10,6 +10,7 @@ import { useExplorer } from "@/hooks/use-explorer"; import { jsonModes, markdownModes, + markdownFrontmatters, languages, parsers, sourceTypes, @@ -24,6 +25,7 @@ import type { JsonMode, Language, MarkdownMode, + MarkdownFrontmatter, SourceType, Version, } from "@/hooks/use-explorer"; @@ -50,19 +52,36 @@ const JSONPanel: React.FC = () => { const MarkdownPanel: React.FC = () => { const explorer = useExplorer(); const { markdownOptions, setMarkdownOptions } = explorer; - const { markdownMode } = markdownOptions; + const { markdownMode, markdownFrontmatter } = markdownOptions; return ( - { - const markdownMode = value as MarkdownMode; - setMarkdownOptions({ ...markdownOptions, markdownMode }); - }} - items={markdownModes} - placeholder="Mode" - /> + <> + { + const markdownMode = value as MarkdownMode; + setMarkdownOptions({ ...markdownOptions, markdownMode }); + }} + items={markdownModes} + placeholder="Mode" + /> + + { + const markdownFrontmatter = value as MarkdownFrontmatter; + setMarkdownOptions({ + ...markdownOptions, + markdownFrontmatter, + }); + }} + items={markdownFrontmatters} + placeholder="Front Matter" + /> + ); }; diff --git a/src/hooks/use-ast.ts b/src/hooks/use-ast.ts index 6af90feb..6903fad1 100644 --- a/src/hooks/use-ast.ts +++ b/src/hooks/use-ast.ts @@ -43,14 +43,29 @@ export function useAST() { case "json": { const { jsonMode } = jsonOptions; const language = json.languages[jsonMode]; - astParseResult = language.parse({ body: code.json }); + astParseResult = language.parse({ + body: code.json, + path: "", + physicalPath: "", + bom: false, + }); break; } case "markdown": { - const { markdownMode } = markdownOptions; + const { markdownMode, markdownFrontmatter } = markdownOptions; const language = markdown.languages[markdownMode]; - astParseResult = language.parse({ body: code.markdown }); + astParseResult = language.parse( + { body: code.markdown, path: "", physicalPath: "", bom: false }, + { + languageOptions: { + frontmatter: + markdownFrontmatter === "off" + ? false + : markdownFrontmatter, + }, + }, + ); break; } @@ -58,7 +73,7 @@ export function useAST() { const { cssMode, tolerant } = cssOptions; const language = css.languages[cssMode]; astParseResult = language.parse( - { body: code.css }, + { body: code.css, path: "", physicalPath: "", bom: false }, { languageOptions: { tolerant } }, ); break; diff --git a/src/hooks/use-explorer.ts b/src/hooks/use-explorer.ts index dccc8f63..0a47cfbe 100644 --- a/src/hooks/use-explorer.ts +++ b/src/hooks/use-explorer.ts @@ -20,6 +20,7 @@ export type Version = Exclude; export type Language = "javascript" | "json" | "markdown" | "css"; export type JsonMode = "json" | "jsonc" | "json5"; export type MarkdownMode = "commonmark" | "gfm"; +export type MarkdownFrontmatter = "off" | "yaml" | "toml"; export type CssMode = "css"; export type Code = { @@ -41,6 +42,7 @@ export type JsonOptions = { export type MarkdownOptions = { markdownMode: MarkdownMode; + markdownFrontmatter: MarkdownFrontmatter; }; export type CssOptions = { diff --git a/src/lib/const.ts b/src/lib/const.ts index cc4b79e8..37b546b4 100644 --- a/src/lib/const.ts +++ b/src/lib/const.ts @@ -190,6 +190,21 @@ export const markdownModes = [ }, ]; +export const markdownFrontmatters = [ + { + value: "off", + label: "Off", + }, + { + value: "yaml", + label: "YAML", + }, + { + value: "toml", + label: "TOML", + }, +]; + export const cssModes = [ { value: "css", @@ -381,6 +396,7 @@ export const defaultJsonOptions: JsonOptions = { export const defaultMarkdownOptions: MarkdownOptions = { markdownMode: "commonmark", + markdownFrontmatter: "off", }; export const defaultCssOptions: CssOptions = {