diff --git a/README.md b/README.md index 74782ab..c8fb149 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ Successor to [Oracle](https://github.com/script-wizards/oracle). |---|---| | `packages/engine` | `@scriptwizards/perhaps-engine`: parser + roller, no dependencies, no platform APIs | | `packages/cli` | `perhaps [table]`, `--list`, `--seed n` | -| `packages/obsidian` | Obsidian plugin (in progress) | +| `packages/obsidian` | Obsidian plugin: palette roll, insert at cursor, live code block rollers | +| `packages/web` | single-file demo page, deployed to [perhaps.sh](https://perhaps.sh) | ## Development diff --git a/packages/engine/src/roll.ts b/packages/engine/src/roll.ts index f17e31d..a2bf2dd 100644 --- a/packages/engine/src/roll.ts +++ b/packages/engine/src/roll.ts @@ -12,7 +12,8 @@ import type { const MAX_DEPTH = 10; const REROLL_ATTEMPTS = 5; -const REF_PATTERN = /^([A-Za-z0-9_-]+)(?:\.(selectUnique|selectMany)\((\d+)\))?$/; +const REF_PATTERN = + /^([A-Za-z0-9_-]+(?:\s+[A-Za-z0-9_-]+)*)(?:\.(selectUnique|selectMany)\((\d+)\))?$/; const DICE_PATTERN = /\b(\d+)[dD](\d+)([+-]\d+)?\b/g; const RANGE_PATTERN = /^(\d+)\s*-\s*(\d+)$/; const LIST_SEPARATOR = ", "; diff --git a/packages/engine/test/roll.test.ts b/packages/engine/test/roll.test.ts index d9bbc85..53fa55c 100644 --- a/packages/engine/test/roll.test.ts +++ b/packages/engine/test/roll.test.ts @@ -139,6 +139,15 @@ describe("cross-table references", () => { const roller = new Roller([encounters, treasure], sequence(0)); expect(roller.roll(encounters).text).toBe("wolves guarding a gem"); }); + + it("accepts spaces in ref names, normalized to hyphens", () => { + const encounters = table("output\n overheard: [tavern trouble]\n"); + const tavern = table("title\n Tavern Trouble\noutput\n a brawl\n"); + const roller = new Roller([encounters, tavern], sequence(0)); + const result = roller.roll(encounters); + expect(result.text).toBe("overheard: a brawl"); + expect(result.errors).toEqual([]); + }); }); describe("safety", () => { diff --git a/packages/obsidian/README.md b/packages/obsidian/README.md index be3c32b..08709ee 100644 --- a/packages/obsidian/README.md +++ b/packages/obsidian/README.md @@ -1,10 +1,25 @@ # perhaps (Obsidian plugin) -Not yet implemented. Planned surfaces, in build order: +Rolls perhaps/perchance tables anywhere in your vault. Three surfaces: -1. Command palette: "Roll a table" via SuggestModal over every table in the vault. -2. Reading-view code block processor: `perhaps`/`perchance` blocks render as live rollable widgets. -3. Insert-roll-at-cursor command for session logging. -4. Sidebar roller view with history. +- **Roll a table**: fuzzy picker over every table in the vault, result in a + modal. Click any underlined part to reroll just that part. +- **Roll a table into the note**: same picker, inserts the result at the + cursor. Meant for session logs. +- Reading view: ```` ```perhaps ```` and ```` ```perchance ```` code blocks + render as live rollers with reroll and copy. -The engine lives in `@scriptwizards/perhaps-engine` and has no platform dependencies. +The vault is indexed on load and kept current as files change, so tables can +reference each other across notes by title. + +Syntax lives in [SPEC.md](../../SPEC.md). The engine is +`@scriptwizards/perhaps-engine`, no platform dependencies. + +## Install into a vault + +```bash +just plugin-install path/to/vault +``` + +Then enable Perhaps under Settings, Community plugins. Still to build: a +sidebar roller view with history.