[HELP] i asked gpt4 to write a plugin to add empty lines between lines, could someone /w experience help? thx

hi,
the reason is that todo.txt used by markor, after sorting, will remove all empty lines.

yet, as you know in obsidian, a block is defined as having empty lines above and below.

so even i can use todo.md with markor AND obsidian, after sorting in markor, all empty lines are removed and obsidian ONLY see it as 1 single block.

I have been annoying for this since i use obsidian, because it’s just 1 step away from my target.

now, gpt4 wrote a plugin for me.
from my experience /w gpt4 and VBA, the plugin 's BACKBONE would be ok, i think there may need some troubleshooting.

I AM NO JS programmer (but learn some basic/logo/pascal/C/VB in high school/college).

wish someone could give a hand.

also, if this works (gpt4 helped me made 3 VBA macro for mindmanager),
future is unlimited (yeah gpt4 ofcause is great).

so the script is attached below. let’s see how it will go. thanks

1234

me to gpt4:
can you write an obsidian plugin for me, that it add an empty line between each existing line of text? so that every line is separated from another line by an empty line.

gpt4 reply:
Sure! Here’s a simple Obsidian plugin that adds an empty line between each existing line of text in the active document when you run the command. This plugin assumes you have the development environment set up, as described in the previous answer.

1. Write the plugin code: Create a new JavaScript file (e.g., line-spacer-plugin.js) and add the following code:

const { Plugin } = require("obsidian");

class LineSpacerPlugin extends Plugin {
  async onload() {
    this.addCommand({
      id: "add-empty-lines",
      name: "Add empty lines between lines",
      callback: this.addEmptyLines.bind(this),
    });
  }

  async addEmptyLines() {
    const activeView = this.app.workspace.getActiveViewOfType(this.app.plugins.plugins["markdown"].viewType);

    if (!activeView) {
      return;
    }

    const editor = activeView.sourceMode.cmEditor;
    const doc = editor.getDoc();
    const lineCount = doc.lineCount();

    editor.operation(() => {
      for (let i = lineCount - 1; i > 0; i--) {
        doc.replaceRange("\n", { line: i, ch: 0 });
      }
    });
  }
}

module.exports = LineSpacerPlugin;

2. Build the plugin: Use esbuild to bundle the plugin as described in the previous answer:

esbuild line-spacer-plugin.js --outfile=line-spacer-plugin-built.js --bundle --platform=browser

3. Create a manifest file: Create a manifest.json file in the project directory with the following content:

{
  "id": "line-spacer-plugin",
  "name": "Line Spacer Plugin",
  "version": "0.1.0",
  "description": "A plugin that adds an empty line between each existing line of text in the active document.",
  "author": "Your Name",
  "main": "line-spacer-plugin-built.js",
  "minAppVersion": "0.9.20"
}

4. Load the plugin in Obsidian: Follow the steps described in the previous answer to load the plugin in Obsidian.

Once the plugin is loaded, you can use it by opening a document, then go to the command palette (default hotkey: Ctrl/Cmd+P), search for “Add empty lines between lines,” and press Enter. This will add an empty line between each existing line of text in the active document.

i haven’t setup the development environment yet,
could someone who have experience try compile and test?

thanks

wow, it’s much complex than a VBA macro…

If ChatGPT helps you with something that you adapt, test, and get working for yourself, great! Please share!

But, please don’t copy/paste ChatGPT answers here. The Obsidian Group Discord message when someone posts a ChatGPT “answer” →

Thanks for trying to help! However, asking ChatGPT or any other LLMs (Large Language Models) is discouraged in our community because their responses often contain outdated information or straight-up misinformation. If you don’t know the answer, that’s fine! Other community members can help with unanswered questions.

Thanks :fairy:

1 Like

no,
it helped me to finish 3 vba.

btw what i use is gpt4.

chatgpt=gpt3.5

yes


We don’t encourage AI answers to help questions, nor AI-generated code examples in this community. Your post has been unlisted.

Whatever version ChatGPT is is not irrelevant. As ariehen correctly quoted, “ChatGPT or any other LLMs

it’s a half made product,
i am asking for manual input to finish it.

gpt4 did the 50%,
i am asking someone to give several,
so i can add it up to 100%.

and it seems it is not encouraged here.

then it wont be done from me, thank you you all.

That’s right. Thanks for understanding.

Regarding the problem you were trying to write a plugin to solve, try the Apply Patterns community plugin.

1 Like