diff --git a/src/parser/mindmap.ts b/src/parser/mindmap.ts index 57153bd..c5477a5 100644 --- a/src/parser/mindmap.ts +++ b/src/parser/mindmap.ts @@ -240,6 +240,8 @@ export const addTopic = (parentObject, mainTopic = "Main Topic", options = {}) = id: UUID(), title: mainTopic, titleUnedited: true, + boundaries: [], + summaries: [], ...options } parentObject.children.attached.push(topicObject) @@ -331,6 +333,8 @@ export const addSingleSummary = (parentObject, topicObject, options = {}) => { id: UUID(), title: "Summary", titleUnedited: true, + boundaries: [], + summaries: [], ...options } parentObject.children.summary = parentObject.children.summary || [] diff --git a/src/parser/mindmark.ts b/src/parser/mindmark.ts index 83990a6..4c310e5 100644 --- a/src/parser/mindmark.ts +++ b/src/parser/mindmark.ts @@ -43,6 +43,23 @@ function addLine(line: string, status: any) { status.lastTopic = topicObject + // Update levels array, setting summary topic as new parent topic level + // Use appropriate indentation level to ensure subsequent subtopics can correctly identify their parent + let summaryLevel = { + parent: topicObject, + indent: indent + 4, // Reserve indentation level for subtopics + boundaries: [], + summaries: [] + } + + // Add new level or replace existing level with same indentation + const existingLevelIndex = status.levels.findIndex(l => l.indent === indent + 4) + if (existingLevelIndex >= 0) { + status.levels[existingLevelIndex] = summaryLevel + } else { + status.levels.push(summaryLevel) + } + return } @@ -106,7 +123,7 @@ function addLine(line: string, status: any) { topicObject.title = line parentObject.boundaries - .filter(b => b.name == name) + ?.filter(b => b.name == name) .some(b => { let index = parentObject.children.attached.indexOf(topicObject) @@ -133,7 +150,7 @@ function addLine(line: string, status: any) { topicObject.title = line parentObject.summaries - .filter(b => b.name == name) + ?.filter(b => b.name == name) .some(b => { let index = parentObject.children.attached.indexOf(topicObject) diff --git a/src/parser/relstionship.spec.ts b/src/parser/relationship.spec.ts similarity index 100% rename from src/parser/relstionship.spec.ts rename to src/parser/relationship.spec.ts diff --git a/src/parser/summary.spec.ts b/src/parser/summary.spec.ts index b49a88f..d2ab12e 100644 --- a/src/parser/summary.spec.ts +++ b/src/parser/summary.spec.ts @@ -98,4 +98,56 @@ central topic }) + + it('SubSubtopics', () => { + let map = createMapByXMindMark(` +central topic +- subtopic 1[S] + - subsubtopic 1 +[S] summary topic + - summarySubtopic 1 + - summarySubtopic 2 + `) + + let subtopic1 = map.rootTopic.children.attached[0]; + strictEqual('subtopic 1', subtopic1.title); + + // Verify subtopic 1's child topic, now there's only one child + strictEqual('subsubtopic 1', subtopic1.children.attached[0].title); + + // Verify summary topic + let summaryTopic = map.rootTopic.children.summary[0]; + strictEqual('summary topic', summaryTopic.title); + + // Verify child topics under summary topic + strictEqual('summarySubtopic 1', summaryTopic.children.attached[0].title); + strictEqual('summarySubtopic 2', summaryTopic.children.attached[1].title); + + // Verify summary relationship + let summary = map.rootTopic.summaries[0]; + strictEqual('(0,0)', summary.range); + strictEqual(summaryTopic.id, summary.topicId); + }) + + it('Subtopics with boundaries', () => { + let map = createMapByXMindMark(` +central topic +* topic 1 [S] +* topic 2 [S] +[S] summary topic + - subtopic 1 [B] + - subtopic 2 [B] + [B] boundary topic + `) + let summaryTopic = map.rootTopic.children.summary[0] + strictEqual('summary topic', summaryTopic.title) + strictEqual('subtopic 1 ', summaryTopic.children.attached[0].title) + strictEqual('subtopic 2 ', summaryTopic.children.attached[1].title) + let summary = map.rootTopic.summaries[0] + strictEqual('(0,1)', summary.range) + strictEqual(summaryTopic.id, summary.topicId) + let boundary = summaryTopic.boundaries[0] + strictEqual('(0,1)', boundary.range) + strictEqual('boundary topic', boundary.title) + }) })