mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
refactor(oc-path): share frontmatter formatting (#120098)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user