Numbered Headings

Last modified by Clemens Robbenhaar on 2024/07/08 00:04

cogDisplays numbered headings in the wiki
TypeXAR
Category
Developed by

Jeremie Bousquet

Active Installs45
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

Check the Numbered Headings Application which provides more features and is more recent.

Insert the following in your page to have the headings automatically numbered:

{{numberedheadings/}}

To extend this to the whole wiki:

  • edit objects of page Macros.NumberedHeadingsStylesheetExtensionMacro
  • navigate to the XWiki.StyleSheetExtension object
  • choose "Use this extension" : "Always" instead of "On demand"
  • Then all headings will be numbered without need of adding the {{numberedheadings/}} in each page

Sample result:

numberedheadings.png

This macro was greatly inspired by this thread. Only small bits were done to adapt it to XWiki.

Implementation

This macro adds the following CSS to the page where it's used:

#xwikicontent {
   counter-reset: mynum-h1 !important;
}

#xwikicontent h1 {
   counter-reset: mynum-h2 !important;
}

#xwikicontent h1:before {
   content: counter(mynum-h1) " " !important;
   counter-increment: mynum-h1 !important;
}


#xwikicontent h2 {
   counter-reset: mynum-h3 !important;
}

#xwikicontent h2:before {
   content: counter(mynum-h1) "." counter(mynum-h2) " " !important;
   counter-increment: mynum-h2 !important;
}

#xwikicontent h3 {
   counter-reset: mynum-h4 !important;
}

#xwikicontent h3:before {
   content: counter(mynum-h1) "." counter(mynum-h2) "." counter(mynum-h3) " " !important;
   counter-increment: mynum-h3 !important;
}

#xwikicontent h4 {
   counter-reset: mynum-h5 !important;
}

#xwikicontent h4:before {
   content: counter(mynum-h1) "." counter(mynum-h2) "." counter(mynum-h3) "." counter(mynum-h4) " " !important;
   counter-increment: mynum-h4 !important;
}

#xwikicontent h5 {
   counter-reset: mynum-h6 !important;
}

#xwikicontent h5:before {
   content: counter(mynum-h1) "." counter(mynum-h2) "." counter(mynum-h3) "." counter(mynum-h4) "." counter(mynum-h5) " " !important;
   counter-increment: mynum-h5 !important;
}

#xwikicontent h6 {

}

#xwikicontent h6:before {
   content: counter(mynum-h1) "." counter(mynum-h2) "." counter(mynum-h3) "." counter(mynum-h4) "." counter(mynum-h5) "." counter(mynum-h6) " " !important;
   counter-increment: mynum-h6 !important;
}

Release Notes

v1.2

  • fix missing space between number and text as pointed out by this comment
  • macro page is now hidden by default and macro visibility is set to current wiki. Please use "Install on Farm" instead to make it available globally. 

v1.1

bugfix : version 1.0 was not working due to badly renamed page ...

v1.0

Initial release

Get Connected