Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mokeyish/obsidian-code-emitter
An obsidian plugin that allows code blocks executed interactively in sandbox like jupyter notebooks. Supported language rust、kotlin、python、Javascript、TypeScript etc.
https://github.com/mokeyish/obsidian-code-emitter
code-runner jupyter markdown obsidan
Last synced: 12 days ago
JSON representation
An obsidian plugin that allows code blocks executed interactively in sandbox like jupyter notebooks. Supported language rust、kotlin、python、Javascript、TypeScript etc.
- Host: GitHub
- URL: https://github.com/mokeyish/obsidian-code-emitter
- Owner: mokeyish
- License: gpl-3.0
- Created: 2022-07-30T07:32:13.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T13:47:33.000Z (20 days ago)
- Last Synced: 2024-10-22T23:41:22.245Z (19 days ago)
- Topics: code-runner, jupyter, markdown, obsidan
- Language: TypeScript
- Homepage:
- Size: 1.28 MB
- Stars: 263
- Watchers: 5
- Forks: 12
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - mokeyish/obsidian-code-emitter - An obsidian plugin that allows code blocks executed interactively in sandbox like jupyter notebooks. Supported language rust、kotlin、python、Javascript、TypeScript etc. (TypeScript)
README
# Obsidian Code Emitter
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/mokeyish/obsidian-code-emitter?display_name=tag&include_prereleases)
![GitHub all releases](https://img.shields.io/github/downloads/mokeyish/obsidian-code-emitter/total?style=flat-square)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
- IOSCurrently, support languages:
| Supported language | Way |
| ------------------ | ------------------------------------------------------------ |
| Rust | https://play.rust-lang.org |
| Kotlin | https://play.kotlinlang.org |
| V | https://play.vosca.dev/ |
| HTML&CSS | [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM) |
| JavaScript | JS Sandbox ([qiankun](https://github.com/umijs/qiankun/blob/master/src/sandbox/index.ts)) |
| TypeScript[] | [TypeScript](https://www.typescriptlang.org/) Compiler + JS Sandbox |
| Wenyan | [Wenyan](https://github.com/wenyan-lang/wenyan) Compiler + JS Sandbox |
| Python | WebAssembly ([Pyodide](https://github.com/pyodide/pyodide)) |
| Java | [Sololearn](https://www.sololearn.com) |
| Go | [Sololearn](https://www.sololearn.com) |
| c/c++ | [Sololearn](https://www.sololearn.com) |
| CSharp | [Sololearn](https://www.sololearn.com) |
| Swift | [Sololearn](https://www.sololearn.com) |
| R | [Sololearn](https://www.sololearn.com) |**Note**: Only `Python`、`TypeScript`、`JavaScript` 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 🤪
- [Obsidian Enhancing Export](https://github.com/mokeyish/obsidian-enhancing-export)
---
![.](./screenshots/code-emitter.gif)
## Installation
1. Search `Code Emitter` in the community plugins of [obsidian](https://obsidian.md/), and install it.
## Examples
### Python
Install numpy through `micropip`. All available packages are list in [here](https://github.com/mokeyish/pyodide-dist/find/master) (search `whl`).
#### using numpy
```python
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)
```#### using matplotlib
```python
import micropip
await micropip.install('matplotlib')import matplotlib.pyplot as plt
fig, ax = plt.subplots() # Create a figure containing a single Axes.
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the Axes.
plt.show() # Show the figure.
```### HTML&CSS
```html
Helloworld.h {
color: red;
}
.w {
color: green;
}```
### Any languages that support CORS
Here is the example to support Ruby.
```typescript
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](https://github.com/umijs/qiankun/blob/master/src/sandbox/index.ts), which is licensed under
- MIT license (LICENSE-MIT or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
And other codes is licensed under
- GPL-3.0 license (LICENSE-GPL-3.0 or [https://opensource.org/licenses/GPL-3.0](https://opensource.org/licenses/GPL-3.0))