https://github.com/mprojectscode/obsidian-js-engine-plugin
https://github.com/mprojectscode/obsidian-js-engine-plugin
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/mprojectscode/obsidian-js-engine-plugin
- Owner: mProjectsCode
- License: gpl-3.0
- Created: 2023-06-28T19:23:53.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2025-03-22T16:57:47.000Z (about 1 year ago)
- Last Synced: 2025-03-30T02:04:47.776Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://www.moritzjung.dev/obsidian-js-engine-plugin-docs/
- Size: 795 KB
- Stars: 118
- Watchers: 5
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Obsidian JS Engine Plugin
This plugin for Obsidian allows you to run JavaScript from within your notes using special code blocks.
## Usage
Start by creating a code block with `js-engine` as the code block language.
Inside the code block you can write what ever JavaScript code that you want.
The plugin will run the JavaScript and render the returned value in place of the code block.
````md
## This is a Note in Obsidian
```js-engine
return engine.markdown.create('*test*');
```
````
## API Docs
Docs are available [here](https://www.moritzjung.dev/obsidian-js-engine-plugin-docs/).
## Examples
### Markdown Builder
```js
let markdownBuilder = engine.markdown.createBuilder();
markdownBuilder.createHeading(2, 'Test Heading');
markdownBuilder.createParagraph('This is a test paragraph.');
markdownBuilder.createHeading(3, 'This is a sub heading');
markdownBuilder.createHeading(4, 'This is a sub sub heading');
markdownBuilder.createParagraph('This is another test paragraph.');
return markdownBuilder;
```
#### Output
> ## Test Heading
>
> This is a test paragraph.
>
> ### This is a sub heading
>
> #### This is a sub sub heading
>
> This is another test paragraph.
### Rendering Strings as Markdown
```js
let str = '*test*';
return str;
```
```js
let str = '*test*';
return engine.markdown.create(str);
```
The top example renders the string as plain text and the second one renders the text as markdown.
#### Output
> \*test\*
> _test_
### Importing JS
```js
let lib = await engine.importJs('lib.js');
return lib.getGreeting();
```
With a file named `lib.js` in the root of the vault.
```js
export function getGreeting() {
return 'Hello!';
}
```
#### Output
> Hello!