Skip to content

Commit 0b59ff7

Browse files
committed
update readme and docs
1 parent 3c77e94 commit 0b59ff7

35 files changed

+505
-394
lines changed

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build obsidian plugin
2+
3+
on:
4+
push:
5+
# Sequence of patterns matched against refs/tags
6+
tags:
7+
- '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10
8+
9+
env:
10+
PLUGIN_NAME: obsidian-js-engine-plugin # Change this to the name of your plugin-id folder
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Use Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: '18.x' # You might need to adjust this value to your own version
22+
- name: Build
23+
id: build
24+
run: |
25+
yarn
26+
yarn run build --if-present
27+
mkdir ${{ env.PLUGIN_NAME }}
28+
cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}
29+
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
30+
ls
31+
echo "tag_name=$(git tag --sort version:refname | tail -n 1)" >> $GITHUB_OUTPUT
32+
33+
- name: Create Release
34+
id: create_release
35+
uses: actions/create-release@v1
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
VERSION: ${{ github.ref }}
39+
with:
40+
tag_name: ${{ github.ref }}
41+
release_name: ${{ github.ref }}
42+
draft: false
43+
prerelease: false
44+
45+
- name: Upload zip file
46+
id: upload-zip
47+
uses: actions/upload-release-asset@v1
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
with:
51+
upload_url: ${{ steps.create_release.outputs.upload_url }}
52+
asset_path: ./${{ env.PLUGIN_NAME }}.zip
53+
asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip
54+
asset_content_type: application/zip
55+
56+
- name: Upload main.js
57+
id: upload-main
58+
uses: actions/upload-release-asset@v1
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
with:
62+
upload_url: ${{ steps.create_release.outputs.upload_url }}
63+
asset_path: ./main.js
64+
asset_name: main.js
65+
asset_content_type: text/javascript
66+
67+
- name: Upload manifest.json
68+
id: upload-manifest
69+
uses: actions/upload-release-asset@v1
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
with:
73+
upload_url: ${{ steps.create_release.outputs.upload_url }}
74+
asset_path: ./manifest.json
75+
asset_name: manifest.json
76+
asset_content_type: application/json
77+
78+
- name: Upload styles.css
79+
id: upload-css
80+
uses: actions/upload-release-asset@v1
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
with:
84+
upload_url: ${{ steps.create_release.outputs.upload_url }}
85+
asset_path: ./styles.css
86+
asset_name: styles.css
87+
asset_content_type: text/css

README.md

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,86 @@
1-
# Obsidian Sample Plugin
1+
# Obsidian JS Engine Plugin
22

3-
This is a sample plugin for Obsidian (https://obsidian.md).
3+
This plugin for Obsidian allows you to run JavaScript from within your notes using special code blocks.
44

5-
This project uses Typescript to provide type checking and documentation.
6-
The repo depends on the latest plugin API (obsidian.d.ts) in Typescript Definition format, which contains TSDoc comments describing what it does.
5+
## Usage
76

8-
**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
7+
Start by creating a code block with the `js-engine` plugin. Inside the code block you can write any JS code and at the end return a value.
8+
The plugin will then render the returned value instead of the code block. When you return nothing, the plugin will not render anything and the code block will be invisible.
99

10-
This sample plugin demonstrates some of the basic functionality the plugin API can do.
10+
## API Docs
1111

12-
- Adds a ribbon icon, which shows a Notice when clicked.
13-
- Adds a command "Open Sample Modal" which opens a Modal.
14-
- Adds a plugin setting tab to the settings page.
15-
- Registers a global click event and output 'click' to the console.
16-
- Registers a global interval which logs 'setInterval' to the console.
12+
The following variables are available in the code blocks.
1713

18-
## First time developing plugins?
14+
| Name | Type |
15+
|-----------|-------------------------------------------------|
16+
| app | `App` (Obsidian) |
17+
| engine | `API` (this plugin) |
18+
| context | `ExecutionContext` (this plugin) or `undefined` |
19+
| component | `Component` (Obsidian) |
20+
| container | `HTMLElement` |
1921

20-
Quick starting guide for new plugin devs:
22+
Documentation for the API and types that are available inside the code block can be found [here](https://mprojectscode.github.io/obsidian-js-engine-plugin/classes/API.API.html).
2123

22-
- Check if [someone already developed a plugin for what you want](https://obsidian.md/plugins)! There might be an existing plugin similar enough that you can partner up with.
23-
- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
24-
- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
25-
- Install NodeJS, then run `npm i` in the command line under your repo folder.
26-
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
27-
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
28-
- Reload Obsidian to load the new version of your plugin.
29-
- Enable plugin in settings window.
30-
- For updates to the Obsidian API run `npm update` in the command line under your repo folder.
24+
## Examples
3125

32-
## Releasing new releases
26+
### Markdown Builder
3327

34-
- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
35-
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
36-
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases
37-
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.
38-
- Publish the release.
28+
```js
29+
let markdownBuilder = engine.markdown.createBuilder()
3930

40-
> You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`.
41-
> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json`
31+
markdownBuilder.createHeading(2, "Test Heading")
32+
markdownBuilder.createParagraph("This is a test paragraph.")
4233

43-
## Adding your plugin to the community plugin list
34+
markdownBuilder.createHeading(3, "This is a sub heading")
35+
markdownBuilder.createHeading(4, "This is a sub sub heading")
36+
markdownBuilder.createParagraph("This is another test paragraph.")
37+
```
4438

45-
- Check https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md
46-
- Publish an initial version.
47-
- Make sure you have a `README.md` file in the root of your repo.
48-
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
39+
#### Output
4940

50-
## How to use
41+
> ## Test Heading
42+
> This is a test paragraph.
43+
> ### This is a sub heading
44+
> #### This is a sub sub heading
45+
> This is another test paragraph.
5146
52-
- Clone this repo.
53-
- `npm i` or `yarn` to install dependencies
54-
- `npm run dev` to start compilation in watch mode.
47+
### Rendering Strings as Markdown
5548

56-
## Manually installing the plugin
49+
```js
50+
let str = "*test*";
51+
return str;
52+
```
5753

58-
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
54+
```js
55+
let str = "*test*";
56+
return engine.markdown.create(str);
57+
```
5958

60-
## Improve code quality with eslint (optional)
59+
The top example renders the string as plain text and the second one renders the text as markdown.
6160

62-
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
63-
- To use eslint with this project, make sure to install eslint from terminal:
64-
- `npm install -g eslint`
65-
- To use eslint to analyze this project use this command:
66-
- `eslint main.ts`
67-
- eslint will then create a report with suggestions for code improvement by file and line number.
68-
- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder:
69-
- `eslint .\src\`
61+
#### Output
7062

71-
## Funding URL
63+
> \*test\*
7264
73-
You can include funding URLs where people who use your plugin can financially support it.
65+
> *test*
7466
75-
The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file:
67+
### Importing JS
7668

77-
```json
78-
{
79-
"fundingUrl": "https://buymeacoffee.com"
80-
}
69+
```js
70+
let lib = await engine.importJs("lib.js");
71+
return lib.getGreeting();
8172
```
8273

83-
If you have multiple URLs, you can also do:
74+
With a file named `lib.js` in the root of the vault.
8475

85-
```json
86-
{
87-
"fundingUrl": {
88-
"Buy Me a Coffee": "https://buymeacoffee.com",
89-
"GitHub Sponsor": "https://github.com/sponsors",
90-
"Patreon": "https://www.patreon.com/"
91-
}
76+
```js
77+
export function getGreeting() {
78+
return "Hello!";
9279
}
9380
```
9481

95-
## API Documentation
82+
#### Output
83+
84+
> Hello!
85+
9686

97-
See https://github.com/obsidianmd/obsidian-api

docs/assets/highlight.css

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
:root {
2-
--light-hl-0: #000000;
3-
--dark-hl-0: #D4D4D4;
4-
--light-hl-1: #0451A5;
5-
--dark-hl-1: #9CDCFE;
6-
--light-hl-2: #A31515;
7-
--dark-hl-2: #CE9178;
2+
--light-hl-0: #0000FF;
3+
--dark-hl-0: #569CD6;
4+
--light-hl-1: #000000;
5+
--dark-hl-1: #D4D4D4;
6+
--light-hl-2: #001080;
7+
--dark-hl-2: #9CDCFE;
8+
--light-hl-3: #795E26;
9+
--dark-hl-3: #DCDCAA;
10+
--light-hl-4: #098658;
11+
--dark-hl-4: #B5CEA8;
12+
--light-hl-5: #A31515;
13+
--dark-hl-5: #CE9178;
14+
--light-hl-6: #AF00DB;
15+
--dark-hl-6: #C586C0;
816
--light-code-background: #FFFFFF;
917
--dark-code-background: #1E1E1E;
1018
}
@@ -13,31 +21,51 @@
1321
--hl-0: var(--light-hl-0);
1422
--hl-1: var(--light-hl-1);
1523
--hl-2: var(--light-hl-2);
24+
--hl-3: var(--light-hl-3);
25+
--hl-4: var(--light-hl-4);
26+
--hl-5: var(--light-hl-5);
27+
--hl-6: var(--light-hl-6);
1628
--code-background: var(--light-code-background);
1729
} }
1830

1931
@media (prefers-color-scheme: dark) { :root {
2032
--hl-0: var(--dark-hl-0);
2133
--hl-1: var(--dark-hl-1);
2234
--hl-2: var(--dark-hl-2);
35+
--hl-3: var(--dark-hl-3);
36+
--hl-4: var(--dark-hl-4);
37+
--hl-5: var(--dark-hl-5);
38+
--hl-6: var(--dark-hl-6);
2339
--code-background: var(--dark-code-background);
2440
} }
2541

2642
:root[data-theme='light'] {
2743
--hl-0: var(--light-hl-0);
2844
--hl-1: var(--light-hl-1);
2945
--hl-2: var(--light-hl-2);
46+
--hl-3: var(--light-hl-3);
47+
--hl-4: var(--light-hl-4);
48+
--hl-5: var(--light-hl-5);
49+
--hl-6: var(--light-hl-6);
3050
--code-background: var(--light-code-background);
3151
}
3252

3353
:root[data-theme='dark'] {
3454
--hl-0: var(--dark-hl-0);
3555
--hl-1: var(--dark-hl-1);
3656
--hl-2: var(--dark-hl-2);
57+
--hl-3: var(--dark-hl-3);
58+
--hl-4: var(--dark-hl-4);
59+
--hl-5: var(--dark-hl-5);
60+
--hl-6: var(--dark-hl-6);
3761
--code-background: var(--dark-code-background);
3862
}
3963

4064
.hl-0 { color: var(--hl-0); }
4165
.hl-1 { color: var(--hl-1); }
4266
.hl-2 { color: var(--hl-2); }
67+
.hl-3 { color: var(--hl-3); }
68+
.hl-4 { color: var(--hl-4); }
69+
.hl-5 { color: var(--hl-5); }
70+
.hl-6 { color: var(--hl-6); }
4371
pre, code { background: var(--code-background); }

0 commit comments

Comments
 (0)