From 754fb0968c09c0685e545513304138591d2cca27 Mon Sep 17 00:00:00 2001 From: Roger Barnes Date: Mon, 30 Nov 2026 21:06:33 +1100 Subject: [PATCH 1/2] feat(markdown): make embedded lists, tables, and yamlBlocks opt-in by default (#265) --- .gitignore | 1 + docs/.sctx/config.json | 1 - docs/config.md | 7 +++--- src/plugins/markdown/parse-embedded.ts | 6 ++--- .../markdown/parse-embedded-config.test.ts | 23 +++++++++++-------- .../markdown/parse-embedded-content.test.ts | 9 +++++++- ...parse-embedded-hierarchy-embedding.test.ts | 9 +++++++- .../parse-embedded-relationships.test.ts | 9 +++++++- .../read-space-on-a-page-general.test.ts | 4 +++- .../relationship-embedded-nodes.test.ts | 1 + tests/validate/general.test.ts | 7 +++++- 11 files changed, 54 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 63010b8e..0f65fa9a 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ lefthook-local.yml .gitleaks-priv.toml hook-test/fixtures/.state/ +hook-test/fixtures/config.json diff --git a/docs/.sctx/config.json b/docs/.sctx/config.json index 0417aba5..6d0a011b 100644 --- a/docs/.sctx/config.json +++ b/docs/.sctx/config.json @@ -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 } } } diff --git a/docs/config.md b/docs/config.md index b489e145..1dd302da 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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 } } } @@ -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 diff --git a/src/plugins/markdown/parse-embedded.ts b/src/plugins/markdown/parse-embedded.ts index 35c2bf9a..c8b4bb4f 100644 --- a/src/plugins/markdown/parse-embedded.ts +++ b/src/plugins/markdown/parse-embedded.ts @@ -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, + tables: specific?.tables ?? wildcard?.tables ?? false, + yamlBlocks: specific?.yamlBlocks ?? wildcard?.yamlBlocks ?? false, }; } diff --git a/tests/plugins/markdown/parse-embedded-config.test.ts b/tests/plugins/markdown/parse-embedded-config.test.ts index 5c217e02..d879627d 100644 --- a/tests/plugins/markdown/parse-embedded-config.test.ts +++ b/tests/plugins/markdown/parse-embedded-config.test.ts @@ -99,7 +99,7 @@ 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) @@ -107,17 +107,17 @@ Stays inside subsection content. | 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 } }, }, }); @@ -125,6 +125,8 @@ Stays inside subsection content. 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']); }); @@ -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 @@ -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', () => { @@ -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) { diff --git a/tests/plugins/markdown/parse-embedded-content.test.ts b/tests/plugins/markdown/parse-embedded-content.test.ts index b87c2fec..d8446cae 100644 --- a/tests/plugins/markdown/parse-embedded-content.test.ts +++ b/tests/plugins/markdown/parse-embedded-content.test.ts @@ -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); diff --git a/tests/plugins/markdown/parse-embedded-hierarchy-embedding.test.ts b/tests/plugins/markdown/parse-embedded-hierarchy-embedding.test.ts index 01be29dd..4956bd0f 100644 --- a/tests/plugins/markdown/parse-embedded-hierarchy-embedding.test.ts +++ b/tests/plugins/markdown/parse-embedded-hierarchy-embedding.test.ts @@ -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'), diff --git a/tests/plugins/markdown/parse-embedded-relationships.test.ts b/tests/plugins/markdown/parse-embedded-relationships.test.ts index 0c8b987f..30e483fa 100644 --- a/tests/plugins/markdown/parse-embedded-relationships.test.ts +++ b/tests/plugins/markdown/parse-embedded-relationships.test.ts @@ -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']; diff --git a/tests/plugins/markdown/read-space-on-a-page-general.test.ts b/tests/plugins/markdown/read-space-on-a-page-general.test.ts index 73b71f3b..60d2c139 100644 --- a/tests/plugins/markdown/read-space-on-a-page-general.test.ts +++ b/tests/plugins/markdown/read-space-on-a-page-general.test.ts @@ -17,7 +17,9 @@ describe('readSpaceOnAPage - on-a-page-valid.md (space_on_a_page)', () => { let diagnostics: Record; 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; diff --git a/tests/plugins/markdown/relationship-embedded-nodes.test.ts b/tests/plugins/markdown/relationship-embedded-nodes.test.ts index 17f78b06..52ef92dd 100644 --- a/tests/plugins/markdown/relationship-embedded-nodes.test.ts +++ b/tests/plugins/markdown/relationship-embedded-nodes.test.ts @@ -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: [ diff --git a/tests/validate/general.test.ts b/tests/validate/general.test.ts index 12f7922e..8b34839b 100644 --- a/tests/validate/general.test.ts +++ b/tests/validate/general.test.ts @@ -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', () => { From ff7757f2b4ee68307ecefbc755b908f119466b30 Mon Sep 17 00:00:00 2001 From: Roger Barnes Date: Mon, 30 Nov 2026 21:38:25 +1100 Subject: [PATCH 2/2] docs: document plugins.markdown.embedded opt-in across concepts, schemas, and skill reference --- docs/concepts.md | 12 ++++++------ docs/schemas.md | 4 ++-- plugin/.claude-plugin/plugin.json | 2 +- .../references/schema-authoring.md | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/concepts.md b/docs/concepts.md index f8c9dc0f..92e691b1 100644 --- a/docs/concepts.md +++ b/docs/concepts.md @@ -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. @@ -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: @@ -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. --- diff --git a/docs/schemas.md b/docs/schemas.md index 38b4c398..864817b9 100644 --- a/docs/schemas.md +++ b/docs/schemas.md @@ -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: @@ -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): diff --git a/plugin/.claude-plugin/plugin.json b/plugin/.claude-plugin/plugin.json index 6d426a72..b46e5b8f 100644 --- a/plugin/.claude-plugin/plugin.json +++ b/plugin/.claude-plugin/plugin.json @@ -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", diff --git a/plugin/skills/structured-context/references/schema-authoring.md b/plugin/skills/structured-context/references/schema-authoring.md index d858be44..2ff85837 100644 --- a/plugin/skills/structured-context/references/schema-authoring.md +++ b/plugin/skills/structured-context/references/schema-authoring.md @@ -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 | |---|---|---|