twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.17k stars 71 forks source link

[FR] button to open contents of code block in code editor #194

Closed erauner12 closed 1 year ago

erauner12 commented 1 year ago

If I want to make changes to the code with the full power of a code editor, it would be cool if I could open the contents of the code in an individual block in vscode, for example.

erauner12 commented 1 year ago

if run-javascript for example, then open open in vscode with syntax highlighting of .js file:

ex:

function multiple(x) {

    function fn(y)
    {
        return x * y;
    }

    return fn;
}

var triple = multiple(3);
triple(2); // returns 6
triple(3); // returns 9
console.log(triple(2));
chlohal commented 1 year ago

Would this open the Markdown file, but with JS language mode on? Or a separate file created for the specific code block?

hannesdelbeke commented 1 year ago

separate file would make most sense, however I'f then also expect a way to send codechanges back to obsidian

this could be achieved by

  1. saving the code as a temp file
  2. open it in your favorite editor
  3. do changes, press save
  4. obsidian plugin detects the updates and reloads with new code in the code block
chlohal commented 1 year ago

I see, thanks. Currently, editing the code block content is difficult for the plugin (as we apply buttons to the rendered version -- accessing the source code from the rendered version is hard).

This can definitely be done, but we'd have to get that working first. I'm sorry

twibiral commented 1 year ago

As @chlohal said, this is hard to do and not part of the near-future roadmap. If you use javascript instead of run-javascript at least the syntax highlighting will still work and you can still run the code in the reading. You can also install the plugin Completr to get an IDE-like auto-completion.

erauner12 commented 1 year ago

Makes sense, I appreciate the consideration!

hannesdelbeke commented 1 year ago

how hard would it be to run a whole file, instead of a block? this would avoid the need to handle the editting of code blocks, since you can just open the whole note in an IDE.

  1. e.g. in obsidian you can have a note named my_note.py
  2. you can "execute" the whole note with this plugin
  3. you can also open the note in another IDE, since it's just a file. then any updates to this will auto show in Obsidian.
  4. if i want to show the note in a code block, i could do ![[my_note.py]] to expand the content