diff --git a/playground/index.html b/playground/index.html
index 0308129..d9f06b5 100644
--- a/playground/index.html
+++ b/playground/index.html
@@ -23,8 +23,8 @@
-
-
+
+
Or directly edit your minds below:
diff --git a/playground/src/loader.ts b/playground/src/loader.ts
index f636590..a43265b 100644
--- a/playground/src/loader.ts
+++ b/playground/src/loader.ts
@@ -1,10 +1,25 @@
+import { parseXMindToXMindMarkFile } from '../../src'
+
export async function loadFileAsText(file: File): Promise
{
return new Promise((resolve, reject) => {
const fileReader = new FileReader()
- fileReader.addEventListener('loadend', () => resolve(fileReader.result as string))
fileReader.addEventListener('error', reject)
fileReader.addEventListener('abort', reject)
- fileReader.readAsText(file)
+ const suffix = file.name.split('.').slice(-1)[0]
+ if (suffix === 'xmind') {
+ fileReader.readAsArrayBuffer(file)
+ fileReader.addEventListener('loadend', async () => {
+ const content = await parseXMindToXMindMarkFile(fileReader.result as ArrayBuffer);
+ if (content) {
+ resolve(content)
+ } else {
+ reject(new Error('Not valid .xmind file.'))
+ }
+ })
+ } else {
+ fileReader.readAsText(file)
+ fileReader.addEventListener('loadend', () => resolve(fileReader.result as string))
+ }
})
}
diff --git a/src/cli/commands.ts b/src/cli/commands.ts
index 9158a53..0e053ef 100644
--- a/src/cli/commands.ts
+++ b/src/cli/commands.ts
@@ -19,7 +19,7 @@ export const resetCommand = new Command('reset')
export async function fromActionHandler(xmindFilePath: string, outputFilePath: string | undefined) {
const xmindFile = readFileSync(xmindFilePath)
- const xmindmarkContent = await parseXMindToXMindMarkFile(xmindFile)
+ const xmindmarkContent = await parseXMindToXMindMarkFile(xmindFile.buffer as ArrayBuffer);
if (outputFilePath) {
let outputPath = resolve(outputFilePath)
@@ -44,7 +44,7 @@ export const fromCommand = new Command('from')
.description('Generate .xmindmark file from other types of file')
.action(fromActionHandler)
-export async function mainActionHandler(files: string[], options: CLIOptions, command: Command) {
+export async function mainActionHandler(files: string[], options: CLIOptions, command: Command) {
if (files.length === 0) command.help()
const { format, outputDir } = options
diff --git a/src/index.ts b/src/index.ts
index 6b289a3..769d491 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1 +1,2 @@
export { parseXMindMarkToXMindFile } from './lib/xmindmark-to-xmind'
+export { parseXMindToXMindMarkFile } from './lib/xmind-to-xmindmark'
\ No newline at end of file
diff --git a/src/lib/xmind-to-xmindmark.ts b/src/lib/xmind-to-xmindmark.ts
index d76b5a5..182536c 100644
--- a/src/lib/xmind-to-xmindmark.ts
+++ b/src/lib/xmind-to-xmindmark.ts
@@ -143,7 +143,8 @@ function isOrderInsideRange(range: ClosedRange, order: number): boolean {
}
function makeIndentOfLine({ depth }: Pick): string {
- return Array.from({ length: depth }).reduce(prevIndent => prevIndent.concat(' '), '')
+ return depth <= 1 ?
+ '' : Array.from({ length: depth - 1 }).reduce(prevIndent => prevIndent.concat(' '), '')
}
function makePrefixOfLine({ depth, type }: TopicScope): string {
@@ -225,7 +226,7 @@ function makeIdentifyBoundaries(topic: TopicModel): Boundary[] {
if (topic.boundaries.length === 1) return [{ ...topic.boundaries[0], identifier: 'B' }]
- return topic.boundaries.map((boundary, i) => ({ ...boundary, identifier: `B${i + 1}`}))
+ return topic.boundaries.map((boundary, i) => ({ ...boundary, identifier: `B${i + 1}` }))
}
function makeIdentifySummaries(topic: TopicModel): Summary[] {
@@ -237,7 +238,7 @@ function makeIdentifySummaries(topic: TopicModel): Summary[] {
&& topic.children.summary.length === topic.summaries.length
) {
const summaries = topic.summaries.map((summary, i) => {
- const title = topic.children!.summary?.find(({ id }) => id === summary.topicId )?.title
+ const title = topic.children!.summary?.find(({ id }) => id === summary.topicId)?.title
return typeof title !== 'undefined'
? { ...summary, title, identifier: `S${i + 1}` }
diff --git a/src/tests/xmind-to-xmindmark.sample.ts b/src/tests/xmind-to-xmindmark.sample.ts
index cb22538..37f2491 100644
--- a/src/tests/xmind-to-xmindmark.sample.ts
+++ b/src/tests/xmind-to-xmindmark.sample.ts
@@ -511,32 +511,32 @@ export const inputJSON = [
export const expectedOutputXMindMark =
`Central Topic
- - Main Topic 1 [^1]
- - Subtopic 1 [2]
- - Subtopic 1 [B1]
- - Subtopic 2 [B1][B2]
- - Subtopic 3 [B2]
- [B1]: title1
- [B2]: title2
- - Subtopic 2
- - Subtopic 3 [^2]
- - Subtopic 1 [B]
- - Subtopic 2 [B]
- - Subtopic 3 [B]
- [B]: title2
- - Main Topic 2 [1]
- - Main Topic 3
- - Subtopic 1
- - Subtopic 1 [^3][S1]
- - Subtopic 2 [B][S1][S2]
- - Subtopic 3 [B][S1][S2]
- - Subtopic 4 [S2]
- [S1]: Summary 1
- - Subtopic 1
- - Subtopic 2
- - Subtopic 3
- [S2]: Summary 2
- - Subtopic 2
- - Subtopic 3
- - Main Topic 4 [3]
+- Main Topic 1 [^1]
+ - Subtopic 1 [2]
+ - Subtopic 1 [B1]
+ - Subtopic 2 [B1][B2]
+ - Subtopic 3 [B2]
+ [B1]: title1
+ [B2]: title2
+ - Subtopic 2
+ - Subtopic 3 [^2]
+ - Subtopic 1 [B]
+ - Subtopic 2 [B]
+ - Subtopic 3 [B]
+ [B]: title2
+- Main Topic 2 [1]
+- Main Topic 3
+ - Subtopic 1
+ - Subtopic 1 [^3][S1]
+ - Subtopic 2 [B][S1][S2]
+ - Subtopic 3 [B][S1][S2]
+ - Subtopic 4 [S2]
+ [S1]: Summary 1
+ - Subtopic 1
+ - Subtopic 2
+ - Subtopic 3
+ [S2]: Summary 2
+ - Subtopic 2
+ - Subtopic 3
+- Main Topic 4 [3]
`
\ No newline at end of file