From 628fbb3ed31e1bbfa27a25e2abd9d5d030fcd198 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 14 Apr 2026 07:57:26 +0200 Subject: [PATCH] Fixes #1932 --- plugs/index/item.test.ts | 32 ++++++++++++++++++++++++++++++++ plugs/index/item.ts | 12 ++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/plugs/index/item.test.ts b/plugs/index/item.test.ts index a06a678a..0c09b7dd 100644 --- a/plugs/index/item.test.ts +++ b/plugs/index/item.test.ts @@ -72,3 +72,35 @@ test("Test item indexing", async () => { expect(items[8].links).toEqual(["link 2"]); expect(new Set(items[8].ilinks)).toEqual(new Set(["link", "link 2"])); }); + +// Regression test for https://github.com/silverbulletmd/silverbullet/issues/1932 +// and https://github.com/silverbulletmd/silverbullet/issues/1903 +const nestedListMd = ` +* 1. Foobar +* Regular item +- 2. second +- - nested bullet +- * mixed markers +* - reverse mixed +`; + +test("Test item indexing with nested lists in list items", async () => { + createMockSystem(); + const tree = parseMarkdown(nestedListMd); + const frontmatter = extractFrontMatter(tree); + const pageMeta: PageMeta = { + ref: "test", + name: "test", + tag: "page", + created: "", + lastModified: "", + perm: "rw", + }; + // Should not throw an error + const items = await indexItems(pageMeta, frontmatter, tree); + expect(items.length).toBeGreaterThan(0); + + // The regular item should still be indexed correctly + const regularItem = items.find((i) => i.name === "Regular item"); + expect(regularItem).toBeDefined(); +}); diff --git a/plugs/index/item.ts b/plugs/index/item.ts index 13f6dadf..4d16dc52 100644 --- a/plugs/index/item.ts +++ b/plugs/index/item.ts @@ -143,10 +143,14 @@ export function extractItemFromNode( item.text = renderToText(nameNode).trim(); - const nameNodeClone = cloneTree(nameNode!); - cleanTags(nameNodeClone); - cleanAttributes(nameNodeClone); - item.name = renderToText(nameNodeClone).trim(); + if (nameNode) { + const nameNodeClone = cloneTree(nameNode); + cleanTags(nameNodeClone); + cleanAttributes(nameNodeClone); + item.name = renderToText(nameNodeClone).trim(); + } else { + item.name = item.text; + } if (tags.length > 0) { item.tags = tags;