chore(deps): js-yaml 5 (frontmatter reads YAML 1.2's core schema; comment-only frontmatter has no properties)

This commit is contained in:
saberzero1 committed 2026-11-26 00:10:30 +01:00
1 parent 2386362d57
commit 3b78d1658d
5 files changed
+86 -22

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Frontmatter is read with js-yaml 5, using YAML 1.2's core schema (the values Quartz read before are unchanged). Frontmatter with only comments now has no properties, as in Obsidian, instead of being reported as invalid frontmatter.
+50 -18
View File
@@ -65,7 +65,7 @@
"hast-util-to-jsx-runtime": "^2.3.6",
"is-absolute-url": "^4.0.1",
"isomorphic-git": "^1.36.3",
"js-yaml": "^4.1.0",
"js-yaml": "^5.5.0",
"lightningcss": "^1.31.1",
"micromorph": "^0.4.5",
"minimatch": "^11.0.5",
@@ -99,7 +99,6 @@
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.2.0",
"@types/hast": "^3.0.4",
"@types/js-yaml": "^4.0.9",
"@types/node": "^26.5.1",
"@types/pretty-time": "^1.1.5",
"@types/semver": "^7.7.1",
@@ -324,6 +323,36 @@
"js-yaml": "^4.1.1"
}
},
"node_modules/@changesets/parse/node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"dev": true,
"license": "Python-2.0"
},
"node_modules/@changesets/parse/node_modules/js-yaml": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz",
"integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/puzrin"
},
{
"type": "github",
"url": "https://github.com/sponsors/nodeca"
}
],
"license": "MIT",
"dependencies": {
"argparse": "^2.0.1"
},
"bin": {
"js-yaml": "bin/js-yaml.js"
}
},
"node_modules/@changesets/pre": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@changesets/pre/-/pre-2.0.2.tgz",
@@ -3400,13 +3429,6 @@
"@types/unist": "*"
}
},
"node_modules/@types/js-yaml": {
"version": "4.0.9",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.9.tgz",
"integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/katex": {
"version": "0.16.8",
"resolved": "https://registry.npmjs.org/@types/katex/-/katex-0.16.8.tgz",
@@ -3552,10 +3574,20 @@
}
},
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"license": "Python-2.0"
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-3.0.4.tgz",
"integrity": "sha512-fwWK3Zq22l4XJJjx5mcBHGikIk+hJqO+32dPm0Jur7+rtG5x1scOjSfdT9ZKeWHPpsya/l0HHK4tDImBkTrtvA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/puzrin"
},
{
"type": "github",
"url": "https://github.com/sponsors/nodeca"
}
],
"license": "PSF-2.0"
},
"node_modules/array-union": {
"version": "2.1.0",
@@ -5057,9 +5089,9 @@
}
},
"node_modules/js-yaml": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz",
"integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==",
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-5.5.0.tgz",
"integrity": "sha512-paNr4LFIFPjeeSmwNYdrb8FafLLG/Cr2Af3GjbsHJ5CxIjH4r0c2emlmRdAtpPAieP1gRVzk6buBbVP5gBMGAg==",
"funding": [
{
"type": "github",
@@ -5072,10 +5104,10 @@
],
"license": "MIT",
"dependencies": {
"argparse": "^2.0.1"
"argparse": "^3.0.3"
},
"bin": {
"js-yaml": "bin/js-yaml.js"
"js-yaml": "bin/js-yaml.mjs"
}
},
"node_modules/jsonfile": {
+1 -2
View File
@@ -95,7 +95,7 @@
"hast-util-to-jsx-runtime": "^2.3.6",
"is-absolute-url": "^4.0.1",
"isomorphic-git": "^1.36.3",
"js-yaml": "^4.1.0",
"js-yaml": "^5.5.0",
"lightningcss": "^1.31.1",
"micromorph": "^0.4.5",
"minimatch": "^11.0.5",
@@ -126,7 +126,6 @@
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.2.0",
"@types/hast": "^3.0.4",
"@types/js-yaml": "^4.0.9",
"@types/node": "^26.5.1",
"@types/pretty-time": "^1.1.5",
"@types/semver": "^7.7.1",
+17
View File
@@ -223,6 +223,23 @@ describe("frontmatter built-in", () => {
)
})
test("reads YAML frontmatter with YAML 1.2's core schema, as Obsidian does", () => {
const data = readFrontmatterData(
"---\ntitle: Hello world\ndate: 2024-01-02\ndraft: True\nn: 012\nnone: ~\nratio: .5\nalias: yes\n---\n",
)
assert.deepStrictEqual(data, {
title: "Hello world",
date: "2024-01-02",
draft: true,
n: 12,
none: null,
ratio: 0.5,
alias: "yes",
})
// a block without a document holds no properties
assert.deepStrictEqual(readFrontmatterData("---\n# only a comment\n---\nbody\n"), {})
})
test("refuses JavaScript frontmatter instead of executing it", async () => {
const g = globalThis as { __quartzFrontmatterRan?: boolean }
delete g.__quartzFrontmatterRan
+13 -2
View File
@@ -1,6 +1,6 @@
import matter from "gray-matter"
import remarkFrontmatter from "remark-frontmatter"
import yaml from "js-yaml"
import { CORE_SCHEMA, loadAll } from "js-yaml"
import toml from "toml"
import { QuartzTransformerPlugin } from "../types"
import { QuartzPluginData } from "../vfile"
@@ -141,6 +141,17 @@ const refuseJavaScript = (): never => {
)
}
/**
* YAML frontmatter as properties. YAML 1.2's core schema, as Obsidian reads properties: `true`,
* `null`, `~` and numbers resolve, dates stay strings. A block without a document (empty, or only
* comments) holds no properties.
*/
function loadYaml(source: string): object {
const docs = loadAll(source, { schema: CORE_SCHEMA })
if (docs.length > 1)
throw new Error("expected a single document in the frontmatter, but found more")
return (docs[0] ?? {}) as object
}
/** Parse a file's frontmatter with the configured delimiters and language (`{}` when it has none). */
export function readFrontmatterData(
source: Buffer | string,
@@ -158,7 +169,7 @@ export function readFrontmatterData(
delimiters: options.delimiters ?? frontmatterDefaults.delimiters,
language,
engines: {
yaml: (s) => yaml.load(s, { schema: yaml.JSON_SCHEMA }) as object,
yaml: loadYaml,
toml: (s) => toml.parse(s) as object,
javascript: refuseJavaScript,
js: refuseJavaScript,