@dogsbay/format-starlight 0.2.0-beta.131 → 0.2.0-beta.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,18 @@ import { FIXED_SLUG, githubSlug } from "../github-slug.js";
15
15
  import { outsideFences, outsideInlineCode } from "../fences.js";
16
16
  import { findSelfClosingTags, parseJsLiteral } from "../js-literal.js";
17
17
  import { componentPropDefaults, jsValueToJinja, renderComponentTemplate, splitTopLevel } from "../jsx-to-jinja.js";
18
+ /**
19
+ * gray-matter EVALUATES front matter that opens with `---js` / `---javascript` (its javascript
20
+ * engine is `eval`), so a page in someone else's repo could run code on this machine. Every
21
+ * call passes this, which refuses that engine; YAML and JSON are unchanged.
22
+ */
23
+ const NO_JS_FRONT_MATTER = {
24
+ engines: {
25
+ javascript: () => {
26
+ throw new Error("JavaScript front matter is not run");
27
+ },
28
+ },
29
+ };
18
30
  // ── Indentation helper ─────────────────────────────────
19
31
  /**
20
32
  * Indent all lines of content to match the indentation of the original tag.
@@ -856,7 +868,7 @@ export function resolvePlanBadges(source, partialsDir) {
856
868
  */
857
869
  function readYaml(file) {
858
870
  const yaml = readFileSync(file, "utf8").replace(/^\uFEFF?---[ \t]*\r?\n/, "");
859
- return matter(`---\n${yaml}\n---\n`).data;
871
+ return matter(`---\n${yaml}\n---\n`, NO_JS_FRONT_MATTER).data;
860
872
  }
861
873
  const yamlCache = new Map();
862
874
  function cachedYaml(file) {
@@ -1239,7 +1251,7 @@ export function resolveLocalDataComponents(source, partialsDir) {
1239
1251
  const file = within(content, join(dir, f));
1240
1252
  if (!file)
1241
1253
  throw new Error("outside");
1242
- const parsed = matter(readFileSync(file, "utf8"));
1254
+ const parsed = matter(readFileSync(file, "utf8"), NO_JS_FRONT_MATTER);
1243
1255
  // The body's own imports go (the page's are stripped the same way).
1244
1256
  const body = outsideFences(parsed.content, (t) => t.replace(/^import\s[^\n]*from\s*["'][^"']+["'];?[ \t]*$/gm, ""));
1245
1257
  return { data: parsed.data, body: body.trim() };
@@ -1650,7 +1662,7 @@ function loadChangelog(dir) {
1650
1662
  }
1651
1663
  for (const file of files.sort()) {
1652
1664
  try {
1653
- const parsed = matter(readFileSync(join(sub, file), "utf8"));
1665
+ const parsed = matter(readFileSync(join(sub, file), "utf8"), NO_JS_FRONT_MATTER);
1654
1666
  const fm = parsed.data;
1655
1667
  const d = fm.date instanceof Date ? fm.date : new Date(String(fm.date ?? ""));
1656
1668
  if (Number.isNaN(d.getTime()))
package/dist/parse.js CHANGED
@@ -12,6 +12,18 @@
12
12
  import { assignHeadingSlugs } from "./github-slug.js";
13
13
  import MarkdownIt from "markdown-it";
14
14
  import matter from "gray-matter";
15
+ /**
16
+ * gray-matter EVALUATES front matter that opens with `---js` / `---javascript` (its javascript
17
+ * engine is `eval`), so a page in someone else's repo could run code on this machine. Every
18
+ * call passes this, which refuses that engine; YAML and JSON are unchanged.
19
+ */
20
+ const NO_JS_FRONT_MATTER = {
21
+ engines: {
22
+ javascript: () => {
23
+ throw new Error("JavaScript front matter is not run");
24
+ },
25
+ },
26
+ };
15
27
  const md = new MarkdownIt({ html: true, linkify: true });
16
28
  export function extractFrontmatter(source) {
17
29
  const lines = source.split("\n");
@@ -27,7 +39,7 @@ export function extractFrontmatter(source) {
27
39
  // Parse YAML via gray-matter for a full record that preserves custom fields.
28
40
  let raw = {};
29
41
  try {
30
- const result = matter(source);
42
+ const result = matter(source, NO_JS_FRONT_MATTER);
31
43
  raw = result.data ?? {};
32
44
  }
33
45
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/format-starlight",
3
- "version": "0.2.0-beta.131",
3
+ "version": "0.2.0-beta.133",
4
4
  "description": "Starlight MDX importer for Dogsbay — converts Starlight sources (with JSX components, Render partials, and adapter-specific extensions) into TreeNode[]",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,9 +17,9 @@
17
17
  "jsonc-parser": "^3.3.1",
18
18
  "markdown-it": "^14.3.0",
19
19
  "markdown-it-footnote": "^4.0.0",
20
- "@dogsbay/format-dogsbay-md": "0.2.0-beta.131",
21
- "@dogsbay/markdown-it-mdx-jsx": "0.2.0-beta.131",
22
- "@dogsbay/types": "0.2.0-beta.131"
20
+ "@dogsbay/format-dogsbay-md": "0.2.0-beta.133",
21
+ "@dogsbay/types": "0.2.0-beta.133",
22
+ "@dogsbay/markdown-it-mdx-jsx": "0.2.0-beta.133"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/iarna__toml": "^2.0.5",