Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
beaussan opened this issue May 2, 2021 · 20 comments
Open

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

beaussan opened this issue May 2, 2021 · 20 comments

Comments

@beaussan
Copy link

@beaussan beaussan commented May 2, 2021

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.

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented May 7, 2021

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

@nickynicolson
Copy link

@nickynicolson nickynicolson commented Aug 25, 2021

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

@davidlee321
Copy link

@davidlee321 davidlee321 commented Sep 12, 2021

+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)

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Sep 13, 2021

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.

@davidlee321
Copy link

@davidlee321 davidlee321 commented Sep 15, 2021

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.

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Sep 17, 2021

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.

@davidleejy
Copy link

@davidleejy davidleejy commented Sep 24, 2021

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?

@charleshan
Copy link

@charleshan charleshan commented Nov 18, 2021

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)

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Nov 18, 2021

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

@miguelsm
Copy link

@miguelsm miguelsm commented Dec 13, 2021

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

@dcalacci
Copy link

@dcalacci dcalacci commented Dec 17, 2021

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.

@chishaku
Copy link

@chishaku chishaku commented Dec 20, 2021

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

@chishaku
Copy link

@chishaku chishaku commented Dec 20, 2021

@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!

@charleshan
Copy link

@charleshan charleshan commented Dec 24, 2021

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
Copy link

@charleshan charleshan commented Jan 6, 2022

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

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Jan 6, 2022

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

@OliverFarren
Copy link

@OliverFarren OliverFarren commented Jan 9, 2022

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.

@kenfinnigan
Copy link

@kenfinnigan kenfinnigan commented Jan 14, 2022

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

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Jan 18, 2022

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
Copy link
Owner

@blacksmithgu blacksmithgu commented Jan 18, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet