I wrote a little script to write dataview results into documents

const vault = this.app.vault
const file = this.app.workspace.getActiveFile()

const target = input.target
const msg = input.msg
const tokenStartMultilineInsert = input.tokenStartMultilineInsert || "INSERT"
const tokenEndMultilineInsert = input.tokenEndMultilineInsert || "END"
const exprMultiline = RegExp(`(%%).*?(${tokenStartMultilineInsert} ${target}).*?(%%)[^]*?(%%).*?(${tokenEndMultilineInsert} ${target}).*?(%%)`, "gm")

//unused as of now, couldnt make it not break things
//const tokenStartInlineInsert = input.tokenStartInlineInsert || "INLINE"
//const exprInline = RegExp(`(%%).*?(${tokenStartInlineInsert} ${target}).*?(%%).*`, "gm")

await vault.process(file, (data) => {
    //clear whatever is between the ml tokens
    data = data.replace(exprMultiline, `%% ${tokenStartMultilineInsert} ${target} %%\n%% ${tokenEndMultilineInsert} ${target} %%`)
    //fill in our target text
    data = data.replace(exprMultiline, `%% ${tokenStartMultilineInsert} ${target} %%\n${msg}%% ${tokenEndMultilineInsert} ${target} %%`)
    return data

useable in dataview and documents as such:

await dv.view("Scripts/dv_insert", { target: "A", msg: toRender})
%% INSERT A %%
%% END A %%

Not sure if theres any significant drawbacks to this method but its dead simple, stupid and seems to work fine for me, for now.


This broke for me today and ive got no idea why. If it infinitely pastes content for you too ive got no idea how to fix it

What about turning off auto-refresh in the Dataview plugin settings?

Automatic View Refreshing
If enabled, views will automatically refresh when files in your vault change; this can negatively affect some functionality like embeds in views, so turn it off if such functionality is not working.

Iā€™m going to write a Button switch to manipulate whether to write or not.