Giter VIP home page Giter VIP logo

obsidian-run's Introduction

Obsidian Run

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

Installation

Plugin marketplace

You can download this from obsidian plugin store.

Manual Installation

  1. cd to .obsidian/plugins
  2. git clone this repo
  3. cd obsidian-run && bun install && bun run build
  4. there you go 🎉

Usage

  1. install this plugin and install obsidian-custom-save
  2. add the run: run file command to the custom save actions
  3. define a starting tag
%% run start 3+4%%
  1. save the file
  2. you markdown will become something like this
%% run start
3+4
%%
7
%% run end %%

Syntax

Each block of run contains three parts: starting tag (required), generated content, ending tag

starting tag (required)

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.

Content

the generated content

Ending Tag

ending tag closes the run block.

%% run end <metadata> %%

Options

  1. generate ending tag metadata: when enabled, the run block update time and error(if any) will be shown in the ending tag.
  2. ignore folders: the folder listed will be ignored by this plugin

Advanced Usage

Access file object

%% run start file.basename %%

the file object is the TFile but it is patched with file.properties which is the file yaml properties.

Page level variable

---
bar: "foo"
---

%% run start file.properties.bar %%

Dataview

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));
```

%%

Templater and Reusable user scripts

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, the tp 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.

Function

you can write complicated function in starting tag codeblock

Async Function

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.

Debug

you can use console.log in the starting tag codeblock. It will output in the developer tool.

Note

  1. if you want to contribute, please star and open github issue.
  2. 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
  3. you will want to use this with CodeblockCustomizer to collapse your code block.
  4. you will want to save the following codeblock as template so that you can use it easily.
%% run start

```ts fold
return;
```

%%

Support

If you are enjoying this plugin then please support my work and enthusiasm by buying me a coffee on https://www.buymeacoffee.com/yomaru.

Buy Me A Coffee

obsidian-run's People

Contributors

aidenlx avatar chrisgrieser avatar clemens-e avatar edo78 avatar ericaxu avatar fyears avatar gitmurf avatar hananoshikayomaru avatar henrebotha avatar inouetakuya avatar joethei avatar kostapc avatar lishid avatar phibr0 avatar pozdneev avatar reorx avatar taurelas avatar tfthacker avatar timrogers avatar tokuhirom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

icehongssii

obsidian-run's Issues

Clarifying Question: Does this support DQL?

(This is not a Feature Request, so much as just a clarifying question.)

I understand that the plugin supports the dv object from Dataview.

Does obsidian-run support DQL, the Dataview Query Language?

For example does it support inline syntax:

`= this.file.name`

Or query syntax:

LIST 
FROM "My Folder"

If not would it be possible to add support for this to obsidian-run?
Do you know if the dv object allows you to run DQL queries?

inline run block

Is your feature request related to a problem? Please describe.

this is my %%= 3%% note

Describe the solution you'd like

  1. inline expression only work on simple javascript expression but not multiple statements
  2. if user really multiple lines statement, they can use the user defined script with templater

Feature Request: Allow variables defined in one "run block" to be used in all subsequent "run blocks" -- page-level scoping

See start of the discussion in #6.

I would like to be able to define the following -- simple example:

%% start run 01

~~~js
const modal = app.plugins.plugins.modalforms.api
const obs = await self.require.import("[[user.script.obsidian.delay-until-synced.mjs]]")
const timer = 1000
~~~

%%

and to re-use the variables in a following run block:

%% start run 02

~~~js
obs.delayUntilSynced(timer, () => {
    const data = modal.openForm("test-form")
    console.log(data)
}, {omit: ["name"]})

%%

The idea is to consolidate all variable declarations in one place for easier management.

Furthermore, if I would have to call the openForm modal function in another run block, I currently have to re-declare the access to the API -- an additional step I would like to avoid.

The icing on the cake would be that any run block could use any page-level (scoped) variables wherever they are declared.

BRAT does not recognise and install the update(s)

Describe the bug

I am still on version 1.0.1 and am trying to update to 1.0.3 via BRAT -- does not recognise the latest update(s).

To Reproduce

Run the BRAT: Plugins: Check for updates for all beta plugins and UPDATE or BRAT: Plugins: Choose a single version to update command.

See the info message: BRAT No update available for HananoshikaYomaru/obsidian-run, when running the single version update command.

Expected behavior

Brat to install the latest update.

Additional context

SYSTEM INFO:

Obsidian version: v1.4.14
Installer version: v1.4.14
Operating system: Windows 11 Home Single Language 10.0.22621
Login status: logged in
Catalyst license: supporter
Insider build toggle: on
Live preview: on
Legacy editor: off
Base theme: light
Community theme: Minimal v7.2.3
Snippets enabled: 33
Restricted mode: off
Plugins installed: 49
Plugins enabled: 43

[YOM-596] support generation inside callout or blockquote

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

YOM-596

support HTML comment syntax

Is your feature request related to a problem? Please describe.
support <!-- -->

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

[YOM-581] async run doesn't replace the text when there is space

Describe the bug
when there are space between run start and codeblock, async function doesn't work.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots

image

Additional context
what is your OS? did you try to narrow the scope of issue? Any other context?

From SyncLinear.com | YOM-581

Await is only valid in async functions and the top level bodies of modules

Describe the bug

Async function calls are not possible in the run start block.

To Reproduce

I am trying to run the following code:

%% run start 0

```js
const {reverse} = await self.require.import("[[user.script.fp.reverse.mjs]]")

const a = [1, 2, 3]
const b = reverse(a)

return `a = ${a}\nb = ${b}`
```

%%

Run generates the following end tag metadata:

%% run end

error: await is only valid in async functions and the top level bodies of modules

%%

Expected behavior

The output should be:

a = 1,2,3
b = 3,2,1

The following Templater snippet works as expected:

<%*
const {reverse} = await self.require.import("[[user.script.fp.reverse.mjs]]")

const a = [1, 2, 3]
const b = reverse(a)

tR += `a = ${a}\nb = ${b}`
_%>

Additional context

SYSTEM INFO:

Obsidian version: v1.4.14
Installer version: v1.4.14
Operating system: Windows 11 Home Single Language 10.0.22621
Login status: logged in
Catalyst license: supporter
Insider build toggle: on
Live preview: on
Legacy editor: off
Base theme: light
Community theme: Minimal v7.2.3
Snippets enabled: 33
Restricted mode: off
Plugins installed: 49
Plugins enabled: 43

Does not support comments in codeblock

Describe the bug
Adding a comment to codeblock results in the error shown below in screenshot.

Expected behavior
A comment should have no additional effect as expected

Screenshots
If applicable, add screenshots to help explain your problem.
image

Feature Request: Allow folding the "block run" starting tag.

The UX can be enhanced further if one could fold the block run starting tag %% run start <id> <expression> ... %%.

The visual result would be:

%% run start <id>
Output
%% run end %%

That looks much neater in edit and source mode, i.e., it would be less disruptive while writing a note.

Look at how the Fold Anywhere plugin does it: https://github.com/Quorafind/Obsidian-Fold-Anywhere.

By the way: there are compatibility issues of Run with Fold Anywhere you might want to look into. 😉

directly evulate dataview query

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

[YOM-579] periodic update of some notes

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

YOM-579

Feature Request: Remove notification if there are no run blocks to execute.

A notification is displayed on every save, even if there are no run blocks to execute. This can be annoying.

The UX can be enhanced if the notification level can be set -- options:

  • No notification at all. Just execute the run blocks. The user can use console.log to check for any diagnostics.
  • Notify the user if there are any errors.
  • Always notify the user -- this is the current approach of the plugin.

Keep up the good work!

Help needed: I dont understand how to run this plugin

My steps:

  • Download obsidian run plugin
  • Download obsidian custom save plugin
  • Add "run: run file" command to custom save plugin
  • Created a new md file in vault
  • Added a dataview code like following

`
%% run start

dv.list from "" where file.cday = date("<%tp.date.now(\"YYYY-MM-DD\")%>") sort file.ctime asc

%%
`

At this point I have no idea what to do next to get a markdown/text from the dataview query. Can someone please help me?

add donate to plugin 🥲

Is your feature request related to a problem? Please describe.

CleanShot 2023-10-05 at 00 49 54@2x

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.