fix(core): keep unset values visible in prose (#12)
renderText now leaves {{name}} in place when the value is empty, so prose
shows which parameter is still missing instead of a blank.
This commit is contained in:
@@ -165,7 +165,7 @@ export function renderHost(
|
||||
/** Substitute prose without quoting; secrets always appear masked. */
|
||||
export function renderText(text: string, values: ParamValues, notebook: Notebook): string {
|
||||
const secrets = new Set(notebook.params.filter(def => def.type === "secret").map(def => def.name));
|
||||
return text.replace(template, (match, name: string) => secrets.has(name) ? "••••" : own(values, name) ? values[name]! : match);
|
||||
return text.replace(template, (match, name: string) => secrets.has(name) ? "••••" : own(values, name) && values[name] ? values[name]! : match);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -153,6 +153,8 @@ describe("rendering and secrets", () => {
|
||||
it("renders prose with raw values and handles inherited names safely", () => {
|
||||
const n = book(" x: {type: string}");
|
||||
expect(renderText("{{x}} {{toString}}", { x: "a & b" }, n)).toBe("a & b {{toString}}");
|
||||
// An unset value stays visible as its template instead of vanishing ("on ****").
|
||||
expect(renderText("on **{{x}}**", { x: "" }, n)).toBe("on **{{x}}**");
|
||||
expect(render(n, {}, {}).invalid.x).toBeUndefined();
|
||||
expect(render(n, {}, {}).missing).toContain("x");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user