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