Adapt TOC - without numbering (DataviewJS)

Hi there,

I’ve got this snippet to create a Table of Contents for my notes:

// Set this to 1 if you want to include level 1 headers,
// or set it to 2 if you want to ignore level 1 headers
const startAtLevel = 2
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, 'Inhoudsopgave')
dv.paragraph(toc.join('\n'))

Currently it generates a numbered list. But since I generally number the headings myself, I’d like to let the snippet generate without the numbers. How do I get that?

Thanks in advance for any help!

Could change the 1. to -, or delete the 1. if you don’t care about the indentation.

Thanks for the tip, that pointed me in the right direction.

I’ve now adapted the numbering to “regular bullets (-)” to maintain indentation.

For anyone looking for similar issues:
I’ve also altered the last bit dv.paragraph(toc.join('\n')) to something else, so I could add a css-class:
dv.el("p", toc.join('\n'), { cls: "dataview-toc" })

(Perhaps I could have added the class right there in the dv.paragraph section, but the dataview-resources weren’t very clear on that.)

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