Expand my Community achievements bar.

SOLVED

Table of contents - Custom filter

Avatar

Level 3

Hi , most of the logic for the table of contents component is handled at TableOfContentsFilter.java. I see the component creates IDs for h1-h6 elements in a page if not already present and then maps it to the table of contents list items. In this process, all the unnecessary text elements within the h1-h6 tags such as <span> classes are also getting copied to the id field and the same id displayed on the Table of contents list as well without any formatting. (For example superscripted references)

 

Now, I am looking at modifying this logic in the filter class and I would like to know if that's possible. A model delegate is not possible here and the logic is heavily built in the filter. Can we extend or by any means modify the logic here with no much hassle. 

 

Thanks for your time and highly appreciate any suggestions.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Sahana_S,

It is not possible to extend TableOfContentsFilter.java directly. It's because this class is part of internal package so it will not be exposed on java code level.

In my opinion the easiest option will be to create your own implementation simply copying the code - and use it as a base.

What is also good that TableOfContentsFilter.java can be disabled via OSGi configuration, so having your own implementation you do not need to do any tricks with service ranking etc.

View solution in original post

3 Replies

Avatar

Community Advisor

Hi, 


Since the code is open source: https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/w..., I think the best approach would be to create your own custom filter and register it with a higher rank. The reason for this is that the implementation seems quite locked down, so overriding it with your own filter might be the most effective solution.

 

Reference: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-specify-the-order-o...

 

Hope this helps



Esteban Bustamante

Avatar

Correct answer by
Community Advisor

Hi @Sahana_S,

It is not possible to extend TableOfContentsFilter.java directly. It's because this class is part of internal package so it will not be exposed on java code level.

In my opinion the easiest option will be to create your own implementation simply copying the code - and use it as a base.

What is also good that TableOfContentsFilter.java can be disabled via OSGi configuration, so having your own implementation you do not need to do any tricks with service ranking etc.

Avatar

Level 3

Thank you @lukasz-m . I did this and in the process, I have created custom classes for the internally referenced files as well. This works. Thank you !