diff --git a/extensions/oc-path/src/oc-path/edit.ts b/extensions/oc-path/src/oc-path/edit.ts index 402ea77b45cb..c1327154b464 100644 --- a/extensions/oc-path/src/oc-path/edit.ts +++ b/extensions/oc-path/src/oc-path/edit.ts @@ -10,6 +10,7 @@ */ import type { AstBlock, AstItem, FrontmatterEntry, MdAst } from "./ast.js"; +import { formatFrontmatterValue } from "./frontmatter-format.js"; import { formatOcPath, type OcPath } from "./oc-path.js"; import { guardSentinel } from "./sentinel.js"; @@ -139,13 +140,3 @@ function finalize(ast: MdAst): MdEditResult { } return { ok: true, ast: { ...ast, raw: parts.join("\n") } }; } - -function formatFrontmatterValue(value: string): string { - if (value.length === 0) { - return '""'; - } - if (/[:#&*?|<>=!%@`,[\]{}\r\n]/.test(value)) { - return JSON.stringify(value); - } - return value; -} diff --git a/extensions/oc-path/src/oc-path/emit.ts b/extensions/oc-path/src/oc-path/emit.ts index 96ca60016417..c322afd0ddb9 100644 --- a/extensions/oc-path/src/oc-path/emit.ts +++ b/extensions/oc-path/src/oc-path/emit.ts @@ -23,6 +23,7 @@ */ import type { MdAst } from "./ast.js"; +import { formatFrontmatterValue } from "./frontmatter-format.js"; import { guardSentinel } from "./sentinel.js"; /** @@ -114,16 +115,5 @@ export function emitMd(ast: MdAst, opts: EmitOptions = {}): string { return parts.join("\n"); } -function formatFrontmatterValue(value: string): string { - // Frontmatter is yaml-ish; quote values with structural chars. - if (value.length === 0) { - return '""'; - } - if (/[:#&*?|<>=!%@`,[\]{}\r\n]/.test(value)) { - return JSON.stringify(value); - } - return value; -} - // Re-export the frontmatter type for convenience so tests don't need // to import from ast.ts. diff --git a/extensions/oc-path/src/oc-path/frontmatter-format.ts b/extensions/oc-path/src/oc-path/frontmatter-format.ts new file mode 100644 index 000000000000..c083608241eb --- /dev/null +++ b/extensions/oc-path/src/oc-path/frontmatter-format.ts @@ -0,0 +1,10 @@ +export function formatFrontmatterValue(value: string): string { + // Frontmatter is yaml-ish; quote values with structural chars. + if (value.length === 0) { + return '""'; + } + if (/[:#&*?|<>=!%@`,[\]{}\r\n]/.test(value)) { + return JSON.stringify(value); + } + return value; +} diff --git a/extensions/oc-path/src/oc-path/universal.ts b/extensions/oc-path/src/oc-path/universal.ts index c54053d510a6..326ae2b37f64 100644 --- a/extensions/oc-path/src/oc-path/universal.ts +++ b/extensions/oc-path/src/oc-path/universal.ts @@ -19,6 +19,7 @@ import { expectDefined } from "openclaw/plugin-sdk/expect-runtime"; import { isMap, isScalar, isSeq, type Pair } from "yaml"; import type { MdAst } from "./ast.js"; import { setMdOcPath } from "./edit.js"; +import { formatFrontmatterValue } from "./frontmatter-format.js"; import type { JsoncAst, JsoncEntry, JsoncValue } from "./jsonc/ast.js"; import { insertJsoncOcPath, setJsoncOcPath } from "./jsonc/edit.js"; import { resolveJsoncOcPath } from "./jsonc/resolve.js"; @@ -873,16 +874,6 @@ function rebuildMdRaw(ast: MdAst): MdAst { return { ...ast, raw: parts.join("\n") }; } -function formatFrontmatterValue(value: string): string { - if (value.length === 0) { - return '""'; - } - if (/[:#&*?|<>=!%@`,[\]{}\r\n]/.test(value)) { - return JSON.stringify(value); - } - return value; -} - function slugifyHeading(s: string): string { return s .toLowerCase()