Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,256,600
Community Members
 
Community Events
164
Community Groups

TOC macro use to show Headings in embedded word docs

Create a User Macro : No Macro Body

This is to be used in conjunction with the TOC Macro and will append to the TOC Macro
{code}

## @noparams
<ac:structured-macro ac:name="html">
<ac:plain-text-body><![CDATA[
<style>
ul#WORDTOC .h1 {
font-weight: bold;
margin-top:6px
}

ul#WORDTOC .h2:before,
ul#WORDTOC .h3:before,
ul#WORDTOC .h4:before ,
ul#WORDTOC .h5:before ,
ul#WORDTOC .h6:before{
content:'\2022';
padding-right:6px;

}
ul#WORDTOC .h2{
margin-left:12px
}
ul#WORDTOC .h3{
margin-left:24px
}
ul#WORDTOC .h4{
margin-left:36px
}
ul#WORDTOC .h5{
margin-left:48px
}
ul#WORDTOC .h6{
margin-left:60px
}
</style>
<script>
AJS.toInit(function () {
var saidHello = false;
AJS.$('.converter-macro-ajax-container').ajaxStop(function(){
runOnce();
});
function runOnce(){
if (!saidHello) htmlTableOfContents();
}
function htmlTableOfContents (documentRef) {
AJS.$('.toc-macro').append("<ul id='WORDTOC'></ul>");
var documentRef = documentRef || document;
var toc = documentRef.getElementById('WORDTOC');
var headings = [].slice.call(documentRef.body.querySelectorAll('.office-container h1, .office-container h2, .office-container h3, .office-container h4, .office-container h5, .office-container h6'));
headings.forEach(function (heading, index) {
var anchor = documentRef.createElement('a');
anchor.setAttribute('name', 'toc' + index);
anchor.setAttribute('id', 'toc' + index);

var link = documentRef.createElement('a');
link.setAttribute('href', '#toc' + index);
link.textContent = heading.textContent;

var div = documentRef.createElement('div');
div.setAttribute('class', heading.tagName.toLowerCase());

div.appendChild(link);
toc.appendChild(div);
heading.parentNode.insertBefore(anchor, heading);
});
saidHello = true;
}
});
</script>
]]></ac:plain-text-body>
</ac:structured-macro>

{code}

1 comment

Bill Bailey Community Leader Oct 15, 2021

@Matthew Beda very interesting.  I think this would work very well as an article where you go through the theory of how it works to help the user community out there.  Some examples of ones I wrote:

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Confluence Cloud

Presenter Mode for Confluence is here 🖥 👩‍💻

👋  Hello Community!  My name is Stephanie Zhang, and I’m a product manager on the Confluence cloud team. Today, I’m excited to announce the rollout of  Presenter Mode : a ...

2,317 views 19 41
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you