I have found existing questions about the Table of Contents macro, but none quite match this question.
Background to this question: what I'm doing
I have recently returned to using Confluence frequently after a long period of infrequent use. I'm relearning what Confluence does, and doesn't, do out of the box.
I'm using Confluence to write policies for my employer. We have decided to use an ISO standard as a template for the policy heading structure. The heading structure contains three levels. I have "chunked" the structure into Confluence pages at the highest heading level, giving me 14 pages. Those pages will grow as I add content to the skeleton heading structure.
On returning to Confluence, after spending time in other documentation systems, I had two nasty surprises. I'd be very happy to be wrong about both of them:
- The Confluence "Table of Contents" macro does not offer the option to include headings from descendant pages.
- A related issue: The Confluence browser user interface does not support search-and-replace across multiple pages; in particular, search-and-replace that includes descendant pages of the "current" page. It seems I need to write my own code (possibly based on an existing user macro) that, for example:
- Uses the Confluence REST API to traverse the page tree and get the contents of each page
- Performs the search and replace for each page
- Uses the REST API to update each page
I want a single table of contents that includes all of the policy headings. For now, as a workaround, I've created a "single page" version of the policy that consists of a "Table of Contents" macro followed by an "Include Page" macro for each of the 14 "chunks". Each "Include Page" macro is preceded by a Heading 1 paragraph that duplicates the "chunk" page title. A useful side-effect is that I can use this page to search the entire policy using my browser's built-in "Find" function.
On a few occasions, I've needed to perform search'n'replace across the 14 pages of the policy. For now, without a better solution—and I'm not interested in petitioning my employer to buy another for-money Confluence plugin—I've done that by manually editing each of the 14 pages. That's not been fun, but so far I've been too busy writing and editing content to want to look into writing my own search'n'replace code. It's occurred to me to try WebDAV with an external editor, but after making some enquiries to my local Confluence administrator, I dropped that idea (I can explain, if asked).
I'd like to split those 14 pages into smaller chunks, perhaps even right down to the lowest (third) heading level, but I baulk at the thought of:
- Increasing the complexity of the "single page" version (many more "Include Page" macros and preceding headings that duplicate page titles)
- Manually searching'n'replacing across many pages
One feature of the "Table of Contents" macro that I really like is the ability to include or exclude headings based on regular expressions. I'm using that feature to create different versions of the table of contents, based on the presence or absence of strings that I append to the headings, such as "(TODO)" or "(N/A)".
What I want
I want a version of the Table of Contents macro that offers two "checkbox" settings:
- Include headings from descendant pages
- Include descendant page titles as headings (treat child page titles as Heading 1, grandchild page titles as Heading 2, and so on)
Does anyone have this, or something similar, as a user macro that they could share with me?
Failing that: (where, in the installed Confluence product code) can I get the source code of the supplied Table of Contents macro, so that I can use it as the basis for my own version with these additional settings? I have some experience writing Confluence user macros, but that was several years ago.
I'd also like a search-and-replace macro that recurses into descendant pages, but I should ask a separate question about that (I mention it here because it's so closely related to my use case for this TOC macro).