From f69e34b8c1496d24474a986849465be71afde8f1 Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Sat, 7 Mar 2020 18:33:33 +0100 Subject: [PATCH] Separate the "joinString" content from the concatenated files by line breaks --- src/index.ts | 4 ++-- test/index.test.ts | 8 +++++++ test/test-helper/expected/join-separator.txt | 22 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/test-helper/expected/join-separator.txt diff --git a/src/index.ts b/src/index.ts index dae82ca..dc418f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -109,7 +109,7 @@ class MarkDownConcatenator { ignore = [], decreaseTitleLevels = false, startTitleLevelAt = 1, - joinString = "\n", + joinString, titleKey, dirNameAsTitle = false, fileNameAsTitle = false, @@ -121,7 +121,7 @@ class MarkDownConcatenator { this.ignore = ignore; this.decreaseTitleLevels = decreaseTitleLevels; this.startTitleLevelAt = startTitleLevelAt; - this.joinString = joinString; + this.joinString = joinString ? `\n${joinString}\n` : "\n"; this.titleKey = titleKey; this.dirNameAsTitle = dirNameAsTitle; this.fileNameAsTitle = fileNameAsTitle; diff --git a/test/index.test.ts b/test/index.test.ts index 01a22e8..621779d 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -51,6 +51,14 @@ describe("concat", () => { expect(result).toBe(expected); }); + it("should join concatenated files using a specified string.", async () => { + const result = await concat(join(__dirname, "test-helper/main"), { + joinString: "---", + }); + const expected = await getExpected("join-separator.txt"); + expect(result).toBe(expected); + }); + it("should add toc tag and table of contents.", async () => { const result = await concat(join(__dirname, "test-helper/main"), { toc: true }); const expected = await getExpected("toc-tag.txt"); diff --git a/test/test-helper/expected/join-separator.txt b/test/test-helper/expected/join-separator.txt new file mode 100644 index 0000000..a9a42e0 --- /dev/null +++ b/test/test-helper/expected/join-separator.txt @@ -0,0 +1,22 @@ + + + +# Doc A + +--- + + + +# Doc B1 + +--- + + + +# Doc B2 + +--- + + + +# Doc BSub