Dataview query to filter out strikethrough text

Is there a way to filter out any text that is striked out? I have a query that pulls any data under a specific heading but would like to not pull those with strikethrough formatting.

Some regex could help. I don’t know about your table, but you can include a regex ā€˜not match’; something like this:

```dataview
TABLE
FROM [[Your File]]
WHERE !match(file.content, /\~\~(.*?)\~\~/gm)
1 Like

What are you going to do with the filtered text?

Are you already using a variant over the script AlanG has shared around here? If the latter, then you could possibly do a regexreplace on the strikethrough text before presenting the text to the user.

I was on my phone when I posted but would like to post the variations and error results I have unsuccessfully tried for any insights.

What I am doing is looking for any text under the ā€œThoughts and Notesā€ subsection which is where I place items that don’t rise to a task/todo level, or are fleeting thoughts, etc. As they are in my daily notes but not referenced easily, I am trying to make a single page where these are gathered so I don’t forget. If the note get’s moved, then obviously it’s not in the subsection anymore but others, I want to keep around just in case for now so I strikeout the text. As I work through the process of building my PKM, I may simply just delete them.

TABLE L.text AS "Thoughts and Notes"
FROM "01_Daily_Notes"
FLATTEN file.lists AS L
WHERE meta(L.section).subpath = "Thoughts and Notes" 
WHERE !match(file.content, /~\~(.*?)\~\~/gm)

image

TABLE L.text AS "Thoughts and Notes"
FROM "01_Daily_Notes"
FLATTEN file.lists AS L
WHERE meta(L.section).subpath = "Thoughts and Notes"
WHERE NOT meta(L.text).(file.content, /~\~(.*?)\~\~/gm)

image

TABLE L.text AS "Thoughts and Notes"
FROM "01_Daily_Notes"
FLATTEN file.lists AS L
WHERE meta(L.section).subpath = "Thoughts and Notes" 
WHERE NOT file.content.contains("~~")

image

Did you manage to sort it out?

I am a not a DV expert and just dip my toes in scripting as well and I’m more comfortable with DVJs, for some reason. All my queries on my dashboard canvas are DVJs queries.
I couldn’t get the subpath to work in DVJs so I cooked with the ingredients I had. I also didn’t work with the advice given above, as I simply deleted the text within pairs of ~~ (the original text in the files remain in place):

```dataviewjs

// Define path
const queryPath = /01_Daily_Notes/;

// Query all pages
const allPages = dv.pages("");

// Filter pages to be queried
const filteredPages = allPages.filter(page => {
    const path = page.file.path;
    return queryPath.test(path);
});

// Crawl the raw data content and filter pages based on given criteria
const pages = await Promise.all(
    filteredPages.map(async (page) => {
        const content = await dv.io.load(page.file.path);

        const subpathRegex = /##\s*Thoughts\sand\sNotes([\s\S]*?)#{1,6}\s/gm;
        const matchSubpath = content.match(subpathRegex);

        if (matchSubpath) {
            const filterPattern = /~~(.*?)~~/gm;
            const filteredContent = matchSubpath[0].replace(filterPattern, '');

            return {
                link: page.file.link,
                content: filteredContent
            };
        }

        return null;
    })
);

// Remove null entries and render the result table
const filteredAndProcessedPages = pages.filter(p => p !== null);

dv.table(
    ["Thoughts and notes", "Content"],
    filteredAndProcessedPages.map(p => [p.link, p.content])
);
```
  • The above expects any heading to come after level Thoughts and Notes, though.
    Or you can change /##\s*Thoughts\sand\sNotes([\s\S]*?)#{1,6}\s/gm to something else to better target the text to be manipulated or maybe you can get subpath to work.
    Also, the lines need to be separated as they are currently merged in the table. Changing const filteredContent = matchSubpath[0].replace(filterPattern, ''); to const filteredContent = matchSubpath[0].replace(filterPattern, '\n\n'); didn’t help. There is some way to separate them as I saw this issue before but it eludes me.
1 Like

You got it! Thanks!!!

As I said, this is a workaround, not the solution. I’d be interested in the Solution myself.

Funny cause to me this is a great solution.

Simple enough, though. Change it to const filteredContent = matchSubpath[0].replace(filterPattern, '<br><br>'); and voila.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.