Giter Site home page Giter Site logo

mokeyish / obsidian-code-emitter Goto Github PK

View Code? Open in Web Editor NEW
238.0 5.0 8.0 1.23 MB

An obsidian plugin that allows code blocks executed interactively in sandbox like jupyter notebooks. Supported language rust、kotlin、python、Javascript、TypeScript etc.

License: GNU General Public License v3.0

Svelte 11.01% TypeScript 86.14% JavaScript 2.61% CSS 0.24%
code-runner jupyter markdown obsidan

obsidian-code-emitter's Introduction

Obsidian Code Emitter

GitHub release (latest by date including pre-releases) GitHub all releases

This plugin allows code blocks executed interactively like jupyter notebooks. It is based on HTTP REST APIs and JS sandbox and Webassembly technology, and has no local environment requirements, so it supports all platforms supported by Obsidian.

Supports all Obsidian supported platforms, includes:

  • Windows
  • MacOS
  • Linux
  • Android
  • IOS

Currently, support languages:

Supported language Way
Rust https://play.rust-lang.org
Kotlin https://play.kotlinlang.org
V https://play.vosca.dev/
JavaScript JS Sandbox (qiankun)
TypeScript[] TypeScript Compiler + JS Sandbox
Wenyan Wenyan Compiler + JS Sandbox
Python WebAssembly (Pyodide)
Java Sololearn
Go Sololearn
c/c++ Sololearn
CSharp Sololearn
Swift Sololearn
R Sololearn

Note: Only PythonTypeScriptJavaScript are run locally in sandbox(js / webassembly). Other's will send code to third-party website to eval the results (eg: https://play.kotlinlang.org, https://play.rust-lang.org). Please take care to avoid sending your potentially-sensitive source code.

Ads: You might like my other plugins 🤪


.

Installation

  1. Search Code Emitter in the community plugins of obsidian, and install it.

Examples

Python

Install numpy through micropip. All available packages are list in here (search whl).

import micropip
await micropip.install('numpy')  
import numpy as np
a = np.random.rand(3,2)
b = np.random.rand(2,5)

print(a@b)

Any languages that support CORS

Here is the example to support Ruby.

const url = 'https://api2.sololearn.com/v2/codeplayground/v2/compile';

const runCode = async (code: string, lang: 'cpp' | 'go' | 'c' | 'java' | 'cs' | 'swift' | 'rb') => {
  const header = {
    'User-Agent': 'Obsidian Code Emitter/0.1.0 (If this is not allowed, please let me know)',
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'en-US',
    'Content-Type': 'application/json',
  };
		
  const res = await fetch(url, {
    'headers': header,
    'body': JSON.stringify({
      'code': code,
      'codeId': null,
      'input': '',
      'language': lang
    }),
    'method': 'POST',
  });
  return (await res.json()) as {
    success: boolean,
    errors: string[],
    data: {
      sourceCode: number,
      status: number,
      errorCode: number,
      output: string,
      date: string,
      language: string,
      input: string,
    }
  };
};

const ruby_code = `
puts "Hello World12"
`;


console.log((await runCode(ruby_code, 'rb')).data.output);

License

This plugin sandbox contains codes from https://github.com/umijs/qiankun, which is licensed under

And other codes is licensed under

obsidian-code-emitter's People

Contributors

dependabot[bot] avatar flippingbinary avatar github-actions[bot] avatar mokeyish avatar nicosup98 avatar seiimonn avatar zhymabekroman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

obsidian-code-emitter's Issues

plugin is making calls to external web sites without warning user

I was poking through this plugin's code to see how it worked and came across this line in the backend for java:

const url = 'https://api2.sololearn.com/v2/codeplayground/v2/compile';

It appears that this plugin makes a call to a third-party web site to compile code. It is unclear whether sololearn.com is OK with this use of their api, but in any case, the user should certainly be warned about sending potentially-sensitive source code for compilation to a third party they may not know or trust. Also, the plugin's README should be very clear about what's happening on the backend so that users can make an informed choice about whether to trust it.

Similar issues exist for the other compiled languages, it seems:

For kotlin:

const url = 'https://api.kotlinlang.org//api/1.7.10/compiler/run';

For rust:

const url = 'https://play.rust-lang.org/execute';

For go:

const url = 'https://go.dev/_/compile?backend=';

Suggest for running code in editing view

It's a very nice plugin, but I prefer to run my python code in the editing view rather than in the reading view

Just like another plugin that runs python plugin called jupyter

Display image output

Is it possible for image output (such as seaborn graphs) to displayed inline?

Documentation Request: How To Add New Languages

This plug-in looks awesome!

I would love to use it with Ruby, and possibly other languages as well (Go, Zig, & Crystal).
Any directions on how to add new languages would be appreciated.

How to execute blocks?

I've just installed Code Emitter plugin 0.1.4 inside Obsidian 1.5.8 on macOS 13.6.4, but I cannot see any button or other means to actually run a code block, Python or Typescript like this:

print(42)

I am missing a short sentence about how to do that in the README as well. Ideas welcome!

matplotlib

How to show graph from matplotlib? I use code:

import micropip                          
await micropip.install('numpy')    
await micropip.install('matplotlib')    
import matplotlib.pyplot as plt           
import numpy as np                        

# data
x = np.linspace(0, 10, 100)
y = np.sin(x)

# graph
plt.figure(figsize=(10, 6))
plt.plot(x, y)
plt.title("Sine Curve")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.grid(True)

# show
plt.show()

julia support

Hi -- would it be possible to add support for Julia evaluation? It isn't supported by sololearn unfortunately. However, it is supported in python notebooks, like jupyter.

Prompt box blocks text (python)

When using the input() function, the prompt box blocks your view of the text telling you what to input. I have yet to test this on desktop, only mobile.

It would be cool to control the ability to run the code auto that I marked separately.

config Code-Emitter:

  • auto: off

Something like that in note:

  • 1
const a = 10;
console.log(`Output: ${a}`)
//Output: 10
  • 2
const b = 20;
console.log(`Output: ${b}`);

So the first code have option run:true(or something like this) and have result: "Output: 10", second code - just wait pressing ▶ and not running, because of configuration of code-emitter.

OR
config Code-Emitter:

  • auto: on

Something like that in note:

  • 3
const c = 10;
console.log(`Output: ${c}`)
//Output: 10
  • 4
const d = 20;
console.log(`Output: ${d}`);

So the third code autorunning is working, the fourth code used manually block(option run: block) for code running.

Unable to run single-line code block

When the code block contains only a single line, the play button is overlapped by the copy button, which prevents execution of the code.

Example:

```typescript
console.log("Hello, World!");
```

Result:

image

Request for Adding C and C++ Support

First of all, I would like to express my gratitude for creating such an amazing Obsidian plugin.

I noticed that the plugin currently does not support C and C++, and I believe that adding this feature could benefit many users. I recently came across a website called cpp.sh which may be useful in adding C and C++ support, as it uses emcc and returns wasm files. However, since I am not familiar with JavaScript and TypeScript, I don't have the ability to add this feature myself. Therefore, I am writing to request if you could consider adding C and C++ support to your plugin.

I understand that you may have other priorities and limitations, so please do not feel obliged to comply with this request. However, if you are able to add support for C and C++, I believe it could help attract more users and make your plugin more diverse.

Thank you for your time and consideration.

[Question] Caching Micropip Wheels

I've been experimenting with using this for python, and it is very cool! I have a question!

When I use micropip to install a package programmatically, it grabs wheels from here. Is it possible to cache those wheels somewhere inside the plugin directory or vault so they get naturally synced with Obsidian sync?

can't open local files

hi, I think this plugin is awesome. now I met one problem is I don't know how to open / save the files in local directory? my computer is Mac system. Thanks.

Update from 0.1.2 to 0.1.3 fails via Obsidian Community Install

Actions:

  1. Open Obsidian
  2. Open Settings
  3. Find Code Emitter in installed community plugins
  4. Click update button

Results:
v0.1.2 remains installed

Expected Results:
v0.1.3 installed

I've also done an uninstall/delete subfolder/reinstall with the same result.

Input isn't working on win11

Issue description:
I run the python code with input() on android obsisdian app and it works, but on my windows11 PC I can't execute this code

Video Android:
https://github.com/user-attachments/assets/1c1c8102-67f4-4580-9857-0f3f13698381

Video Windows 11:
https://github.com/user-attachments/assets/9ad4561c-d4d5-49ae-a626-3f8012042255

Error text:

PythonError: Traceback (most recent call last):
File "/lib/python3.10/asyncio/futures.py", line 201, in result
raise self._exception
File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
result = coro.send(None)
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 506, in eval_code_async
await CodeRunner(
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 357, in run_async
coroutine = eval(self.code, globals, locals)
File "", line 1, in
OSError: [Errno 29] I/O error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.