Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/parser/mindmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 || []
Expand Down
21 changes: 19 additions & 2 deletions src/parser/mindmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
File renamed without changes.
52 changes: 52 additions & 0 deletions src/parser/summary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})