obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Is is possible to embed the files in the list view ?

Open beaussan opened this issue 3 years ago • 22 comments

In the List view, I would love to be able to embed the file directly, could this be done ?

I tried with the list view, with concatenation, but it didn't work.

beaussan avatar May 02 '21 21:05 beaussan

Added to my backlog of things to do - embed support is almost in, it just looks ugly right now.

blacksmithgu avatar May 07 '21 20:05 blacksmithgu

I have a similar request regarding building an embed link for blocks: I have a vault with named blocks (eg for project status) and currently build an overview table which transcludes content using embed link syntax (the ! prefix - as described here https://help.obsidian.md/How+to/Link+to+blocks) Dataview would make this much simpler if I could generate an embed link - currently I can build a block link but the content is only shown on hover. As per @beaussan - I have tried building the embed syntax link using concatenation but it isn't recognised

nickynicolson avatar Aug 25 '21 11:08 nickynicolson

+1 for embed support. I'm currently trying to do something like:

var pages = dv.pages().filter(page => page.file.name.includes('eg '))
var pages = pages.sort(page => page.file.mtime, 'desc')
let embeds = pages.file.name.map( name => '![[' + name + ']]')
dv.list(embeds)

davidlee321 avatar Sep 12 '21 19:09 davidlee321

I'm limited by the Obsidian API in this case - Obsidian has no API for actually rendering embeds. I can circumvent it with a hack where I manually load the raw Markdown in some cases, though the output is a little wierd and doesn't look like a proper embed.

blacksmithgu avatar Sep 13 '21 20:09 blacksmithgu

Noticed that Obsidian renders embeds in a list that the user manually types up.

<!--- These embeds render OK --->
- ![[page_a]]
- ![[page_b]]
- ![[page_c]]

Could a possible workaround in dataview be to let users print to the page? Dataview provides dv.list(), dv.table(). Is there like a dv.print()? If so, users can use the printing function to write stuff that would render like how Obsidian intended.

<!--- Personally I would print this: --->
![[page_a]]
![[page_b]]
![[page_c]]

Forgive me if I don't understand "Obsidian has no API for actually rendering embeds". I haven't delved into Obsidian's provisions for plugin developers.

davidlee321 avatar Sep 15 '21 08:09 davidlee321

The gist of the issue is that the Obsidian plugin API provides a direct way to render markdown anywhere you want - it's called MarkdownRenderer.renderMarkdown(source, ...), and it's what Dataview uses (after some pre-processing) to render all values. This API unfortunately doesn't work for link embeds, which is why Dataview historically hasn't supported it.

As for your suggested solution, there isn't a dv.print() because Dataview does rendering via post-processing: Obsidian renders the page, and then Dataview replaces dataview code blocks with their results. Since this happens after Obsidian renders, I can't replace the Markdown with something else to render.

blacksmithgu avatar Sep 17 '21 04:09 blacksmithgu

I can circumvent it with a hack where I manually load the raw Markdown in some cases, though the output is a little wierd and doesn't look like a proper embed.

This is something I think I could try. Would anyone be familiar with some way of doing this?

Also, I was just mulling about this the other day (again forgive me if this idea is crap): since what users see in each page (Preview mode) is javascript, is there some way to copy the javascript from other pages (preview mode) and plonk them into where embeds are to be rendered?

davidleejy avatar Sep 24 '21 08:09 davidleejy

I was able to get the embeds to work. I manually parsed the links as a string with line breaks instead of using dv.list

let text = '';
for(let i = 0; i < dvLinks.length; i++) {
	text = text + '!' + dvLinks[i] + '\n\n';
}
dv.paragraph(text)

charleshan avatar Nov 18 '21 02:11 charleshan

That's... interesting. I need to experiment with this more...

blacksmithgu avatar Nov 18 '21 04:11 blacksmithgu

I'm using fileLink's second parameter to embed the file contents:

dv.pages("#some-tag").forEach(p => dv.paragraph(dv.fileLink(p.file.name, true)))

Update: This is tested to be working as of Obsidian v0.13.19

miguelsm avatar Dec 13 '21 15:12 miguelsm

This sort of works—I see it in a brief preview, but then it quickly reverts back to a simple list view, not sure why.

dcalacci avatar Dec 17 '21 18:12 dcalacci

@miguelsm @dcalacci I'm also just seeing a list of the filenames.

chishaku avatar Dec 20 '21 14:12 chishaku

@blacksmithgu is there any way to access your workaround for rendering the full markdown? on a branch or otherwise?

any help here would be appreciated!

chishaku avatar Dec 20 '21 14:12 chishaku

It looks like someone made a thread on the Obsidian forum. Our best bet is probably to raise some awareness over there.

https://forum.obsidian.md/t/obsidian-plugin-api-does-not-support-rendering-of-embeds/24617/2

charleshan avatar Dec 24 '21 01:12 charleshan

It looks like Obsidian made changes so that plugins can add embeds.

Support embeds in plugin blocks like Admonition and Dataview

https://twitter.com/obsdmd/status/1479155487111319558

charleshan avatar Jan 06 '22 18:01 charleshan

Indeed, the Obsidian API finally supports embeds. I haven't checked it if "just works" with dataview or if I need to make changes.

blacksmithgu avatar Jan 06 '22 22:01 blacksmithgu

So i've been trying this today with an image and it seems to render the image embedding for a few seconds and then just shows the filename...

Admittedly new to this plugin (which is great btw), I tried with the following for my image file with the name IMG_20220107_230609.jpg

dv.el("div", "![[IMG_20220107_230609.jpg]]")
dv.el("div", "![[IMG_20220107_230609.jpg|200]]")
dv.el("div", dv.fileLink("IMG_20220107_230609.jpg", true))
dv.el("div", dv.fileLink("IMG_20220107_230609.jpg", true, "200"))
dv.paragraph("![[IMG_20220107_230609.jpg]]")
dv.paragraph("![[IMG_20220107_230609.jpg|200]]")
dv.paragraph(dv.fileLink("IMG_20220107_230609.jpg", true))
dv.paragraph(dv.fileLink("IMG_20220107_230609.jpg", true, "200"))

None of which worked. I thought maybe the image size could be an issue so tried the 200, didn't work.

OliverFarren avatar Jan 09 '22 21:01 OliverFarren

I've used dv.el and dv.paragraph to embed with the latest Obsidian and it works for me, but only on second opening of a note.

I use the Homepage plugin to open a specific note on Obsidian start, but on load the Dataview js component shows the filename to be embedded only. Going to another note and then back again will correctly load the embedded content.

Not sure if that's an Obsidian or Dataview problem

kenfinnigan avatar Jan 14 '22 21:01 kenfinnigan

It looks like it works properly in Live Preview, but embed rendering in the traditional edit/read mode still does not work (i.e., it was never implemented in Obsidian).

blacksmithgu avatar Jan 18 '22 03:01 blacksmithgu

Hmm, the support seems a little convoluted - it works via DataviewJS live preview, though not through Dataview queries; I'm guessing you can only create embeds at the top level of the document (i.e., you cannot embed into tables or lists).

blacksmithgu avatar Jan 18 '22 03:01 blacksmithgu

Hi, forgive me for necrobumping this old thread, but has anything changed regarding this feature request?

I'm trying to create weekly and monthly roll-ups using embeds for quickly going through the stuff I've done from my daily notes, and I think this would be a very useful meta-feature that could facilitate building of dashboards and stuff from dataview

autolyticus avatar Jun 11 '22 21:06 autolyticus

Don't think it works very well in DQL or DVJS at the moment. I'll let blacksmithgu comment on the specifics. One hack around this would be to use a bit of DVJS to generate query results and then use the Obs API to write the list of files you want embedded. It seems it should work in theory.

AB1908 avatar Jul 01 '22 13:07 AB1908

Hi there, just wondering if there has been any resolution on being able to display results of a query in LIST mode as embeds rather than links? Daily Notes Viewer does something similar.

TrustTepee avatar Nov 18 '22 23:11 TrustTepee

Linking the Daily Notes Viewer plugin repo https://github.com/Johnson0907/obsidian-daily-notes-viewer

Ligerx avatar Nov 19 '22 03:11 Ligerx

After some digging, I found out that the plug in "Text Expand" does this. It looks like it's doing something similar to Dataview using Obsidian's built in search function. You can either specify a search (like in Dataview) or leave it blank if you want the plugin to use whatever search is already activated in the search pane as input. It then generates a list of the results in the note.

By typing ![[$filename]] in the default template in the plugin's settings, it will embed the results rather than present them as links. So basically what Daily Note Viewer does but for whatever search is active.

clicking any tag, either in the note, in another note, or in the tag pane and then clicking the "Run Expand Query" button will repopulate the note with embedded results. I added a #clear tag that's not use anywhere to clear the results if need be.

Not sure why Dataview can't do this.

Screen Shot 2022-11-19 at 10 25 33 AM

TrustTepee avatar Nov 19 '22 15:11 TrustTepee

Not sure why Dataview can't do this.

It's quite simple really, DV wasn't quite built to do this in the first place. No one has had the time to implement it either, sadly.

AB1908 avatar Nov 25 '22 21:11 AB1908

Bump

d0020002 avatar Jan 12 '23 09:01 d0020002

would also absolutely loooove this

JoshuaLelon avatar Jan 14 '23 17:01 JoshuaLelon

Just in case anyone's interested in embedding the results of a dataviewjs query as a list of blocks, here is the code I'm using below. It is specifically designed to work with blocks that already have block IDs. If there is no block ID in place, the link at the end of each block won't work. You can read more about the topic here: https://www.reddit.com/r/ObsidianMD/comments/10oyj3i/generating_header_and_block_links_with_dataviewjs/

const pagesWithQuotes = await Promise.all(
    dv
    .pages("[[note1]] and [[note2]]")
    .map(pageWithQuote => new Promise(async (resolve, reject) => {
        const content = await dv.io.load(pageWithQuote.file.path);
        resolve({
            name: pageWithQuote.file.name,
            content
        });
    }))
);

const quotesByPage = pagesWithQuotes.map(({
    name,
    content
}) => ({
    name,
    quotes: content
        .split('\n')
        .filter(content => content.match(/.*note1]].*note2]](\s|$)/))
        .map(content =>
          /\s*(\s|\*|\-)*\s*(?<quote>.*)$/gm.exec(content)?.groups?.quote
        )
		.map(content => content.replace(' ^', ' [[placeh0lder#^'))  
		.map(content => content.replace('placeh0lder', name))
}));

quotesByPage.forEach(
    page =>
    page.quotes.forEach(
        quote => dv.paragraph(`>>>- ${quote}]]`)
    )
);

wredmatic avatar Feb 03 '23 23:02 wredmatic

Embedding files in to a list view works fine when Automatic View Refreshing is turned off. When it's turned on and when I make a change to a file, the content from the files disappears in the list view and only the file names are left.

charleshan avatar Feb 10 '23 08:02 charleshan