datacore icon indicating copy to clipboard operation
datacore copied to clipboard

[Request] include $text for blocks

Open stefanku opened this issue 1 year ago • 3 comments

With list-items there is a key '$text' that contains the contents of the item. Are there any plans to also include such a key for blocks in datacore?

stefanku avatar Nov 14 '24 16:11 stefanku

I think I read somewhere in a release that pulling the text content into indexes was actually being avoided for the most part, but that tasks aka list items were a common enough use-case for an exception to that.

I’d still be interested to see if there’s some workaround to display a block’s content since they lack a $text property.

leafybees avatar Mar 14 '25 01:03 leafybees

im curious - if datacore has a reference to the block itself if we can somehow use that information with the obsidian api to pull in the markdown for that block (or section, in my case)

I would love to be able to query section content:

# Notes
here is a note i would like to see in a dataview query somewhere 

and it could be multiple lines!

@blacksmithgu any thoughts on how we can approach this?

lx0n2acl avatar Apr 02 '25 16:04 lx0n2acl

Just a note on this: Datacore provides the line numbers for most of the sub page types with the $position property .start and .end, which can then be used to pull the contents using the obsidian api. I wrote a function for this for my own use, here.

static async loadFileContentBetweenLines(filepath, startLine, endLine) {
        let file = app.vault.getFileByPath(filepath);
        try {
            const fullContent = await app.vault.read(file);
            const lines = fullContent.split('\n');

            const actualEndIndex = Math.min(endLine, lines.length);

            const selectedLines = lines.slice(startLine, actualEndIndex);

            //join and make sure there aren't leading or trailing characters
            return selectedLines.join('\n').trim();

        } catch (error) {
            console.error(`Error reading file or extracting lines from ${file.path}:`, error);
            return null;
        }
    }

techy-robot avatar Jun 30 '25 16:06 techy-robot