-
Notifications
You must be signed in to change notification settings - Fork 2
Add configurable context tag prefix with documentation #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
654164f
1c85383
6b2eae2
d2e48c3
87b4e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Configurable Context Tag Prefix | ||
|
|
||
| ## Problem | ||
|
|
||
| Context tags (`#context/home`, `#context/office`) are hardcoded with the prefix `context`. Users can't discover this feature without reading commits, and can't change the prefix to suit their workflow (e.g. `#at/home`, `#ctx/office`). | ||
|
|
||
| ## Design | ||
|
|
||
| ### Setting | ||
|
|
||
| Add `contextTagPrefix` to `PluginSettings` with default `"context"`. | ||
|
|
||
| ### Core | ||
|
|
||
| Change `extractContexts(text: string)` to `extractContexts(text: string, prefix: string)` — build the regex dynamically from the prefix parameter. | ||
|
|
||
| ### Call sites | ||
|
|
||
| Pass `settings.contextTagPrefix` at all call sites: | ||
|
|
||
| - `sphere-view.ts` — has `this.settings` | ||
| - `sphere-data-loader.ts` — has `this.settings` | ||
| - `someday-scanner.ts` — has `this.settings` | ||
| - `waiting-for-scanner.ts` — needs `settings` added to constructor | ||
|
|
||
| ### Settings UI | ||
|
|
||
| Text field in the settings tab with description explaining what context tags are and how to use them. | ||
|
|
||
| ### README | ||
|
|
||
| Short section after "Project Structure" explaining context tags with examples. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,18 @@ | ||
| // ABOUTME: Extracts GTD context tags (#context/X) from action line text. | ||
| // ABOUTME: Extracts GTD context tags (e.g. #context/X) from action line text. | ||
| // ABOUTME: Used by scanners and views for context-based filtering. | ||
|
|
||
| const CONTEXT_TAG_PATTERN = /#context\/([^\s]+)/gi; | ||
|
|
||
| export function extractContexts(text: string): string[] { | ||
| export function extractContexts(text: string, prefix: string = "context"): string[] { | ||
| const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| const pattern = new RegExp(`#${escaped}\\/([^\\s]+)`, "gi"); | ||
| const contexts: string[] = []; | ||
| let match; | ||
|
|
||
| while ((match = CONTEXT_TAG_PATTERN.exec(text)) !== null) { | ||
| while ((match = pattern.exec(text)) !== null) { | ||
| const context = match[1].toLowerCase(); | ||
| if (!contexts.includes(context)) { | ||
| contexts.push(context); | ||
| } | ||
| } | ||
|
|
||
| // Reset lastIndex since we're using a global regex | ||
| CONTEXT_TAG_PATTERN.lastIndex = 0; | ||
|
|
||
| return contexts; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,9 @@ | ||||||||||||||||||
| // ABOUTME: Tests for WaitingForScanner vault scanning and item extraction. | ||||||||||||||||||
| // ABOUTME: Covers sphere/context extraction, text normalisation, and Dataview integration. | ||||||||||||||||||
|
|
||||||||||||||||||
| import { WaitingForScanner } from "../src/waiting-for-scanner"; | ||||||||||||||||||
| import { App, TFile, Vault, MetadataCache, CachedMetadata } from "obsidian"; | ||||||||||||||||||
| import { DEFAULT_SETTINGS } from "../src/types"; | ||||||||||||||||||
|
Comment on lines
4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add ABOUTME header for this test file. Please prepend two ABOUTME lines describing the test file’s purpose. ✅ Proposed fix+// ABOUTME: Tests WaitingForScanner scanning for waiting-for items.
+// ABOUTME: Covers sphere/context extraction and text normalization.
import { WaitingForScanner } from "../src/waiting-for-scanner";
import { App, TFile, Vault, MetadataCache, CachedMetadata } from "obsidian";
import { DEFAULT_SETTINGS } from "../src/types";As per coding guidelines, Start all source files with two ABOUTME comment lines explaining file purpose. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| describe("WaitingForScanner", () => { | ||||||||||||||||||
| let mockApp: jest.Mocked<App>; | ||||||||||||||||||
|
|
@@ -23,7 +27,7 @@ describe("WaitingForScanner", () => { | |||||||||||||||||
| metadataCache: mockMetadataCache, | ||||||||||||||||||
| } as unknown as jest.Mocked<App>; | ||||||||||||||||||
|
|
||||||||||||||||||
| scanner = new WaitingForScanner(mockApp); | ||||||||||||||||||
| scanner = new WaitingForScanner(mockApp, DEFAULT_SETTINGS); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| test("should scan vault and find waiting-for items", async () => { | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: tavva/flow
Length of output: 3451
🏁 Script executed:
Repository: tavva/flow
Length of output: 710
Escape
contextTagPrefixinextractContextsbefore building RegExp.The function in src/context-tags.ts (line 5) builds a RegExp directly from the user-configured prefix without escaping. Since the settings tab only applies
.trim()validation (src/settings-tab.ts:280), metacharacters like[,(,+,\can cause RegExp syntax errors or unintended matching behavior at runtime. This affects all five call sites: src/waiting-for-scanner.ts (lines 112, 157), src/sphere-view.ts (line 819), src/sphere-data-loader.ts (lines 180, 211, 218), and src/someday-scanner.ts (line 99).Escape the prefix using
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")inextractContextsbefore building the pattern:Suggested fix
export function extractContexts(text: string, prefix: string = "context"): string[] { + const safePrefix = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - const pattern = new RegExp(`#${prefix}\\/([^\\s]+)`, "gi"); + const pattern = new RegExp(`#${safePrefix}\\/([^\\s]+)`, "gi");🤖 Prompt for AI Agents