Tasks plugin - How to use higher order headings in query?

I’m sorry to say that I believe both Tasks and the task queries of Dataview only respect/handle the heading immediately before the task itself.

If you’re dead set on accomplishing this goal, you would need to parse the headings section of the metadata for a given file, and correlate the task position with a self maintained heading hierarchy.

Given a headings section like the following:

image

You could scan through, and see that H2 one on line 1, is followed by H3 one_one on a line inbetween, but “replaced” by H3 one_two on line 9, so that if you had a task at line 10 (which is still before H2 two on line 12), then that task would have the headers “H3 one_two” and “H2 one”, and you could do your check to see if “H2 one” matched the date regex or not…

See the following threads and links for a little more on the headings metadata:

Hope this gives you some insight into how to tackle your issue at hand.


Another approach to how to do the actual filtering in your case could be something like the similar:

  • Scan through each of the headings, and see if any matches your regex. If they do, take note of the heading level, and the line it’s at
  • Keep scanning headings and see if you find a heading at the same level. If you do, take note of the line number (also note the line number if you reach the end of file). The line number from previous item, and this line number is now the “valid” range for your tasks in this file
  • Depending on your file structure, you could repeat the previous steps to find multiple ranges matching your regex
  • Afterwards, scan the tasks and only list tasks where their line numbers is within the found range

Does that make sense to you?

1 Like