I want to add some different styles to my ToC depending on its length. It doesn’t seem that the length is available anywhere in the document, so my idea™ is, that I take .TableOfContents
and findRE
through it to get the number of opening li
tags. If that number is bigger than my x
then I am fairly sure that there are more than x
items in the list.
Something like this…
{{ (findRE "<li[(<\/li)]*" .Content).len }}
Is that the way to go? I assume there might be a better way based on counting the headlines in the document, but that too is not something that has some form of function in the templates available.
One last thing: Is whatever .TableOfContents
returns cached in some form, so that it’s not calculated twice or should I appoint it to a variable and reuse?