blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
7.05k stars 414 forks source link

dv.sectionLink with embed does not work after reading/parsing files #1681

Open codingThome opened 1 year ago

codingThome commented 1 year ago

What happened?

I am parsing a directory and reading all files searching for a certain header (## Visuals). When found and used as normal sectionLink it works but when setting embed true it just shows the File-/Sectionnames (no Links and not embedded). Is this a bug or am I doing something wrong (When not reading file-Content the embedding works) (By the way: it is also not working when using dv.io.load for reading the file-content)

Without embed: 2022-12-22 08_35_19-Scripts - PowerBI_Basic_Vault - Obsidian v1 1 8

With embed:

2022-12-22 08_35_37-Scripts - PowerBI_Basic_Vault - Obsidian v1 1 8

Thanks Thomas

DQL

No response

JS

const pages = dv.pages('"Examples"')
const regex = /## Visuals[\S\s]*/

for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    // Read the file contents
    const contents = await app.vault.read(file)
    if (contents.match(new RegExp(regex, 'sg'))) {
        //when embed is true it does not work like expected
        dv.paragraph(dv.sectionLink(page.file.path, "#Visuals", true))
    }
}

Dataview Version

0.5.47

Obsidian Version

1.1.8

OS

Windows

s-blu commented 1 year ago

Hello,

thanks for your report. You're seeing the alternative text of the embed, therefore its no link. You're not doing anything wrong, as far as I can tell. I can reproduce your described behaviour with your code snippet, but its working fine if I hardcode i.e. dv.paragraph(dv.sectionLink("test.md", "#Visuals", true)) - notable here, it only works until the first reload of the query - then I also only see the alt text.

The embed support is quite wonky and I sadly have no workaround for this behaviour right now. Maybe blacksmithgu can say more.