blacksmithgu / obsidian-dataview

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

Query Codeblocks #1391

Open ujwalnk opened 2 years ago

ujwalnk commented 2 years ago

Many plugins use codeblocks for rendering content on Obsidian. Namely Admonition.

It would be nice to have a feature to query the codeblocks into a list as to list the rendered content of the codeblocks of all admonitions, or say all the codeblocks of java or html.

AB1908 commented 2 years ago

Parsing codeblocks sounds hairy since it would need to be done by hand. Can you demonstrate your use case with an example?

ujwalnk commented 2 years ago

image image image

Say I have all these code blocks, could we have a way to make a list and preview all the ones that meet the condition, say display only the admonitions and not the Verilog code?

EDIT:

Parsing codeblocks sounds hairy since it would need to be done by hand. Can you demonstrate your use case with an example?

Each code block has its language written after the three ticks (```), which I think can be used to segregate the code blocks, thus not requiring a backend.

AB1908 commented 2 years ago

You do have a point. You can write some JS to manually parse these pages after reading their content and then query your own index. Several other users have done so as well. In terms of plugin level support, I don't think anything similar is planned for the short term but blacksmithgu will know better.

ujwalnk commented 2 years ago

Thank you for your response. Can you please share an example of parsing those code blocks using JS. A link to one of those would be extremely helpful. Thanks & Regards, Ujwal N.K.

On Sun, Oct 9, 2022 at 9:37 PM AB1908 @.***> wrote:

You do have a point. You can write some JS to manually parse these pages after reading their content and then query your own index. Several other users have done so as well. In terms of plugin level support, I don't think anything similar is planned for the short term but blacksmithgu will know better.

— Reply to this email directly, view it on GitHub https://github.com/blacksmithgu/obsidian-dataview/issues/1391#issuecomment-1272574070, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJMGVZ5WMYEAN5Z2GXOFELWCLUVXANCNFSM6AAAAAAQC2FADA . You are receiving this because you authored the thread.Message ID: @.***>

blacksmithgu commented 2 years ago

The obsidian index tracks codeblock locations so this is indexable information. The actual contents of the codeblocks will need to be fetched separately but that is doable.

AB1908 commented 2 years ago

Oh that's fantastic. I need to double check metadataCache contents before confidently replying lol.