Skip to content

Commit

Permalink
Merge pull request #23 from decaf-dev/dev
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
decaf-dev authored Sep 22, 2024
2 parents ce6c902 + fe53be5 commit 68fb335
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 54 deletions.
77 changes: 40 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![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)

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).
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).

## Table of contents

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

## Videos

Split a note with default settings.
Split a note using default settings.

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

## Usage

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

> [!NOTE]
> Splitting a note does not modify the original note.
> Splitting a note will not modify the original note.
### Frontmatter

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

### Output folder

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

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

> [!NOTE]
> Default value is a newline character `\n`
> The default value is a newline character `\n`
## Remove delimiter

If enabled, the delimiter will not be included in the content of split notes.

For example, suppose you have two sentences and your delimiter is set to a period `.`.

```markdown
This is sentence 1. This is sentence 2.
```

If this setting is enabled, the output will be:

```markdown
This is sentence 1
```

```markdown
This is sentence 2
```

If you wanted to retain the period in each split note, you could disable this setting. The output would then be:

```markdown
This is sentence 1.
```

```markdown
This is sentence 2.
```

> [!NOTE]
> Enabled by default.
### Use first line as title

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

### Append to split content

This text will be appended to each section of split content.

**Example:**

Suppose you have two sentences and your delimiter is set to a period (`.`).

```markdown
This is sentence 1. This is sentence 2.
```

The split content would result in:

```markdown
This is sentence 1
```

```markdown
This is sentence 2
```

If you want to retain the period at the end of each sentence, simply add a period into the input field of this setting.

The updated result would be:

```markdown
This is sentence 1.
```

```markdown
This is sentence 2.
```
This is text that should appended to the content of each split note.

### Delete original

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "note-splitter",
"name": "Note Splitter",
"version": "1.2.1",
"version": "1.3.0",
"minAppVersion": "0.15.0",
"description": "Split a note into individual notes based on a delimiter.",
"author": "DecafDev",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-note-splitter",
"version": "1.2.1",
"version": "1.3.0",
"description": "Split notes based on a delimiter",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const DEFAULT_SETTINGS: NoteSplitterSettings = {
saveFolderPath: "note-splitter",
useContentAsTitle: false,
delimiter: "\\n",
removeDelimiter: true,
appendToSplitContent: "",
deleteOriginalNote: false,
};
Expand Down
12 changes: 12 additions & 0 deletions src/obsidian/note-splitter-settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export default class NoteSplitterSettingsTab extends PluginSettingTab {
}),
);

new Setting(containerEl)
.setName("Remove delimiter")
.setDesc(
"If enabled, the delimiter will not be included in the content of split notes.",
)
.addToggle((cb) =>
cb.setValue(this.plugin.settings.removeDelimiter).onChange(async (value) => {
this.plugin.settings.removeDelimiter = value;
await this.plugin.saveSettings();
}),
);

new Setting(containerEl)
.setName("Use first line as title")
.setDesc(
Expand Down
35 changes: 22 additions & 13 deletions src/splitter/split-by-delimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,48 @@ export const splitByDelimiter = async (
notify: Notifier,
file: TFile,
isWindows: boolean,
{
delimiter,
saveFolderPath,
useContentAsTitle,
appendToSplitContent,
deleteOriginalNote,
}: Pick<
settings: Pick<
NoteSplitterSettings,
| "saveFolderPath"
| "delimiter"
| "removeDelimiter"
| "useContentAsTitle"
| "appendToSplitContent"
| "deleteOriginalNote"
>,
) => {
const {
delimiter,
saveFolderPath,
useContentAsTitle,
appendToSplitContent,
removeDelimiter,
deleteOriginalNote,
} = settings;
const escapedDelimiter = delimiter.replace(/\\n/g, "\n");

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

const data = await fileSystem.read(file);
const dataWithoutFrontmatter = removeFrontmatterBlock(data);
if (dataWithoutFrontmatter === "") {
const content = await fileSystem.read(file);
const contentWithoutFrontmatter = removeFrontmatterBlock(content);
if (contentWithoutFrontmatter === "") {
notify("No content to split.");
return;
}

const splitContent = dataWithoutFrontmatter
const splitContent = contentWithoutFrontmatter
.split(escapedDelimiter)
.map((content) => content.trim())
.filter((content) => content !== "");
.map((splitContent) => splitContent.trim())
.filter((splitContent) => splitContent !== "")
.map((splitContent) => {
if (!removeDelimiter) {
return splitContent + delimiter;
}
return splitContent;
});

if (splitContent.length === 1) {
notify("Only one section of content found. Nothing to split.");
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface NoteSplitterSettings {
saveFolderPath: string;
useContentAsTitle: boolean;
delimiter: string;
removeDelimiter: boolean;
appendToSplitContent: string;
deleteOriginalNote: boolean;
}
Expand Down
Loading

0 comments on commit 68fb335

Please sign in to comment.