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

forced-shown Outlinks and Images is not displayed in Query Type TASK

Open magicGina opened this issue 2 years ago • 4 comments

What happened?

When use forced-shown outlinks in tasks that written by pure mark down, it can be shown. image But if I use a query type TASK to do some filter or so, it cannot be shown,and the outlink mark is also gone. image

Wether I use DQL or JS, this bug both happend. I can only use dv.markdownTaskList() to show them, but this is generating a new tasklist and changes of task status can not be applyed to origin tasklist. Further more, the markdownTaskList way will fail too when I changed the origin tasklist, showing what shows when use TASK to query. but it turns good when reopen the dataview page.

This is the same thing happend in this issue, I think it is a bug to be solved, but this issue is closed.#1702

I tryed to see what happened, it got me somewhere, and I don't know if this helps: when I use dv.span() to show an item in task array, outlinks is also not shown. But when I use task.text to get the text property,the markdown text is 100% right! It is strange...to me... image

DQL

TASK from "搞机系列/建站/test.md" where !completed

JS

this is the query js, it can not show forced-shown outlinks.

dv.taskList(dv.pages('"搞机系列/建站/test.md"').file.tasks .where(t => !t.completed))

this is the query js, that uses dv.markdownTaskList() .

const markdown = dv.markdownTaskList(dv.pages('"搞机系列/建站/test.md"').file.tasks .where(t => !t.completed))
dv.span(markdown);

this is the js to show what task item is

const tasks = dv.pages('"搞机系列/建站/test.md"').file.tasks.where(t => !t.completed)

let modifiedTasks = tasks.forEach(onetask =>{
	let changed_outlinks = [];
	for(let outlink of onetask.outlinks){
		if("can it show?Lets see pages![[安卓虚拟机]]" == onetask.text){
				dv.span("---");
		dv.span("```the text property is:"+onetask.text+"```");
		dv.span("<br>");
		dv.span(onetask);
		dv.span("<br>");
		}
	}
});

Dataview Version

0.5.58

Obsidian Version

1.4.13

OS

Windows

magicGina avatar Sep 16 '23 18:09 magicGina

image this is the HTML generated by dataview. maybe its because of the css of the class "internal-embed"?

magicGina avatar Sep 17 '23 00:09 magicGina

I use a piece of JS to avoid this bug, now the picture can be shown,but file outlink still not showing


let tasks = dv.pages('"搞机系列/软件/obsidian/dataview有bug/test.md"').file.tasks.where(t => !t.completed);
dv.taskList(tasks);

function showPic() {
let imgSpans = document.getElementsByClassName("internal-embed");
for(let i = 0; i < imgSpans.length; i++)
{
	let outlinkname = imgSpans[i].innerHTML;
	if(outlinkname.endsWith(".jpg")||outlinkname.endsWith(".png")){
		let src = app.vault.adapter.getResourcePath("搞机系列/软件/obsidian/dataview有bug/attachments/"+outlinkname);
		let img = "<img src=\""+src+"\">";
		imgSpans[i].innerHTML = img;
	}
}
}
setTimeout(showPic, 1000)

image

magicGina avatar Sep 17 '23 08:09 magicGina

@magicGina Thanks for the fix!

I had iterated on it a bit to handle resized images.

function FIX_showEmbeddedPicturesInTaskList() {
  const imgSpans = document.getElementsByClassName('internal-embed');

  for (let i = 0; i < imgSpans.length; i++) {
    const fileName = imgSpans[i].attributes?.src?.value;

    if (fileName.endsWith('.jpg') || fileName.endsWith('.png')) {
      const width = imgSpans[i].attributes?.width?.value;
      const height = imgSpans[i].attributes?.height?.value;
      const src = app.vault.adapter.getResourcePath('⚙️ Settings/Attachments/' + fileName);
      const trace = `data-quick-fixed-by="${FIX_showEmbeddedPicturesInTaskList.name}"`;
      const img = `<img ${trace} src="${src}" width="${width}" height="${height}" >`;
      imgSpans[i].innerHTML = img;
    }
  }
}

setTimeout(FIX_showEmbeddedPicturesInTaskList, 50);


padamban avatar Feb 06 '24 07:02 padamban

So dataview don't show it as a bug?

PencilMing avatar Mar 31 '24 05:03 PencilMing