TOC for Tasks plugin grouped result and divided into sections

What I’m trying to do

I want to create TOC (table of content) from a result from a Tasks plugin. The result is grouped - it means that it has sections.

I made a code for extracting @context from my tasks like:

description includes @
group by function task.description.match(/@[^\s)\.,]+/)

The result is divided into sections:

Things I have tried

I tried dataviewjs bit it does not work for any of section level:

const startAtLevel = 4
const content = await dv.io.load(dv.current().file.path)
const toc = content.match(new RegExp(`^#{${startAtLevel},} \\S.*`, 'mg'))
  .map(heading => {
    const [_, level, text] = heading.match(/^(#+) (.+)$/)
    const link = dv.current().file.path + '#' + text
    return '\t'.repeat(level.length - startAtLevel) + `1. [[${link}|${text}]]`
  })
dv.header(2, 'Table of contents')
dv.paragraph(toc.join('\n'))

Is it possible to work with the result from Tasks plugin at all?