Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ lefthook-local.yml
.gitleaks-priv.toml

hook-test/fixtures/.state/
hook-test/fixtures/config.json
1 change: 0 additions & 1 deletion docs/.sctx/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
}
},
"embedded": {
"*": { "lists": false, "tables": false, "yamlBlocks": false },
"document": { "headings": { "type": "section", "minDepth": 2, "maxDepth": 3 } },
"section": { "headings": { "type": "section", "minDepth": 3, "maxDepth": 3 } }
}
Expand Down
12 changes: 6 additions & 6 deletions docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ A **space directory** is a directory of markdown files that backs a `space`. Eac
Each `.md` file with a `type` frontmatter field is a **typed page** — it represents one node. Its body is also scanned for **embedded nodes**:

- **Heading with `[type:: x]`** or **anchor-implied type** (e.g. `## My Goal ^goal1`) → becomes a child node.
- **Relationship headings** (e.g. `### Assumptions`) → when matched to a relationship definition in the schema, signals that following content (list items or table rows) should be typed as that relationship's child type, without requiring explicit inline annotations.
- **Relationship headings** (e.g. `### Assumptions`) → when matched to a relationship definition in the schema, signals that following content (list items or table rows, when opted in via [`plugins.markdown.embedded`](config.md#embedded)) should be typed as that relationship's child type.
- **Untyped headings** → update the depth stack for parent resolution but do not become nodes. They stay in the content of the node whose section contains them; see [Node content](#node-content).
- **Typed bullet items** (`- [type:: solution] Title`) → become child nodes at any nesting depth.
- **Table rows** under a relationship heading → become child nodes of the relationship type.
- **YAML blocks** and **unbracketed `key:: value` paragraph fields** → merged into the current node's `schemaData`.
- **Typed bullet items** (`- [type:: solution] Title`) → become child nodes when `lists: true` is set in [`plugins.markdown.embedded`](config.md#embedded).
- **Table rows** under a relationship heading → become child nodes when `tables: true` is set in [`plugins.markdown.embedded`](config.md#embedded).
- **YAML blocks** (when `yamlBlocks: true` is set in [`plugins.markdown.embedded`](config.md#embedded)) and **unbracketed `key:: value` paragraph fields** → merged into the current node's `schemaData`.

Parsing behaviour for a space directory:
- Files declaring a `space node` type via frontmatter are included as nodes.
Expand Down Expand Up @@ -242,7 +242,7 @@ Each non-root level uses the shared `field`, `fieldOn`, and `multiple` edge opti

### Hierarchy embedding

Hierarchy levels with `templateFormat` and `matchers` support **embedded parsing**: a matching heading in a typed page types following list items or table rows without `[type:: x]` annotations.
Hierarchy levels with `templateFormat` and `matchers` support **embedded parsing**: a matching heading in a typed page types following list items or table rows without `[type:: x]` annotations (requires `lists: true` or `tables: true` in [`plugins.markdown.embedded`](config.md#embedded)).

Two patterns apply:

Expand Down Expand Up @@ -282,7 +282,7 @@ Relationships are defined in `$metadata.relationships`. Like hierarchy levels, t
- **`templateFormat`** — parsing/generation hint: `"heading"`, `"list"`, `"table"`, or `"page"`
- **`matchers`** — heading text patterns (strings or `/regex/`) used to detect relationship sections during embedded parsing

A heading in a typed page that matches a relationship's `matchers` signals to the parser that following content (single nodes, list items, or table rows) should be typed as that relationship's child type — without requiring explicit inline `[type:: x]` annotations.
A heading in a typed page that matches a relationship's `matchers` signals to the parser that following content (single nodes, or list items and table rows when enabled in [`plugins.markdown.embedded`](config.md#embedded)) should be typed as that relationship's child type — without requiring explicit inline `[type:: x]` annotations.

---

Expand Down
7 changes: 3 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ Controls how headings, lists and tables inside a node become embedded nodes, key
"plugins": {
"markdown": {
"embedded": {
"*": { "lists": false, "tables": false },
"document": { "headings": { "type": "section", "minDepth": 2, "maxDepth": 3 } },
"section": { "headings": { "type": "section", "minDepth": 3, "maxDepth": 3 } }
}
Expand All @@ -251,9 +250,9 @@ Controls how headings, lists and tables inside a node become embedded nodes, key
```

- **`headings`** — extracts plain headings within `minDepth`..`maxDepth` (defaults `1`..`5`) as nodes of `type`, or `false` to override a `"*"` headings setting. Headings matched this way become nodes directly; lists and tables beneath them stay as content unless extracted separately. Headings outside the depth range stay as prose in their enclosing node. Explicit `[type:: ...]` annotations and type anchors still take precedence.
- **`lists`** — set to `false` to keep bullet lists as node content instead of extracting embedded list-item nodes (default `true`).
- **`tables`** — set to `false` to keep markdown tables as node content instead of extracting embedded table-row nodes (default `true`).
- **`yamlBlocks`** — set to `false` to keep fenced `yaml` code blocks as node content instead of merging them into node fields (default `true`).
- **`lists`** — set to `true` to extract embedded list-item nodes (default `false`; bullet lists stay as node content).
- **`tables`** — set to `true` to extract embedded table-row nodes (default `false`; markdown tables stay as node content).
- **`yamlBlocks`** — set to `true` to merge fenced `yaml` code blocks into node fields (default `false`; fenced `yaml` blocks stay as node content).

## Filter views

Expand Down
4 changes: 2 additions & 2 deletions docs/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Relationships define links between node types that are not part of the primary s
]
```

With this configuration, embedded task items under an Activity's "Tasks" heading populate `activity.tasks` as `[[Task Title]]` wikilinks, and validation confirms each entry resolves to a `task` node.
With this configuration (and `lists: true` in [`plugins.markdown.embedded`](config.md#embedded)), embedded task items under an Activity's "Tasks" heading populate `activity.tasks` as `[[Task Title]]` wikilinks, and validation confirms each entry resolves to a `task` node.

`HierarchyLevel` options:

Expand All @@ -235,7 +235,7 @@ String shorthand (`"goal"`) normalizes to:

### Hierarchy embedding

When a hierarchy level has `templateFormat` and `matchers`, it participates in **hierarchy embedding** — the same section-based parsing used for relationships. Two patterns are supported:
When a hierarchy level has `templateFormat` and `matchers`, it participates in **hierarchy embedding** — the same section-based parsing used for relationships. Extracting list items or table rows requires `lists: true` or `tables: true` in [`plugins.markdown.embedded`](config.md#embedded). Two patterns are supported:

**Child-level embedding** — a typed-page heading signals that following content should produce nodes of the child type (next level in hierarchy):

Expand Down
2 changes: 1 addition & 1 deletion plugin/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "structured-context",
"version": "0.26.8",
"version": "0.26.9",
"description": "Structured content authoring for Obsidian — automatic validation hooks, slash commands, and agent skills to keep markdown files compliant with your schema.",
"homepage": "https://github.com/mindsocket/structured-context",
"repository": "https://github.com/mindsocket/structured-context",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Use object entries to override defaults:

### Relationships (`$metadata.relationships`)

Relationships define how sub-entities (nodes inside other files) are parsed and generated.
Relationships define how sub-entities (nodes inside other files) are parsed and generated. Extracting list items or table rows also requires opting in via `plugins.markdown.embedded` (`lists: true` / `tables: true`; see `sctx docs config`).

| Field | Default | Description |
|---|---|---|
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/markdown/parse-embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ export function extractEmbeddedNodes(body: string, options: ExtractEmbeddedOptio
const rawHeadings = specific?.headings !== undefined ? specific.headings : wildcard?.headings;
return {
headings: rawHeadings === false ? undefined : rawHeadings,
lists: specific?.lists ?? wildcard?.lists ?? true,
tables: specific?.tables ?? wildcard?.tables ?? true,
yamlBlocks: specific?.yamlBlocks ?? wildcard?.yamlBlocks ?? true,
lists: specific?.lists ?? wildcard?.lists ?? false,
Comment thread
mindsocket marked this conversation as resolved.
Resolved
Comment thread
mindsocket marked this conversation as resolved.
Resolved
tables: specific?.tables ?? wildcard?.tables ?? false,
yamlBlocks: specific?.yamlBlocks ?? wildcard?.yamlBlocks ?? false,
Comment thread
mindsocket marked this conversation as resolved.
Resolved
};
}

Expand Down
23 changes: 13 additions & 10 deletions tests/plugins/markdown/parse-embedded-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,34 @@ Stays inside subsection content.
expect(nodes[0]?.content).toBe('### Nested stays prose');
});

it('keeps lists and tables as content (with their links) when lists/tables are disabled', () => {
it('keeps lists, tables, and yaml blocks as content by default (with their links)', () => {
const body = `## Overview

- [type:: section] Looks like a typed bullet with [a link](other.md)

| Section | Notes |
| --- | --- |
| Row one | See [ref](ref.md) |

\`\`\`yaml
published_date: 2026-03-31
\`\`\`
`;
const { nodes } = extractEmbeddedNodes(body, {
page: { id: 'doc.md', targets: ['doc'] },
pageType: 'document',
metadata: DOC_METADATA,
embedded: {
'*': {
headings: { type: 'section', minDepth: 2 },
lists: false,
tables: false,
},
document: { headings: { type: 'section', minDepth: 2 } },
},
});

expect(nodes).toHaveLength(1);
expect(nodes[0]?.title).toBe('Overview');
expect(nodes[0]?.content).toContain('- [type:: section] Looks like a typed bullet');
expect(nodes[0]?.content).toContain('| Row one | See [ref](ref.md) |');
expect(nodes[0]?.content).toContain('published_date: 2026-03-31');
expect(nodes[0]?.schemaData.published_date).toBeUndefined();
expect(nodes[0]?.contentLinks?.map((l) => l.target)).toEqual(['other.md', 'ref.md']);
});

Expand All @@ -143,7 +145,7 @@ Mention \`[status:: active]\` in prose.
expect(nodes[0]?.schemaData.status).toBeUndefined();
});

it('keeps yaml blocks as content when yamlBlocks is false', () => {
it('merges yaml blocks into fields when yamlBlocks is opted in', () => {
const body = `## Overview

\`\`\`yaml
Expand All @@ -154,11 +156,11 @@ published_date: 2026-03-31
page: { id: 'doc.md', targets: ['doc'] },
pageType: 'document',
metadata: DOC_METADATA,
embedded: { '*': { headings: { type: 'section', minDepth: 2 }, yamlBlocks: false } },
embedded: { '*': { headings: { type: 'section', minDepth: 2 }, yamlBlocks: true } },
});

expect(nodes[0]?.schemaData.published_date).toBeUndefined();
expect(nodes[0]?.content).toContain('published_date: 2026-03-31');
expect(nodes[0]?.schemaData.published_date).toBe('2026-03-31');
expect(nodes[0]?.content).toBeUndefined();
});

it('allows explicit [type:: x] to override embedded headings type', () => {
Expand Down Expand Up @@ -189,6 +191,7 @@ published_date: 2026-03-31
page: { id: 'doc.md', targets: ['doc'] },
pageType: 'document',
metadata: DOC_METADATA,
embedded: { '*': { lists: true, tables: true } },
});
expect(nodes.map((n) => n.title)).toEqual(['Alpha', 'Beta', 'Gamma']);
for (const node of nodes) {
Expand Down
9 changes: 8 additions & 1 deletion tests/plugins/markdown/parse-embedded-content.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { describe, expect, it } from 'bun:test';
import { extractEmbeddedNodes } from '../../../src/plugins/markdown/parse-embedded';
import {
type ExtractEmbeddedOptions,
extractEmbeddedNodes as rawExtractEmbeddedNodes,
} from '../../../src/plugins/markdown/parse-embedded';
import type { HierarchyLevel } from '../../../src/types';
import { makeLevel, withHierarchy } from '../../test-helpers';

const ALL_EMBEDDED = { '*': { lists: true, tables: true, yamlBlocks: true } };
const extractEmbeddedNodes = (body: string, options: ExtractEmbeddedOptions) =>
rawExtractEmbeddedNodes(body, { embedded: ALL_EMBEDDED, ...options });

const HIERARCHY: HierarchyLevel[] = [makeLevel('goal'), makeLevel('task', { templateFormat: 'list' })];
const metadata = withHierarchy(HIERARCHY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { describe, expect, it } from 'bun:test';
import { extractEmbeddedNodes } from '../../../src/plugins/markdown/parse-embedded';
import {
type ExtractEmbeddedOptions,
extractEmbeddedNodes as rawExtractEmbeddedNodes,
} from '../../../src/plugins/markdown/parse-embedded';
import type { HierarchyLevel } from '../../../src/types';
import { makeLevel, makeRelationship, withHierarchy } from '../../test-helpers';

const ALL_EMBEDDED = { '*': { lists: true, tables: true, yamlBlocks: true } };
const extractEmbeddedNodes = (body: string, options: ExtractEmbeddedOptions) =>
rawExtractEmbeddedNodes(body, { embedded: ALL_EMBEDDED, ...options });

const HIERARCHY: HierarchyLevel[] = [
makeLevel('phase'),
makeLevel('activity'),
Expand Down
9 changes: 8 additions & 1 deletion tests/plugins/markdown/parse-embedded-relationships.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { describe, expect, it } from 'bun:test';
import { extractEmbeddedNodes } from '../../../src/plugins/markdown/parse-embedded';
import {
type ExtractEmbeddedOptions,
extractEmbeddedNodes as rawExtractEmbeddedNodes,
} from '../../../src/plugins/markdown/parse-embedded';
import type { Relationship } from '../../../src/types';
import { makeLevel, withHierarchy } from '../../test-helpers';

const ALL_EMBEDDED = { '*': { lists: true, tables: true, yamlBlocks: true } };
const extractEmbeddedNodes = (body: string, options: ExtractEmbeddedOptions) =>
rawExtractEmbeddedNodes(body, { embedded: ALL_EMBEDDED, ...options });

describe('extractEmbeddedNodes - relationships', () => {
const hierarchy = ['vision', 'mission', 'goal', 'opportunity', 'solution', 'experiment'];

Expand Down
4 changes: 3 additions & 1 deletion tests/plugins/markdown/read-space-on-a-page-general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('readSpaceOnAPage - on-a-page-valid.md (space_on_a_page)', () => {
let diagnostics: Record<string, number | string | string[]>;

beforeAll(() => {
const result = readSpaceOnAPage(makePluginContext(VALID_PAGE));
const result = readSpaceOnAPage(
makePluginContext(VALID_PAGE, undefined, { embedded: { '*': { lists: true, yamlBlocks: true } } }),
);
({ nodes: resolvedNodes } = resolveGraphEdges(result.nodes, metadata));
parseIssues = result.parseIssues;
diagnostics = result.diagnostics;
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/markdown/relationship-embedded-nodes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Embedded nodes with parent-side relationships', () => {
const result = extractEmbeddedNodes(markdown, {
page: { id: 'Test Solution.md', targets: ['Test Solution'] },
pageType: 'Solutions',
embedded: { '*': { lists: true, tables: true } },
metadata: {
...withHierarchy(['Phases', 'Activities', 'Capabilities', 'Tools'].map((t) => makeLevel(t))),
relationships: [
Expand Down
7 changes: 6 additions & 1 deletion tests/validate/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ describe('Schema validation', () => {
let nodes: SpaceNode[];

beforeAll(() => {
({ nodes } = resolveGraphEdges(readSpaceOnAPage(makePluginContext(VALID_PAGE)).nodes, metadata));
({ nodes } = resolveGraphEdges(
readSpaceOnAPage(
makePluginContext(VALID_PAGE, undefined, { embedded: { '*': { lists: true, yamlBlocks: true } } }),
).nodes,
metadata,
));
});

it('all nodes pass schema validation', () => {
Expand Down