Is it possible to add numbering to headings in Confluence?

Mick Davidson July 30, 2012

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.

12 answers

1 accepted

8 votes
Answer accepted
Amalia
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2012

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

Mick Davidson July 30, 2012

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

Dmitry Pashkevich October 19, 2013

But it's not available for OnDemand instances :(

Gert-Jan van de Streek May 26, 2014

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

Maarten Arts
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 28, 2018

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

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

Jian Yao June 25, 2018

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?

Maarten Arts
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

@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.

35 votes
Arkadiy Birger March 19, 2019

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. 

Kimi March 23, 2019

Indeed!

Like # people like this
Nancy Jaiswal March 23, 2019

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.

Kimi March 24, 2019

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

Like # people like this
Nancy Jaiswal March 24, 2019

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

Kimi March 24, 2019

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 

Arkadiy Birger March 25, 2019

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. 

Like # people like this
Carl Dunham June 19, 2019

Are you really surprised? They refuse to support inserting tab characters without a plugin.

Like Mubed likes this
Katharina Fenner October 30, 2019

Hi guys,

i've been following your discussion here and wondering if there's still no other way for the numbered headings problem except the plugin or complicated hacks.

I hope every month for a good news in "Whats new in confluence cloud" :)

 

Do you happen to know something about it?

 

thanks

Katharina

Like # people like this
Nancy Jaiswal November 3, 2019

Hi Katharina,

Unfortunately till now there is no inbuilt direct way of getting headings numbered  in my knowledge.

Thanks,

Nancy

Katharina Fenner November 4, 2019

Hi Nany,

 

that is more than a pity.

 

thanks for your help.

Like Karl Jamaels likes this
Bartosz Barwikowski April 28, 2021

I totally agree, it's a shame that such simple feature is not supported by default.

13 votes
Florian Proksch February 28, 2018

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) " ";
}
Andy Ackermann March 21, 2018

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?

EEAS May 31, 2018

Very nice, thank you

Jian Yao June 25, 2018

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

Mike Roels October 5, 2018

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?

Richard Colvin December 4, 2019

If you place an "html" macro at the top of the page and include the noted css inside a <style></style> block inside the macro then it will work for that page only.

Alternatively, the "html" macro can be added to an otherwise empty page and then use the "Include page" macro to include this page. Advantage: any changes made to the style in included page will rendered all pages where it is included.

Like # people like this
Michel_Levy January 6, 2020

It works amazing good for me!

Thanks so much for providing this free solution!

Filip Pokorny January 27, 2020

If you'd like the same for editing, copy the same for the .contentLayout2 class. For instance the last chunk would look like following:

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

What's more interesting that this doesn't always work with sections and on some places skips (just some!!). I don't get it, perhaps there really is a CSS magic among us.

image.png

andreasgounaris October 16, 2020

Great suggestion.

Following up on @Richard Colvin for applying in selected pages, is it possible to create a no-body custom macro and declare the <style></style> in it?

In this way you could skip enabling the HTML macro for security reasons.

Florent R_ April 15, 2021

Thanks, it's working perfectly ! But I changed the id and the class to not affect the comments section :

 

#main-content.wiki-content {
/* Set "title1" to 0 */
counter-reset: title1;
}
#main-content.wiki-content h1 {
/* Set "title2" to 0 */
counter-reset: title2;
}
#main-content.wiki-content h2 {
/* Set "title3" to 0 */
counter-reset: title3;
}
#main-content.wiki-content h3 {
/* Set "title4" to 0 */
counter-reset: title4;
}
#main-content.wiki-content h4 {
/* Set "title5" to 0 */
counter-reset: title5;
}
#main-content.wiki-content h5 {
/* Set "title6" to 0 */
counter-reset: title6;
}




#main-content.wiki-content h1:before {
/* Increment "title1" by 1 */
counter-increment: title1;
content: counter(title1) ". ";
}
#main-content.wiki-content h2:before {
/* Increment "title2" by 1 */
counter-increment: title2;
content: counter(title1) "." counter(title2) ". ";
}
#main-content.wiki-content h3:before {
/* Increment "title3" by 1 */
counter-increment: title3;
content: counter(title1) "." counter(title2) "." counter(title3) ". ";
}
#main-content.wiki-content h4:before {
/* Increment "title4" by 1 */
counter-increment: title4;
content: counter(title1) "." counter(title2) "." counter(title3) "." counter(title4) ". ";
}
#main-content.wiki-content h5:before {
/* Increment "title5" by 1 */
counter-increment: title5;
content: counter(title1) "." counter(title2) "." counter(title3) "." counter(title4) "." counter(title5) ". ";
}
#main-content.wiki-content h6:before {
/* Increment "title6" by 1 */
counter-increment: title6;
content: counter(title1) "." counter(title2) "." counter(title3) "." counter(title4) "." counter(title5) "." counter(title6) ". ";
}

 

9 votes
Precision Plugins September 8, 2014

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

David Meyer April 30, 2021

This plugin still not supported in Cloud.
Atlassian has known about this issue for a decade and still makes it another required co$t. I'm not a coder so adding a stylesheet and code as described below isn't really an option. 

4 votes
Nick van der Net February 28, 2021

It is absolutely ridiculous that in 2021 numbered headings and text size differences aren't supported natively. It's not the 20th century anymore. What's next, Atlassian? Smoke signals.

Poor form....

Mike March 23, 2021

totally agree

Like # people like this
2 votes
Shoham Levy October 29, 2018

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>
andreasgounaris October 18, 2020

Nice!

This approach covers TOC as well, where you can include/exclude sections and subsections via regex provided by the TOC macro.

1 vote
Christian Sprenger February 28, 2021

As all tickets gets automatically resolved in 3 years, I'll sign myself out from these tickets.

Good-Bye Confluence Server

1 vote
Dmitry Pashkevich November 2, 2013

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

Gert-Jan van de Streek May 26, 2014

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

Maarten Arts
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2015

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/

1 vote
Dmitry Pashkevich October 19, 2013
0 votes
Nancy Jaiswal September 11, 2018

Hi All,

We have released Auto Numbered Headings plugin https://marketplace.atlassian.com/apps/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.

Christian Sprenger May 27, 2019

The link does not work (anymore).

Maarten Arts
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 27, 2019

@Chri Brunumbering all headings in a whole space is also available on the Server and Data Center version of Numbered Headings. https://marketplace.atlassian.com/apps/16063

Christian Sprenger May 27, 2019

Oh, OK, this one I know, but I don't have budget for the plugin.

Anyway, thanks for the new link :)

Maarten Arts
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 27, 2019

The app that Nancy posted about 'Auto Numbered Headings' can be found here: https://marketplace.atlassian.com/apps/1219286.

I shared the link to an alternative in my previous reply, since it looked like the app wasn't available.

Like Christian Sprenger likes this
Christian Sprenger May 27, 2019

Cool, thanks for that, I'll look into that :)

Aasha November 9, 2020

@markusjenu   - Could you please provide step by step to add this code in in confluence

I am trying to replace numbered heading addon in confluence. Could you please help us with this.

Eric Hansen December 23, 2020

I've been using the add-on for a while now, mostly with success, but recently, pages that were created 12-15 months ago now behave very strangely when I try to edit.  The page flashes and scrolls elsewhere every time I make a single key-stroke.   It is completely unusable.  Perhaps this is due to changes Atlassian has rolled out in the cloud but the add-on is no fully compatible with. 

I will be reaching out to the add-on supplier for an explanation/fix , but wanted to raise my hand in vote that this functionality should be fundamental / native in Confluence.

0 votes
Markus October 3, 2017

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>
lubos tapusik December 22, 2017

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

Markus December 22, 2017

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);
}
Like Kumar Vishwanathan likes this
lubos tapusik December 22, 2017

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.

Markus December 22, 2017

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();
});
lubos tapusik December 22, 2017

Alright, I see it now. Thank you.

Elahd Bar-Shai April 1, 2019

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 Markus likes this
Jean-Marc Pascal June 11, 2021

Hello @markusjenu ,

I am new in installing this. Installation successful but seems not working on current Confluence Cloud version: I don't see the icon in the menu bar:

Confluence editor menu bar.PNG

Best Regards.

0 votes
Vijay Patil February 4, 2016

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!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events