It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is it possible to add numbering to headings in Confluence?

Morning,

In Confluence we have headings and we have numbered lists.

Is it possible to combine the two (and then use them as part of a template)?

And to have the numbering working automatically?

The idea is that this would work as it does in Word. So once you start using numbered headings, all subsequent headings get numbered both automatically and down a level each time. For example:

Heading 1 = 1. A Heading

<some text>

Heading 2 = 2.1 Help

<some text>

Heading 2 = 2.2 I Need

<some text>

Heading 2 = 2.3 Your Help

<some text>

Etc, etc, so everytime a new heading level was added, the numbering also changed to accommodate that.

Does this make sense?

Cheers.

10 answers

1 accepted

8 votes
Answer accepted

There's a third-party plugin for that: https://marketplace.atlassian.com/16063

Amalia, thanks for pointing me in the right direction. :)

But it's not available for OnDemand instances :(

The add-on now has a stable OnDemand counterpart, you can find it here.

Numbered Headings is now available for Cloud, Server and Data Center:

https://marketplace.atlassian.com/apps/16063

We've installed Numbered Headings Free on server, but cannot find any button to insert number. Is it possible to add number in free version, or it only provides view function?

@Jian YaoThe free version of Numbered Headings uses a macro to number your headings. You can find the macro in the macro browser by search for 'Numbered Headings'.

The button in the editor is only available in Numbered Headings Pro.

Engineering Essentials has just been released to the public.

This resolves the issue of numbered headings space-wide, without needing to put your content inside a macro.

With Engineering Essentials it is now possible to configure an entire space to have numbered headings. Any enabled space will instantly have it's headings numbered. No additional editing of a page is required. This enforces a consistent look and feel within each space. Additionally, because your content does not need to be wrapped in a macro it does not interfere with page differences, change emails, exports, or other plugins. Ensuring your content will continue to be available into the future, regardless of what plugins you have installed. This simplifies export templates and improves compatibility by defining the correct layout for the particular format within your own templates.

As numbered headings are often required for formal documentation we've also provided the ability to separately force version comments on all changes within a space. Enabling fully automatic change history documentation.

With years of experience supporting Confluence in an engineering environment, Precision Plugins have big plans to plug some small gaps, helping Confluence and other extensions be the best environment for your formal documentation.

Checkout the Engineering Essentials package and let us know what you think here:
https://marketplace.atlassian.com/plugins/com.precisionplugins.engineeringessentials

Since all answers here either suggest paid plugins or extensive use of javascript macros I wanted to note that numbering headings can easily be done with a stylesheet (which can be applied globally or space-wide depending on your preferences) using css counters:

#content.page.view {
     /* Set "section" to 0 */
    counter-reset: section;
}

#content.page.view h1 {
     /* Set "subsection" to 0 */
    counter-reset: subsection;
}

#content.page.view h1:before {
    /* Increment "section" by 1 */
    counter-increment: section;
    content: counter(section) " ";
}

/* Continue this scheme as deep as you need */

#content.page.view h2 {
    counter-reset: subsubsection;
}

#content.page.view h2:before {
    /* Increment "subsection" by 1 */
    counter-increment: subsection;
    content: counter(section) "." counter(subsection) " ";
}

#content.page.view h3:before {
    counter-increment: subsubsection;
    content: counter(section) "." counter(subsection) "." counter(subsubsection) " ";
}

Hi, this doesn't work for me. I want to add section numbering in my PDF report. Where do I have to paste your css?

Very nice, thank you

It works fine for viewing document! But during editing, the numbers are not displayed. Any suggestion for display numbers when edit documents?

Thanks Florian, works well for me in non-edit mode. Confluence should incorporate a macro to add.remove at will.

Is there a way to apply this per page?

Here's the OnDemand version of the plugin (I can't edit Amalia's answer)

https://marketplace.atlassian.com/plugins/nl.avisi.confluence.plugins.numberedheadings-connect

Currently it has some issues but I hope they get resolved in near future

Since then both the add-on and the OnDemand platform have seen vast improvements. Check our issue tracker for the current status: http://addons.avisi.com/confluence/numbered-headings/issues.html

We've recently updated our add-ons website. Anyone looking for help on Numbered Headings can find it here: http://addons.avisi.com/numbered-headings/help/

I can't believe that such a basic and essential wiki/documentation/knowledge space functionality is still not implemented natively in Confluence, and requires either some hacks with consequences or a 3rd party paid plugin. There is a plugin for everything, it seems, and they all add up in costs, both direct and maintenance. We are starting to get feed up with this approach by Atlassian, and looking at moving away from their products completely. 

Hi Arkadiy and Kim,

I also agree with your point that must to have features should be provided by Atlassian by default. But you also must appreciate that due to this open platform, many features are available at marketplace in form of add-ons. This way at least user can get away with the problem being faced. Wiki/documentation/ knowledge space has so much varied requirements as per use cases that it is very difficult for a close platform to serve all type of needs single handed.

Hi Nancy Jaiswal,

Indeed that an open platform like Confluence would let developers create more useful add-ons for end users. I do support this mindset and developers should also make money for their living.

But c'mon, we are in 2019 now, not in the '90s anymore.

Numbering to headings should be a must-have feature instead of an addon. If numbering is not a standard default feature, in my point of view, Confluence should not be called a WIKI system.

Not only that, you cannot even increase text size in Confluence neither, to increase text size you have to use the Macro DIV, correct me If I am wrong.

For IT dummies who are working in a Finance or Marketing department, asking them to use Macro DIV for increasing text size, they would curse the system to death :)

If you look at Wordpress, Drupal or other open source CMSs, their WYSIWYG editor includes all these features for free. You might ask me why I will not Wordpress or Drupal instead, well, it's a different topic and debate :)

Cheers

Kim

Hi Kim,

If you will read my comments, I too support basic features in default list of Confluence features. In my opinion it is not the philosophy of letting developers earn their living to prosper a business, it is about providing value to customer.

For providing control on text size, someone from Atlassian can better answer but my take is that any content management system should be controlled one. If you are aware of DITA philosophy, they are trying to provide controlled and limited set  of features to content creators so that uniformity and better search ability could be brought to content. My only point of mentioning this is that providing everything that exist in other editors may not always be a good idea in today's world were volume of content being created is tremendous.

 

Thanks

Nancy

Hi Nancy, 

Agreed with most of the thing you wrote here. I don't expect that we must include all features, but if we need to call someone then we don't basically need a smartphone right, we can use a dumb phone to call someone. For me, a wiki system should include numbering to headings heading which is one of the fundamental need to build Wiki pages. Not sure how other thinks, just my opinion :)

Regarding data volume, if we follow Moore's Law then data storage technology might not stop here and will not limit us from saving more data.  The questions here is what's in is for me and what Atlassian is willing to give us.

Maybe the Atlassian can give us a new option, they provide us the Confluence system, but we can decide to save our data wherever we wanted, either in Azure, Google Cloud or AWS etc.. :)

 

 

Cheers

Kim 

Hello Nancy, 

I am all for "open" platform and the added value added by the 3rd party developers. However, what we are talking about here (and many other cases), is the basic functionality of any CMS/Wiki system that has existed for ages. I should not be required by Atlassian to go and purchase a host of 3rd party plugins (often of questionable quality, and not always available for the full platform offering) to cobble together a decently working Wiki. It's a huge turn off, and will surely drive the user base away from Atlassian altogether. 

Right now, the only reason to use Confluence for us, is because of integration with Jira, but we are seriously questioning the value there, that surely can be replicated with a few other ecosystem offerings.

Again, basic formatting is NOT a good candidate for a 3rd party offering, in my opinion. It's like if you ordered a BMW, but had to pay extra for a 3rd party door handles, because it didn't have one in the stock offering. 

Hi All,

It seems like a very very long pending issue with Confluence.

I found something that sort of works

http://philarcher.org/diary/2011/numbering/

The script works really really well, except the headings start at 3 and everything (even things in the sidebar) get numbered. It will be awesome if someone can figure out how to get this working. I know that there are free plugins, but they clutter up the document and remove the clarity. If we get this working, we can simply put this into <head> and then bingo, everything is right the way it should be.

window.onload = function () {
  var elements=document.getElementsByTagName('*');
  var numbers=[0,0,0,0,0,0,0];
  for (var i in elements) { 
    var e=elements[i];
    if(!e||!e.tagName||!e.tagName.match(/^H([1-6])$/)){continue}
    var eLevel=RegExp.$1;
    var txt='';
    numbers[eLevel]++;
    for(var l=1;l&lt;=6;l++) {
      if(l&lt;=eLevel){
        txt+=numbers[l]+'.'
      } else {
        numbers[l]=0;
      }
    }
    e.textContent=txt+' '+e.textContent.replace(/^[0-9\.\s]+/,'');
  }
}

To try this,

Put the current script in the HTML macro at the end of the page.

I think we need to change this line

var elements=document.getElementsByTagName('*');

The document should be replaced by something that confluence knows as 'page contents'. Please see if you guys can solve this!

I created a script (copied some code from https://stackoverflow.com/questions/5127017/automatic-numbering-of-headings-h1-h6-using-jquery ) you can use in Confluence editor. You can add the script to usermacro and add the macro to header via space tools -> look and feel.

Hotkey hh and a button in the editor.

<script>

AJS.whenIType('hh').execute(function () { //hotkey
addIndex();
});

function addIndex() {
var indices = [];
jQuery("#wysiwygTextarea_ifr").contents().find("h1,h2,h3").each(function(i,e) { //.find("h1,h2,h3,h4,h5,h6") if you want all headings numbered
var hIndex = parseInt(this.nodeName.substring(1)) - 1;
if (indices.length - 1 > hIndex) {
indices= indices.slice(0, hIndex + 1 );
}
if (indices[hIndex] == undefined) {
indices[hIndex] = 0;
}
indices[hIndex]++;
if(jQuery(this).text().indexOf(indices.join(".")+" ") <0 ){
jQuery(this).prepend(indices.join(".")+" ");
}
});
}

AJS.toInit(function(){
AJS.$('#rte-toolbar > div.aui-toolbar2-primary.toolbar-primary').append('<ul class="aui-buttons"><li class="aui-button" id="addIndex">Number headings</li></ul>')
AJS.$("#addIndex").click(function(e) {
e.preventDefault();
addIndex();
});
});

</script>

Hello Markus, just wanted to thank you. Works great!

Few more tweaks:

  1. Removes old heading numbers
    1. Removes all numbers from the start of the heading (including dates for example)
  2. does not lose inline comments or inline macros
function addIndex() {
var indices = [];
jQuery("#wysiwygTextarea_ifr").contents().find("h1,h2,h3").each(function(i,e) { //.find("h1,h2,h3,h4,h5,h6") if you want all headings numbered
var hIndex = parseInt(this.nodeName.substring(1)) - 1;
if (indices.length - 1 > hIndex) {
indices= indices.slice(0, hIndex + 1 );
}
if (indices[hIndex] == undefined) {
indices[hIndex] = 0;
}
indices[hIndex]++;
var lapset=[];
jQuery(this).children().each(function(){
var text = AJS.$(this).prop('outerHTML');
lapset.push(text);
});
jQuery(this).html(indices.join(".")+". " + removeNo(jQuery(this).text()));
jQuery(this).append(lapset.join(""));

});
}

function removeIndex(){
jQuery("#wysiwygTextarea_ifr").contents().find("h1,h2,h3,h4,h5,h6").each(function(i,e) {
var lapset=[];
jQuery(this).children().each(function(){
var text = AJS.$(this).prop('outerHTML');
lapset.push(text);
});
jQuery(this).text(removeNo(jQuery(this).text()));
jQuery(this).append(lapset.join(""));
});
}

function removeNo(str) {
let newstr = str.trim();
newstr = newstr.replace(/[\u00A0\u1680​\u180e\u2000-\u2009\u200a​\u200b​\u202f\u205f​\u3000]/g,' ');
if(IsNumeric(newstr.substring(0,newstr.indexOf(' ')))){
return newstr.substring(newstr.indexOf(' ')+1).trim();
}
return newstr;
}

function IsNumeric(num) {
num = num.split('.').join("");
return (num >=0 || num < 0);
}

I noticed it also added some dots to the numbering that weren't there before.

Thanks a lot again.

Btw I call the function removeIndex() right before addIndex(). I hope that's the intended usage.

I have a dedicated button for the removeIndex() function that I can use if I want to remove the numbers from headings. You don't have to call the function before addIndex, the addIndex removes the numbers too.

jQuery(this).html(indices.join(".")+". " + removeNo(jQuery(this).text()));
AJS.$('#rte-toolbar > div.aui-toolbar2-primary.toolbar-primary').append('<ul class="aui-buttons"><li class="aui-button aui-button-compact" id="addIndex">Number headings</li><li class="aui-button aui-button-compact" id="removeIndex">remove index</li></ul>')
AJS.$("#addIndex").click(function(e) {
e.preventDefault();
addIndex();
});
AJS.$("#removeIndex").click(function(e) {
e.preventDefault();
removeIndex();
});

Alright, I see it now. Thank you.

Thanks for posting this. I've converted your code into a TamperMonkey script so that those of us without admin access to Confluence can use it.

  1. https://greasyfork.org/en/scripts/381252-confluence-auto-numbered-headings
  2. https://gist.github.com/elahd/28f64feddd9ece56f4f0566d195d0cbd
Like 1 person likes this

Hi All,

We have released Auto Numbered Headings plugin https://marketplace.atlassian.com/1219286  which auto numbers the headings of whole space in single click of button. A macro comes along with plugin in case numbering needs to be applied only on selective pages.

Here is my little solution, using JQuery in the HTML MACRO.

<script type="text/javascript">

function enumerateHeaders() {
    var i1 = 0;
    var i2 = 0;
    var i3 = 0;

    AJS.$("#main-content :header").each( function(indx) {
        hdr = $(this);
        console.log( indx+": "+hdr.text() );
        switch (hdr.prop("tagName")) {
        case "H1":
            i1++; i2=0 ; i3=0;
            hdr.text( i1+") " + hdr.text() );
            break;
        case "H2":
            i2++; i3=0;
            hdr.text( i1+"."+i2+") " + hdr.text() );
            break;
        case "H3":
            i3++;
            hdr.text( i1+"."+i2+"."+i3+") " + hdr.text() );
            break;
        }
    });
}

AJS.toInit(function(){
    enumerateHeaders();
});

</script>

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Thursday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

113 views 0 10
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you