Loading...
 
Skip to main content

Features / Usability


Change heading numbering

Hi,

Is it possible to change the starting number when using heading
so normally "!# heading A", would result in "1. Heading A"

but I need to be able for each page to have the starting number set so it does not start at 1 , so

"!Proc/5 - Test Title"
"{startnum = 5}"

I'm not sure this is possible... the "numbers" for the headings (when using the !#Heading notation) are plain text — not an actual ol element, so there's no easy way to reset the counter. You may have to hard-code the number as part of the heading. 😑

HTH,

- RickQuestion | My Tiki Blog | My Tiki UserPage

Why be a dummy? Get smarty! TikiForSmarties.comQuestion
Tiki for SmartiesQuestion, your source for the best (and only) Tiki books, guides, and tutorials.

If you are willing to modify your Tiki source code, you could add {startnum = 5} functionality to the numbered headings syntax. But, there is a risk that a future upgrade to Tiki would change the code so that you could not make the same modification to the code again.

Update: After more testing, I found the change did not work well when used on different levels (I don't know it this would be useful on other levels though). I also didn't care for the fact that it only worked if it was the first heading with the startnum. So, I made a change to the code that gets added.

Edit the file: lib/parser/parserlib.php
Before this line:

Copy to clipboard
$line_lenght = strlen($line);

I know "length" is spelled incorrectly in the variable name, but that is how it is in the code. That variable also is not used anywhere else in the program.

Add these 2 lines:

Copy to clipboard
preg_match('/{\s*startnum\s*=\s*(\d+)\s*}/',$line,$starthnum); $line=preg_replace('/{\s*startnum.*}/','',$line);

The first line looks for the {startnum=5} string and, if it is present, it puts the starting number specified into the variable $starthnum[1].

The second line removes the "{startnum=5}" text from the heading line.

Those lines must be inserted before the "line_lenght" variable is set, or the value of the "line_lenght" variable will be incorrect. Since it isn't used anywhere else, that may not be a problem, but why risk it.

Then add a third line of code before this line:
Copy to clipboard
$show_title_level[$hdrlevel] = preg_match('/^!+[\+\-]?#/', $line);

Make it:

Copy to clipboard
if ($starthnum[1]) { $hdr_structure[$nb_hdrs][$hdrlevel-1] = $starthnum[1]; } $show_title_level[$hdrlevel] = preg_match('/^!+[\+\-]?#/', $line);

If a startnum was specified, that line sets the start number into the header number structure.

To use it, make your !# heading line like this:
!#{startnum=5}heading A

The {startnum=5} string can be used on any !# heading line, so you can change the number at any time.
Spaces can be used anywhere within the "{startnum=5}" string and the "{startnum=5}" can be anywhere in the heading line. The number will always be at the front of the heading. To have the number display somewhere else in the heading text ("!Proc/5 - Test Title") would require a much larger modification to the code. If you want to do that, then you should look into creating a plugin instead.

There isn't any error checking, but if you don't specify a valid number to start with, the "{startnum=?}" string should still be removed from the heading line, and the numbering will default to 1.

The lines of code where this change is made are the same in Tiki 8 thru Tiki 12 (and currently Tiki 13 and Tiki trunk))Image , so you might be able to make the same change to any future Tiki versions you upgrade to.

Tom