Execute code in logseq

As a student
I would like to
Execute the programming code directly from logseq

execute_code_example

Reference: GitHub - twibiral/obsidian-execute-code: Obsidian Plugin to execute code in a note.

Please let’s gather ideas and thoughts about this here:

some implantation is available in JavaScript here
GitHub - twibiral/obsidian-execute-code: Obsidian Plugin to execute code in a note.

Hello @Dinesh_Datir. It seems that what you posted is an Obsidian plugin. Just out of curiosity, does the code running with that plugin have access to any data in the page or vault, or is it completely isolated?

hi @danilofaria . Not sure about it , But what I can tell is, it is using code block content and running with compiler , for c++ it uses cling compiler.

Also there is similar extension for VS code .

GitHub - JeepShen/vscode-markdown-code-runner: Run code snippets in Markdown.

Regarding scope of access. I have my logseq graphs inside an Obsidian vault. Obsidian can search all the logseq graphs plus I have tested an Obsidian plugin that can access all logseq graphs and pages. I tried a Logseq plugin and its access seems restricted to the Logseq graph it is contained in.

I’m only using Obsidian to get javascript access to all my Logseq graphs and their pages.

Maybe Logseq will open up the API to allow plugin developers to scan pages in multiple graphs.

This is already possible, logseq-query can perform a query to multiple graphs at once:

Also, Logseq plugins API are available over HTTP/JSON if you enable the local server in Logseq settings. Those API can work with multiple graphs at once.

1 Like

By way of explanation I have existing command line scripts that check the markdown files for discrepancies independent of datalog and EDNs in order to identify any bad references, perform counts etc.

So I’m looking for a javascript API call that can be included in my own plugin that can perform multigraph serial searches of the markdown files rather than running datalog queries.

In Obsidian their API has this call

getMarkdownFiles();

which returns an array of the content of the markdown file. There is no requirement for a server to be created.

Any idea how I could code this in logseq?

Thanks

deflet can help in executing code (clojure) that is in the markdown code snippet

```clojure
(prn 1)
\```

Logseq already supports evaluating Clojure snippets:

https://docs.logseq.com/#/page/clojurescript%20eval%20in%20a%20block

3 Likes

Good point … however I was after a javascript option not clojure :slight_smile:

2 Likes

Have you try logseq custom.js feature? I can add custom function with Javascript and call it from clojure eval in logseq

2 Likes

The last one provides an example of mixing both:

2 Likes

Is there any interest in having a way to run powershell or bash from within Logseq? I’d be the first interested in both powershell and bash. Moreover, I would love if these could be made to automatically run when the page is loaded via some sort of property …

Nice-to-have: I believe R Studio has a nice capability with regards to running code snippets (Inline Code)