Generate markdown from dataview query and javascript.
- ✅ Powerful, Dead Simple
- ✅ Markdown based, work with every markdown editor / render
- ✅ Works well with Dataview, Templater, Obsidian publish
demo: https://www.youtube.com/watch?v=_UAr6e6hlVI&t=71s
You can download this from obsidian plugin store.
- cd to
.obsidian/plugins
- git clone this repo
cd obsidian-run && bun install && bun run build
- there you go 🎉
- install this plugin and install obsidian-custom-save
- add the
run: run file
command to the custom save actions - define a starting tag
%% run start 3+4%%
- save the file
- you markdown will become something like this
%% run start
3+4
%%
7
%% run end %%
Each block of run contains three parts: starting tag (required), generated content, ending tag
you define your expression in the starting tag. The expression will be used to calculate the content. It is the only required part for a run block.
%% run start <expression> %%
or you can also write multiple line statements. Notice that if you write in multiple line you must return a value.
%% run start
```ts|js
<your expression in codeblock>
```
%%
You can use it with CodeblockCustomizer, to have folding codeblock.
the generated content
ending tag closes the run block.
%% run end <metadata> %%
- generate ending tag metadata: when enabled, the run block update time and error(if any) will be shown in the ending tag.
- ignore folders: the folder listed will be ignored by this plugin
%% run start file.basename %%
the file object is the TFile but it is patched with file.properties
which is the file yaml properties.
---
bar: "foo"
---
%% run start file.properties.bar %%
you can access the dv
object if you have dataview plugin installed and enabled.
%% run start
```ts
return dv.markdownList(dv.pages("#ai/image").map((page) => page.file.link));
```
%%
you can access the tp
object if you have templater plugin installed and enabled.
Then you need to go to the setting of template and manually set a startup template. The reason of doing this is that
tp
is not initialized by default by templater and it will be undefined. Learn more and see a video: #14 (comment). If you don't want to set a start up template, you can manually run templater once everytime you start up obsidian. As long as templater runs once, thetp
object will be defined.
Templater allows user to have their user defined functions and scripts. To learn more, checkout https://silentvoid13.github.io/Templater/user-functions/script-user-functions.html.
you can write complicated function in starting tag codeblock
You can do any kind of async operation in the run block. Async function is non-blocking. Results will be resolved after all sync operation are resolved. You can use the obsidian request function to fetch data.
you can use console.log
in the starting tag codeblock. It will output in the developer tool.
- if you want to contribute, please star and open github issue.
- this plugin is powerful, but it is still under early development. The syntax is subject to change but will be backward compatible as much as possible
- you will want to use this with CodeblockCustomizer to collapse your code block.
- you will want to save the following codeblock as template so that you can use it easily.
%% run start
```ts fold
return;
```
%%
If you are enjoying this plugin then please support my work and enthusiasm by buying me a coffee on https://www.buymeacoffee.com/yomaru.