Skip to content

Commit

Permalink
add insert method
Browse files Browse the repository at this point in the history
  • Loading branch information
masaki39 committed May 7, 2024
1 parent 4b3087f commit 06e1b64
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 22 deletions.
52 changes: 43 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

# Obsidian Outline Converter Plugin

- Obsidian Outline Converter Plugin
- Features
- This plugin converts bullet list outlines into continuous text.
- You can use two commands: `Auto-header converter` & `Custom converter`
- It includes commands to fold text at indentation levels 1-3.
- Installation
- You can download from `Community plugins` in Obsidian settings.
- Commands
Expand All @@ -17,27 +15,44 @@
- Options include inserting text before or after content, ignoring content and using line breaks.
- Replacement
- You can search & replace terms as you like before outputting the connected sentences.
- {{break}}
- Double line breaks are inserted before this sentence, as I configured.
- Insertion
- You can use `{{i:id}}` as insert anything in the active file.
- {{i:mermaid}}
- `{{i:id}}` is replaced with content between `{{s:id}}` and `{{e:id}}`.
- Select export method
- Choose from the following options for exporting your text:
- Copy to clipboard.
- Append to the cursor's current position.
- Append to the bottom of the active note.
- Replace a section; if none exists, create it at the bottom of the note.
- Swap lines commands
- In bullet lists, it uses line swapping commands of the Outliner plugin.
- Outside of that, it simply swaps lines.
- You cannot use these commands unless the Outliner plugin is installed.
- Other commands
- Fold all of indentation levels 1-3.
- Swap lines commands
- In bullet lists, it uses line swapping commands of the Outliner plugin.
- Outside of that, it simply swaps lines.
- Note
- The command of `Auto-header converter` can convert this outline into the text below.

{{s:mermaid}}

```mermaid
flowchart TD
OutlineList-->|convert|ContinuousText
ContinuousText-->|replacement×1-5|ReplacedText
ReplacedText-->|+insertion|Export
```

{{e:mermaid}}
# Output


## Obsidian Outline Converter Plugin

### Features

This plugin converts bullet list outlines into continuous text. You can use two commands: `Auto-header converter` & `Custom converter` It includes commands to fold text at indentation levels 1-3.
This plugin converts bullet list outlines into continuous text. You can use two commands: `Auto-header converter` & `Custom converter`

### Installation

Expand All @@ -59,13 +74,32 @@ Customize how text is handled at each indentation level from 1 to 5. Options inc

You can search & replace terms as you like before outputting the connected sentences.

Double line breaks are inserted before this sentence, as I configured.

### Insertion

You can use `{{i:id}}` as insert anything in the active file.

```mermaid
flowchart TD
OutlineList-->|convert|ContinuousText
ContinuousText-->|replacement×1-5|ReplacedText
ReplacedText-->|+insertion|Export
```

Some

### Select export method

Choose from the following options for exporting your text: Copy to clipboard. Append to the cursor's current position. Append to the bottom of the active note. Replace a section; if none exists, create it at the bottom of the note.

### Swap lines commands
### Other commands

Fold all of indentation levels 1-3.

#### Swap lines commands

In bullet lists, it uses line swapping commands of the Outliner plugin. Outside of that, it simply swaps lines. You cannot use these commands unless the Outliner plugin is installed.
In bullet lists, it uses line swapping commands of the Outliner plugin. Outside of that, it simply swaps lines.

### Note

Expand Down
39 changes: 27 additions & 12 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export default class OutlineConverter extends Plugin {
// transform linebreak
result = result.replace(/\\n/g, "\n");

//insert methods
result = await this.insertContent(result);

// export
if (this.settings.exportMethod == 'Copy'){
this.copyContent(result);
Expand Down Expand Up @@ -189,6 +192,9 @@ export default class OutlineConverter extends Plugin {
// transform linebreak
result = result.replace(/\\n/g, "\n");

//insert methods
result = await this.insertContent(result);

// export
if (this.settings.exportMethod == 'Copy'){
this.copyContent(result);
Expand Down Expand Up @@ -287,11 +293,6 @@ export default class OutlineConverter extends Plugin {
const commands = (this.app as any).commands;
const commandExist = commands.listCommands().some((cmd: any) => cmd.id === commandId);

if (!commandExist){
new Notice("Install outliner plugin");
return;
}

const cursor = editor.getCursor();
if (cursor.line == 0) {
return;
Expand All @@ -300,7 +301,7 @@ export default class OutlineConverter extends Plugin {
const line = editor.getLine(cursor.line);
const lineAbove = editor.getLine(cursor.line - 1);

if (line.trim().startsWith(`- `) && lineAbove.trim().startsWith(`- `)) {
if (commandExist && !editor.somethingSelected() && line.trim().startsWith(`- `) && lineAbove.trim().startsWith(`- `)) {
commands.executeCommandById(commandId);
} else {
editor.exec("swapLineUp");
Expand All @@ -319,11 +320,6 @@ export default class OutlineConverter extends Plugin {
const commands = (this.app as any).commands;
const commandExist = commands.listCommands().some((cmd: any) => cmd.id === commandId);

if (!commandExist){
new Notice("Install outliner plugin");
return;
}

const cursor = editor.getCursor();
const lastLineNumber = editor.lineCount() - 1; // Get the index of the last line

Expand All @@ -335,7 +331,7 @@ export default class OutlineConverter extends Plugin {
const lineBelow = editor.getLine(cursor.line + 1);

// Check if both current line and the line below start with "- "
if (line.trim().startsWith(`- `) && lineBelow.trim().startsWith(`- `)) {
if (commandExist && !editor.somethingSelected() && line.trim().startsWith(`- `) && lineBelow.trim().startsWith(`- `)) {
commands.executeCommandById(commandId);
} else {
editor.exec("swapLineDown");
Expand Down Expand Up @@ -466,6 +462,25 @@ export default class OutlineConverter extends Plugin {
return connectedResult;
}

// insert methods
async insertContent(result: string): Promise<string> {
// get file
const activeFile = this.app.workspace.getActiveFile();
if (!activeFile) {
return result;
}
const fileContent = await this.app.vault.read(activeFile);

// match {{i:id}}
const insertPattern = /\{\{i:(.+?)\}\}/g;
result = result.replace(insertPattern, (match, id) => {
const contentPattern = new RegExp(`\\{\\{s:${id}\\}\\}(.*?)\\{\\{e:${id}\\}\\}`, 's');
const content = contentPattern.exec(fileContent);
return content ? content[1] : match;
});
return result;
}

// add output methods

// copy content
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": "outline-converter",
"name": "Outline Converter",
"version": "1.2.0",
"version": "1.3.0",
"minAppVersion": "1.5.12",
"description": "Convert outline to continuous text.",
"author": "masaki39",
Expand Down

0 comments on commit 06e1b64

Please sign in to comment.