It adds a new block type, freeform, in which you can add any JavaScript, including JavaScript that imports ES modules from sites like esm.sh, so you can import modules like Observable Plot and make inline charts in your notes.
It tries to bring a tiny bit of the flavor of Observable to Obsidian (disclosure: I worked there). Probably most useful to folks who are very comfortable with JavaScript.
Since no one seems to have responded to this, I’ll add that I think this is a brilliant plugin and opens up many interesting possibilities for Obsidian. Your examples of plotting, parsing Markdown, and integrating with dataview are super-helpful. A few questions/suggestions…
Can there be an option to not display the code in the “result”? Maybe ```freeform-no-code … or something like that?
I can imagine having several freeform blocks with same functions. To avoid copy and paste, is it possible to load a script file with common functions/code? I think dataview has some mechanism to do this - will try to look.
Is it possible to import from the obsidian API? Like to access normalizedPath? I think this is not possible, but maybe there’s a way.
freeform will be a great way to do things without the overhead of writing a full plugin. Again, thanks for this and the helpful examples!!
For a long time I’ve wanted to do this with dataview queries (mostly DQL), in my reference/help notes for using Dataview. Is there a way to apply your plugin to achieve this?
Not sure what you mean @ShaneNZ, but the blog post @tmcw refers to in the top message of this thread has an example of accessing Dataview. I’ve tried it myself to plot some data in my notes and it worked nicely.
Sorry, on a re-read I realise I wasn’t clear about what I’m trying to achieve. I have a few reference files full of useful DQL queries, things like this:
```dataview
TABLE file.etags
WHERE any(econtains(file.etags, ["#theme","#type"]))
```
What I’d love is for that query to be visible underneath the dataview output from that query, so I can see both at once. And while I’m wishing for ponies here, it’d be really great to be able to edit the query with the output live updating ) In essence, I want this to work:
I know freeform wont directly support and work like that, but I’m wondering if there is a way (maybe with some Javascript wrapped around the query) to get it working.
PS in writing this post, I’m realising what I really want is this:
```dataview-preview
TABLE file.etags
WHERE any(econtains(file.etags, ["#theme","#type"]))
```
Think I’ll put a feature request into Dataview/Datacore…
Here’s a way to do what you want… This freeform script will run a query, get the Markdown result, and inject it back into the note (there is no easy way that I can find to render Obsidian Markdown in the Freeform result iframe).
Above the Freeform code block, you need to have a line that says “DataView result:” . Everything between that and the freeform code block will be replaced by the rendered query result.
```freeform
// Test query is below (can do multi-line)
const q = `
TABLE file.mtime, file.name
FROM "Misc"
`;
// Run the query and get markdown results
const result = await window.top.app.plugins.plugins.dataview.api.queryMarkdown(q);
// Add the results below the freeform code block
// Get the markdown for this note
let md = window.top.app.workspace.activeEditor?.editor.getDoc().getValue();
// Find the "DataView result:\n" text and the start of the code block
const sm = "DataView result:\n"
const em = "```"
const s = md.indexOf(sm) + sm.length
const e = md.indexOf(em)
// Inject the query result into the note between "DataView result:" and the freeform code block
md = md.substring(0, s) + "\n" + result.value + "\n" + md.substring(e, md.length);
// Store the note
window.top.app.workspace.activeEditor?.editor.getDoc().setValue(md);
```