feat: Unify spark table detection and content resolution
Export isSparkTableHeader from content-registry and use it in both CLI and frontend table parsing. Add resolveContentRef to resolve content references consistently. Write processed registry content back to the file index so browser mode renders identically to CLI mode.
This commit is contained in:
@@ -47,6 +47,7 @@ import { parseInput } from "../../components/journal/command-parser";
|
||||
import {
|
||||
inspectSparkTableCsv,
|
||||
buildSparkTableCompletion,
|
||||
isSparkTableHeader,
|
||||
} from "../content-registry";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -927,6 +928,32 @@ describe("parseInput", () => {
|
||||
// content-registry (spark tables)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe("isSparkTableHeader", () => {
|
||||
test("detects plain dice formula", () => {
|
||||
expect(isSparkTableHeader("d6")).toBe(true);
|
||||
expect(isSparkTableHeader("d20")).toBe(true);
|
||||
expect(isSparkTableHeader("d100")).toBe(true);
|
||||
});
|
||||
|
||||
test("detects dice count and modifiers", () => {
|
||||
expect(isSparkTableHeader("2d6")).toBe(true);
|
||||
expect(isSparkTableHeader("3d6+5")).toBe(true);
|
||||
expect(isSparkTableHeader("1d8-2")).toBe(true);
|
||||
});
|
||||
|
||||
test("rejects non-dice headers", () => {
|
||||
expect(isSparkTableHeader("Name")).toBe(false);
|
||||
expect(isSparkTableHeader("d")).toBe(false);
|
||||
expect(isSparkTableHeader("6")).toBe(false);
|
||||
expect(isSparkTableHeader("d6x")).toBe(false);
|
||||
expect(isSparkTableHeader("roll")).toBe(false);
|
||||
});
|
||||
|
||||
test("trims surrounding whitespace", () => {
|
||||
expect(isSparkTableHeader(" d20 ")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("inspectSparkTableCsv", () => {
|
||||
test("detects spark table from CSV headers", () => {
|
||||
const csv = `d6,Name,Description
|
||||
|
||||
Reference in New Issue
Block a user