TOC - Only show headings under a parent heading
Asked by Josh Sutton:

I'm trying to setup a Table of Contents that only shows heading under a parent heading. For example if I have the follow structure, I want to setup the table of contents to only show 'Favourite Foods' and 'Unknown Foods' under the 'Places' heading.

* Favourite Foods
* Unknown Foods

I've tried following the example below by excluding the Foods and Things headings but the example expression does not work. If I type .\*(Foods\|Things) the TOC still shows everything. If I type (Foods\|Things).\* the TOC shows ALL h2 options.

* Favourite Foods
* Unknown Foods
* Favourite Foods
* Unknown Foods
* Favourite Foods
* Unknown Foods

I've also tried only including the Places heading with the Minimum Heading Level set to 2. However, if I type Places.\* the TOC returns blank. If I remove the Minimum Heading Level then the TOC returns only the parent heading without the child headings.

* Places

![Example.PNG](/t5/image/serverpage/image-id/43546iFDBD59871BBDC08A/image-size/large?v=v2&px=999 "Example.PNG")

Source: <https://confluence.atlassian.com/doc/table-of-contents-macro-182682099.html>

Does anyone have any suggestions?


Answers:
author: Jared Brenner
body: Hi Josh,

Depending on how your headings are organized you may want to consider the [Table of Content Zone macro](https://confluence.atlassian.com/conf612/table-of-content-zone-macro-958777854.html), which will display headings that are nested within it rather than all headings on the page. Of course, if you can't easily separate the headings into distinct sections then this solution wouldn't work for you.

Good luck!


author: Stephen Sifers
body: Hello Josh and welcome to the Community!

This was a fun one to review and to answer. If we follow the example, you're wanting to only include results (Favourite Place OR Unknown Places). With this said, you will use a simple regex to include only those results. Here is the example:

Include Headings:

```
Favourite\sPlaces.*|Unknown\sPlaces.*
```

OR

```
^(Favourite Places)|^(Unknown Places)
```

The above applies to the example within the documentation. There is a limitation to this that you should be aware of though. Since each line will be processed and include or exclude based on the regex you provide, this will not allow for filtering of a child object since regex is looking at all results linearly. Here is how the regex is seeing the results:

```
Places
Favourite Places
Unknown Places
Foods
Favourite Foods
Unknown Foods
Things
Favourite Foods
Unknown Foods
```

Now, if you only want to display content under Places without having to include said content like above, you will need to do something as follows:

Minimum Heading Level = 2

Exclude Heading

```
.*Foods|.*Things
```

Upon further testing, it does not seem that the include or exclude regex are processing the items as an array. I attempted to display a line after a result which kept returning no value. There is also a reported bug within the product which results will display within preview mode and not with a published page. You may find that bug at [CONFCLOUD-52856](https://jira.atlassian.com/browse/CONFCLOUD-52856).

Once again, this is a great question and I really enjoyed providing an answer. I hope this is applicable to what you're attempting to accomplish.

Regards,  
Stephen Sifers

comments: author: Josh Sutton
body: I was able to go through and list every h2 heading that I wanted to display in the 'Include Headings' options. This will be a pain to maintain long term though.

Unfortunately, what I really need is what you described at the end.
> Now, if you only want to display content under Places without having to include said content like above, you will need to do something as follows:
>
> Minimum Heading Level = 2  
> Exclude Heading
>
> ```
> .*Foods|.*Things
> ```

> Upon further testing, it does not seem that the include or exclude regex are processing the items as an array. I attempted to display a line after a result which kept returning no value.

When I use these options in an attempt to exclude a parent heading and all child headings under it, the only heading that gets hidden is the parent. Then all child headings get pushed under the parent item above it. I get the follow output based on these two scenarios.

Minimum Heading Level = 1

Exclude Heading = .\*Foods

Output:

```
Places
   Favourite Places
   Unknown Places
   Favourite Foods
   Unknown Foods
Things
   Favourite Foods
   Unknown Foods
```

Desired Output:

```
Places
   Favourite Places
   Unknown Places
Things
   Favourite Foods
   Unknown Foods
```

Minimum Heading Level = 2

Exclude Heading = .\*Foods

Output:

```
Favourite Places
Unknown Places
Favourite Foods
Unknown Foods
Favourite Foods
Unknown Foods
```

Desired Output:

```
Favourite Places
Unknown Places
Favourite Foods
Unknown Foods
```

It looks like you are correct that the Heading groups are not being treated as an array but instead as individual items. Until a change is made to allow heading groups to be treated as an array it looks like this will be impossible.


Tags: atl-adm

cloud

confluence-cloud

heading

table-of-contents