Skip to content

Commit 68fb335

Browse files
authored
Merge pull request #23 from decaf-dev/dev
1.3.0
2 parents ce6c902 + fe53be5 commit 68fb335

File tree

9 files changed

+134
-54
lines changed

9 files changed

+134
-54
lines changed

README.md

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Obsidian Downloads](https://img.shields.io/badge/dynamic/json?logo=obsidian&color=%23483699&label=downloads&query=%24%5B%22note-splitter%22%5D.downloads&url=https%3A%2F%2Fraw.githubusercontent.com%2Fobsidianmd%2Fobsidian-releases%2Fmaster%2Fcommunity-plugin-stats.json)
44

5-
Note splitter is an [Obsidian.md](https://obsidian.md) plugin for desktop only. It allows you to split a single note into many notes based on a specified sequence of characters (a delimiter).
5+
Note splitter is an [Obsidian.md](https://obsidian.md) plugin for desktop only. It allows you to split a single note into many notes based on a sequence of characters (a delimiter).
66

77
## Table of contents
88

@@ -16,7 +16,7 @@ Note splitter is an [Obsidian.md](https://obsidian.md) plugin for desktop only.
1616

1717
## Videos
1818

19-
Split a note with default settings.
19+
Split a note using default settings.
2020

2121
<video src="https://github.com/decaf-dev/obsidian-note-splitter/assets/40307803/b15117e8-a297-4353-b705-13e7713872ef" controls="controls" style="max-width: 100%;">
2222
Your browser does not support the video tag.
@@ -39,15 +39,15 @@ Split a note with [use first line as title](#use-first-line-as-title) enabled.
3939

4040
## Usage
4141

42-
1. Open the note that you want to split
42+
1. Open a note that you want to split
4343
2. Switch to editing mode
4444
3. Open the Obsidian command palette
4545
4. Type **Split by delimiter**
4646
5. Press enter
4747
6. See split notes in the [output folder](#output-folder)
4848

4949
> [!NOTE]
50-
> Splitting a note does not modify the original note.
50+
> Splitting a note will not modify the original note.
5151
5252
### Frontmatter
5353

@@ -57,7 +57,7 @@ When splitting a note, frontmater is ignored. Only content after the frontmatter
5757

5858
### Output folder
5959

60-
The folder to save split notes in. If empty, the folder of the original note will be used.
60+
The folder to save split notes in. If the input is empty, the folder of the original note will be used.
6161

6262
> [!NOTE]
6363
> Default value is `note-splitter`
@@ -67,7 +67,40 @@ The folder to save split notes in. If empty, the folder of the original note wil
6767
The sequence of characters to split by. When you split a note, the content before and after each delimiter will become new notes.
6868

6969
> [!NOTE]
70-
> Default value is a newline character `\n`
70+
> The default value is a newline character `\n`
71+
72+
## Remove delimiter
73+
74+
If enabled, the delimiter will not be included in the content of split notes.
75+
76+
For example, suppose you have two sentences and your delimiter is set to a period `.`.
77+
78+
```markdown
79+
This is sentence 1. This is sentence 2.
80+
```
81+
82+
If this setting is enabled, the output will be:
83+
84+
```markdown
85+
This is sentence 1
86+
```
87+
88+
```markdown
89+
This is sentence 2
90+
```
91+
92+
If you wanted to retain the period in each split note, you could disable this setting. The output would then be:
93+
94+
```markdown
95+
This is sentence 1.
96+
```
97+
98+
```markdown
99+
This is sentence 2.
100+
```
101+
102+
> [!NOTE]
103+
> Enabled by default.
71104
72105
### Use first line as title
73106

@@ -102,37 +135,7 @@ When `Use first line as title` is enabled, invalid characters in the first line
102135

103136
### Append to split content
104137

105-
This text will be appended to each section of split content.
106-
107-
**Example:**
108-
109-
Suppose you have two sentences and your delimiter is set to a period (`.`).
110-
111-
```markdown
112-
This is sentence 1. This is sentence 2.
113-
```
114-
115-
The split content would result in:
116-
117-
```markdown
118-
This is sentence 1
119-
```
120-
121-
```markdown
122-
This is sentence 2
123-
```
124-
125-
If you want to retain the period at the end of each sentence, simply add a period into the input field of this setting.
126-
127-
The updated result would be:
128-
129-
```markdown
130-
This is sentence 1.
131-
```
132-
133-
```markdown
134-
This is sentence 2.
135-
```
138+
This is text that should appended to the content of each split note.
136139

137140
### Delete original
138141

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "note-splitter",
33
"name": "Note Splitter",
4-
"version": "1.2.1",
4+
"version": "1.3.0",
55
"minAppVersion": "0.15.0",
66
"description": "Split a note into individual notes based on a delimiter.",
77
"author": "DecafDev",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-note-splitter",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"description": "Split notes based on a delimiter",
55
"main": "main.js",
66
"scripts": {

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const DEFAULT_SETTINGS: NoteSplitterSettings = {
77
saveFolderPath: "note-splitter",
88
useContentAsTitle: false,
99
delimiter: "\\n",
10+
removeDelimiter: true,
1011
appendToSplitContent: "",
1112
deleteOriginalNote: false,
1213
};

src/obsidian/note-splitter-settings-tab.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ export default class NoteSplitterSettingsTab extends PluginSettingTab {
3636
}),
3737
);
3838

39+
new Setting(containerEl)
40+
.setName("Remove delimiter")
41+
.setDesc(
42+
"If enabled, the delimiter will not be included in the content of split notes.",
43+
)
44+
.addToggle((cb) =>
45+
cb.setValue(this.plugin.settings.removeDelimiter).onChange(async (value) => {
46+
this.plugin.settings.removeDelimiter = value;
47+
await this.plugin.saveSettings();
48+
}),
49+
);
50+
3951
new Setting(containerEl)
4052
.setName("Use first line as title")
4153
.setDesc(

src/splitter/split-by-delimiter.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,48 @@ export const splitByDelimiter = async (
99
notify: Notifier,
1010
file: TFile,
1111
isWindows: boolean,
12-
{
13-
delimiter,
14-
saveFolderPath,
15-
useContentAsTitle,
16-
appendToSplitContent,
17-
deleteOriginalNote,
18-
}: Pick<
12+
settings: Pick<
1913
NoteSplitterSettings,
2014
| "saveFolderPath"
2115
| "delimiter"
16+
| "removeDelimiter"
2217
| "useContentAsTitle"
2318
| "appendToSplitContent"
2419
| "deleteOriginalNote"
2520
>,
2621
) => {
22+
const {
23+
delimiter,
24+
saveFolderPath,
25+
useContentAsTitle,
26+
appendToSplitContent,
27+
removeDelimiter,
28+
deleteOriginalNote,
29+
} = settings;
2730
const escapedDelimiter = delimiter.replace(/\\n/g, "\n");
2831

2932
if (escapedDelimiter === "") {
3033
notify("No delimiter set. Please set a delimiter in the settings.");
3134
return;
3235
}
3336

34-
const data = await fileSystem.read(file);
35-
const dataWithoutFrontmatter = removeFrontmatterBlock(data);
36-
if (dataWithoutFrontmatter === "") {
37+
const content = await fileSystem.read(file);
38+
const contentWithoutFrontmatter = removeFrontmatterBlock(content);
39+
if (contentWithoutFrontmatter === "") {
3740
notify("No content to split.");
3841
return;
3942
}
4043

41-
const splitContent = dataWithoutFrontmatter
44+
const splitContent = contentWithoutFrontmatter
4245
.split(escapedDelimiter)
43-
.map((content) => content.trim())
44-
.filter((content) => content !== "");
46+
.map((splitContent) => splitContent.trim())
47+
.filter((splitContent) => splitContent !== "")
48+
.map((splitContent) => {
49+
if (!removeDelimiter) {
50+
return splitContent + delimiter;
51+
}
52+
return splitContent;
53+
});
4554

4655
if (splitContent.length === 1) {
4756
notify("Only one section of content found. Nothing to split.");

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface NoteSplitterSettings {
44
saveFolderPath: string;
55
useContentAsTitle: boolean;
66
delimiter: string;
7+
removeDelimiter: boolean;
78
appendToSplitContent: string;
89
deleteOriginalNote: boolean;
910
}

0 commit comments

Comments
 (0)