nimib-land / nimibex

🐐 nimibex - extensions, experiments and extras for nimib ecosystem
MIT License
6 stars 0 forks source link

Add an easily customizable TOC #13

Closed dlesnoff closed 1 year ago

dlesnoff commented 1 year ago

In the few Nimib files that I created, I always resort to templates similar to this one for the creation of a table of contents (TOC):

var nbToc: NbBlock

template addToc =
  newNbBlock("nbText", false, nb, nbToc, ""):
    nbToc.output = "### Table of Contents:\n\n"

template nbSection(name:string) =
  let anchorName = name.toLower.replace(" ", "-")
  nbText "<a name = \"" & anchorName & "\"></a>\n## " & name & "\n\n---"
  # see below, but any number works for a numbered list
  nbToc.output.add "1. <a href=\"#" & anchorName & "\">" & name & "</a>\n"

It would be interesting to make this easily configurable with a simple addToc command, that would define nbSection, nbSubSection, nbSubSubSection, nbParagraph (like Latex?) or nbH1Title, nbH2Title, etc ... for each level of heading. It would be cool if the Toc appearance could be configurable too (level of heading, title?) without having to resort to nbToc.output and newNbBlock.

pietroppeter commented 1 year ago

The idea was to add this to nimib itself, see https://github.com/pietroppeter/nimib/issues/58