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

Inline queries don't handle embedded image links

Open pstelzer opened this issue 3 years ago • 19 comments
trafficstars

What happened?

Embedded image links are handled correctly by list and table dataviews, but not by inline queries.

Obsidian_Dataview_02

DQL

---
image-embed: "![[Obsidian.png]]"
---

`= this.image-embed`

JS

No response

Dataview Version

0.5.17

Obsidian Version

0.14.6

OS

Windows

pstelzer avatar Apr 28 '22 08:04 pstelzer

This is because inline queries don't currently use react (which supports inline images) for their rendering; will see if I can get it to work.

blacksmithgu avatar Apr 29 '22 04:04 blacksmithgu

I just found out that I would need that myself 😁

Use case is I have a field with a link to a photo:

Photo:: [[pnoto.png]]

And I would like it to be displayed as an embed using inline query.

I tried the following without much success

dv.current().Photo
dv.fileLink(dv.current().Photo, true)

stecydube avatar Jun 15 '22 11:06 stecydube

I can concur. I've been banging my head against the keyboard trying to get embed() to work. I have the note and the image in the same folder. I've tried with the yaml both with and without the braces.

---
image: "[[ScreenShot.png]]"
---
## This works as expected, so it knows where the image is and can display it normally
![image](ScreenShot.png)

## Shows the name as a link and hovering will show the image
`= link("ScreenShot.png")`

## Just shows the name as text, not a link any more
`= embed(link("ScreenShot.png"))`

## As expected, shows the name as a link and hovering will show the image
`= link(this.image)`

## embed() fails again; Just shows the name as text, not a link any more
`= embed(link(this.image))`

scottmc42 avatar Oct 20 '22 18:10 scottmc42

Use inline query like this to generate markdown img tag:

`= "![b|150](" + this.imgUrl + ")"`

fwolf avatar Nov 19 '22 15:11 fwolf

@fwolf , I just tried that code and it's still not showing up. If I remove the !, then it appears as a link to the correct image so I know the markdown works.

What does the b|150 mean? If this for a plugin?

scottmc42 avatar Nov 19 '22 21:11 scottmc42

@fwolf , I just tried that code and it's still not showing up. If I remove the !, then it appears as a link to the correct image so I know the markdown works.

What does the b|150 mean? If this for a plugin?

It should work unless u change dataview's inline query prefix in config, in short its a "" + string + "" compute in a inline query.

The b|150 is markdown marker copy from other plugin generated content, to set the image display width, do not need any plugin to use it.

fwolf avatar Nov 20 '22 01:11 fwolf

@fwolf , Here is the markdown I'm using:

---
name: "Sir Truumble Broomfodder"
image: "truumble-token.png"
race: "Kobold"
gender: "Male"
class: 
    - "Totem Barbarian"
level: 3
background: "City Watch"
hp: 32
ac: 19
modifier: 4
passive: 12
location: "Testville"
player: "Scott"
---

|    0  ![[truumble-token.png]]     |
|:-------------------------------:|
|  **Sir Truumble Broomfodder**   |
|  `= this.gender` `= this.race`  |
|         `= this.class`          |
|      Level: `= this.level`      |
| Background: `= this.background` |
| Currently in: `= this.location` |
|     Player: `= this.player`     |
|  1 `= "![[" + this.image + "]]"`  |
|  2 `= "![](" + this.image + ")"`    |

The image shows up when hardcoded (next to the 0). On the table row marked 1, it just displays the image name, not a link, and not showing the brackets. On the table row marked 2, I used your formatting example and nothing shows up; no image, no text.

scottmc42 avatar Nov 26 '22 22:11 scottmc42

@scottmc42, I actually wanted to use it for the same usecase as you do. The suggestion from @fwolf didn't work for me either. Neither did any form of embed(). The current workaround I'm using is via TABLE (also works with LIST). Borrowing from your example:

---
image: "![[truumble-token.png]]"
---

```dataview
TABLE WITHOUT ID
    this.image AS "Portrait" 
WHERE file.name = this.file.name
```

This also works with scaled images, e.g.:

---
image-wxh: "![[truumble-token.png|50x50]]"
image-w: "![[truumble-token.png|50]]"
---

The WHERE clause is necessary to prevent the table from fetching all files with the 'image' attribute.

pstelzer avatar Dec 07 '22 13:12 pstelzer

@pstelzer , I'm aware of the dataview workaround. However, as shown in my above example, I'm trying to put the picture inside of an MD table. Unfortunately, that means I cannot use solutions that are multi-line.

scottmc42 avatar Dec 07 '22 16:12 scottmc42

@pstelzer , I'm aware of the dataview workaround. However, as shown in my above example, I'm trying to put the picture inside of an MD table. Unfortunately, that means I cannot use solutions that are multi-line.

you should probably be able to do it with inline js then if you use execute, would be ugly but possible

ggstrader avatar Dec 17 '22 19:12 ggstrader

is second this, still no way to display img with inline queries

lucastucious avatar Jan 04 '23 13:01 lucastucious

I hope embedded local images should work in inline query because all the URL image shortened links are now broken and I had a hard time to fix all of them...

Missionary-OSBS avatar Jan 21 '23 10:01 Missionary-OSBS

Is this still not possible?

Worren avatar Aug 11 '23 13:08 Worren

Is this still not possible?

+1 would love to see support for this as well, I think it will be a more common use case going forward with properties.

I suppose @blacksmithgu original response that inline queries do not use react has not changed

Another alternative would be to use an inline hidden field ie (photo:: ![[test.jpg]]) - doesn't work for all scenarios obviously.

GovSat1 avatar Aug 26 '23 13:08 GovSat1

In the Obsidian forum @holroy came up with a workaround that wasn't mentioned here:

---
cover: full/path/toImage.jpg
---
`$= dv.container = '<img src="' + app.vault.getResourcePath( dv.fileLink(dv.current().cover) ) + '" />' `

Source: https://forum.obsidian.md/t/using-metadata-of-pictures-inside-the-note/57514/9

For me that was helpful. Maybe for some others as well 😊

davidkopp avatar Jan 20 '24 10:01 davidkopp