Skip to content

Commit bc0639b

Browse files
committed
markdown builder and import API
1 parent a96efd8 commit bc0639b

22 files changed

+1521
-1308
lines changed

README.md

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,65 @@ The repo depends on the latest plugin API (obsidian.d.ts) in Typescript Definiti
88
**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
99

1010
This sample plugin demonstrates some of the basic functionality the plugin API can do.
11-
- Adds a ribbon icon, which shows a Notice when clicked.
12-
- Adds a command "Open Sample Modal" which opens a Modal.
13-
- Adds a plugin setting tab to the settings page.
14-
- Registers a global click event and output 'click' to the console.
15-
- Registers a global interval which logs 'setInterval' to the console.
11+
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.
1617

1718
## First time developing plugins?
1819

1920
Quick starting guide for new plugin devs:
2021

21-
- 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.
22-
- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
23-
- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
24-
- Install NodeJS, then run `npm i` in the command line under your repo folder.
25-
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
26-
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
27-
- Reload Obsidian to load the new version of your plugin.
28-
- Enable plugin in settings window.
29-
- For updates to the Obsidian API run `npm update` in the command line under your repo folder.
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.
3031

3132
## Releasing new releases
3233

33-
- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
34-
- 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.
35-
- 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
36-
- 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.
37-
- Publish the release.
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.
3839

3940
> 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`.
4041
> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json`
4142
4243
## Adding your plugin to the community plugin list
4344

44-
- Check https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md
45-
- Publish an initial version.
46-
- Make sure you have a `README.md` file in the root of your repo.
47-
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
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.
4849

4950
## How to use
5051

51-
- Clone this repo.
52-
- `npm i` or `yarn` to install dependencies
53-
- `npm run dev` to start compilation in watch mode.
52+
- Clone this repo.
53+
- `npm i` or `yarn` to install dependencies
54+
- `npm run dev` to start compilation in watch mode.
5455

5556
## Manually installing the plugin
5657

57-
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
58+
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
5859

5960
## Improve code quality with eslint (optional)
60-
- [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.
61-
- To use eslint with this project, make sure to install eslint from terminal:
62-
- `npm install -g eslint`
63-
- To use eslint to analyze this project use this command:
64-
- `eslint main.ts`
65-
- eslint will then create a report with suggestions for code improvement by file and line number.
66-
- 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:
67-
- `eslint .\src\`
61+
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\`
6870

6971
## Funding URL
7072

@@ -74,19 +76,19 @@ The simple way is to set the `fundingUrl` field to your link in your `manifest.j
7476

7577
```json
7678
{
77-
"fundingUrl": "https://buymeacoffee.com"
79+
"fundingUrl": "https://buymeacoffee.com"
7880
}
7981
```
8082

8183
If you have multiple URLs, you can also do:
8284

8385
```json
8486
{
85-
"fundingUrl": {
86-
"Buy Me a Coffee": "https://buymeacoffee.com",
87-
"GitHub Sponsor": "https://github.com/sponsors",
88-
"Patreon": "https://www.patreon.com/"
89-
}
87+
"fundingUrl": {
88+
"Buy Me a Coffee": "https://buymeacoffee.com",
89+
"GitHub Sponsor": "https://github.com/sponsors",
90+
"Patreon": "https://www.patreon.com/"
91+
}
9092
}
9193
```
9294

esbuild.config.mjs

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,49 @@ if you want to view the source, please visit the github repository of this plugi
1010
*/
1111
`;
1212

13-
const prod = process.argv[2] === 'production';
14-
15-
esbuild
16-
.build({
17-
banner: {
18-
js: banner,
19-
},
20-
entryPoints: ['src/main.ts'],
21-
bundle: true,
22-
external: [
23-
'obsidian',
24-
'electron',
25-
'@codemirror/autocomplete',
26-
'@codemirror/closebrackets',
27-
'@codemirror/collab',
28-
'@codemirror/commands',
29-
'@codemirror/comment',
30-
'@codemirror/fold',
31-
'@codemirror/gutter',
32-
'@codemirror/highlight',
33-
'@codemirror/history',
34-
'@codemirror/language',
35-
'@codemirror/lint',
36-
'@codemirror/matchbrackets',
37-
'@codemirror/panel',
38-
'@codemirror/rangeset',
39-
'@codemirror/rectangular-selection',
40-
'@codemirror/search',
41-
'@codemirror/state',
42-
'@codemirror/stream-parser',
43-
'@codemirror/text',
44-
'@codemirror/tooltip',
45-
'@codemirror/view',
46-
...builtins,
47-
],
48-
format: 'cjs',
49-
watch: !prod,
50-
target: 'es2018',
51-
logLevel: 'info',
52-
sourcemap: prod ? false : 'inline',
53-
treeShaking: true,
54-
outfile: 'main.js',
55-
minify: true,
56-
plugins: [
57-
esbuildSvelte({
58-
compilerOptions: { css: true },
59-
preprocess: sveltePreprocess(),
60-
}),
61-
],
62-
})
63-
.catch(() => process.exit(1));
13+
await esbuild.build({
14+
banner: {
15+
js: banner,
16+
},
17+
entryPoints: ['src/main.ts'],
18+
bundle: true,
19+
external: [
20+
'obsidian',
21+
'electron',
22+
'@codemirror/autocomplete',
23+
'@codemirror/closebrackets',
24+
'@codemirror/collab',
25+
'@codemirror/commands',
26+
'@codemirror/comment',
27+
'@codemirror/fold',
28+
'@codemirror/gutter',
29+
'@codemirror/highlight',
30+
'@codemirror/history',
31+
'@codemirror/language',
32+
'@codemirror/lint',
33+
'@codemirror/matchbrackets',
34+
'@codemirror/panel',
35+
'@codemirror/rangeset',
36+
'@codemirror/rectangular-selection',
37+
'@codemirror/search',
38+
'@codemirror/state',
39+
'@codemirror/stream-parser',
40+
'@codemirror/text',
41+
'@codemirror/tooltip',
42+
'@codemirror/view',
43+
...builtins,
44+
],
45+
format: 'cjs',
46+
target: 'es2018',
47+
logLevel: 'info',
48+
sourcemap: false,
49+
treeShaking: true,
50+
outfile: 'main.js',
51+
minify: true,
52+
plugins: [
53+
esbuildSvelte({
54+
compilerOptions: { css: true },
55+
preprocess: sveltePreprocess(),
56+
}),
57+
],
58+
});

esbuild.dev.config.mjs

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,61 @@ if you want to view the source, please visit the github repository of this plugi
1111
*/
1212
`;
1313

14-
const prod = process.argv[2] === 'production';
14+
const context = await esbuild.context({
15+
banner: {
16+
js: banner,
17+
},
18+
entryPoints: ['src/main.ts'],
19+
bundle: true,
20+
external: [
21+
'obsidian',
22+
'electron',
23+
'@codemirror/autocomplete',
24+
'@codemirror/closebrackets',
25+
'@codemirror/collab',
26+
'@codemirror/commands',
27+
'@codemirror/comment',
28+
'@codemirror/fold',
29+
'@codemirror/gutter',
30+
'@codemirror/highlight',
31+
'@codemirror/history',
32+
'@codemirror/language',
33+
'@codemirror/lint',
34+
'@codemirror/matchbrackets',
35+
'@codemirror/panel',
36+
'@codemirror/rangeset',
37+
'@codemirror/rectangular-selection',
38+
'@codemirror/search',
39+
'@codemirror/state',
40+
'@codemirror/stream-parser',
41+
'@codemirror/text',
42+
'@codemirror/tooltip',
43+
'@codemirror/view',
44+
...builtins,
45+
],
46+
format: 'cjs',
47+
target: 'es2018',
48+
logLevel: 'info',
49+
sourcemap: 'inline',
50+
treeShaking: true,
51+
outdir: 'exampleVault/.obsidian/plugins/obsidian-js-engine-plugin/',
52+
outbase: 'src',
53+
plugins: [
54+
copy([
55+
{
56+
from: './styles.css',
57+
to: '',
58+
},
59+
{
60+
from: './manifest.json',
61+
to: '',
62+
},
63+
]),
64+
esbuildSvelte({
65+
compilerOptions: { css: true },
66+
preprocess: sveltePreprocess(),
67+
}),
68+
],
69+
});
1570

16-
esbuild
17-
.build({
18-
banner: {
19-
js: banner,
20-
},
21-
entryPoints: ['src/main.ts'],
22-
bundle: true,
23-
external: [
24-
'obsidian',
25-
'electron',
26-
'@codemirror/autocomplete',
27-
'@codemirror/closebrackets',
28-
'@codemirror/collab',
29-
'@codemirror/commands',
30-
'@codemirror/comment',
31-
'@codemirror/fold',
32-
'@codemirror/gutter',
33-
'@codemirror/highlight',
34-
'@codemirror/history',
35-
'@codemirror/language',
36-
'@codemirror/lint',
37-
'@codemirror/matchbrackets',
38-
'@codemirror/panel',
39-
'@codemirror/rangeset',
40-
'@codemirror/rectangular-selection',
41-
'@codemirror/search',
42-
'@codemirror/state',
43-
'@codemirror/stream-parser',
44-
'@codemirror/text',
45-
'@codemirror/tooltip',
46-
'@codemirror/view',
47-
...builtins,
48-
],
49-
format: 'cjs',
50-
watch: !prod,
51-
target: 'es2016',
52-
logLevel: 'info',
53-
sourcemap: prod ? false : 'inline',
54-
treeShaking: true,
55-
outdir: 'exampleVault/.obsidian/plugins/obsidian-js-engine-plugin/',
56-
outbase: 'src',
57-
plugins: [
58-
copy([
59-
{
60-
from: './styles.css',
61-
to: '',
62-
},
63-
{
64-
from: './manifest.json',
65-
to: '',
66-
},
67-
]),
68-
esbuildSvelte({
69-
compilerOptions: { css: true },
70-
preprocess: sveltePreprocess(),
71-
})
72-
],
73-
})
74-
.catch(() => process.exit(1));
71+
await context.watch();

exampleVault/Test.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,23 @@ let blockquote = callout.createBlockQuote()
2929
blockquote.createHeading(5, "This is a block quote")
3030
blockquote.createParagraph("This is another test paragraph.")
3131
32+
callout.createTable(["Column 1", "Column 2"], [
33+
["data 1", "**data 2**"],
34+
["data 3", "data 4"],
35+
]);
36+
3237
return markdownBuilder
3338
```
3439

40+
# Import Test
41+
42+
```js-engine
43+
let lib = await engine.importJs("lib.js");
44+
return lib.getGreeting();
45+
```
46+
47+
# Async Tewst
3548

49+
```js-engine
50+
return await engine.test()
51+
```

exampleVault/lib.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getGreeting() {
2+
return "Hello!";
3+
}

0 commit comments

Comments
 (0)