Loading...
 
Features / Usability

Features / Usability


Re: Change heading numbering

posts: 214

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 Update: The code that creates the auto numbered headings was added in Tiki 2 and was originally in lib/tikilib.php. It was moved to lib/parser/parserlib.php in Tiki 8. The code has been essentially the same for a long time., so you might be able to make the same change to any future Tiki versions you upgrade to.

Tom

There are no comments at this time.

Upcoming Events

1)  18 Apr 2024 14:00 GMT-0000
Tiki Roundtable Meeting
2)  16 May 2024 14:00 GMT-0000
Tiki Roundtable Meeting
3)  20 Jun 2024 14:00 GMT-0000
Tiki Roundtable Meeting
4)  18 Jul 2024 14:00 GMT-0000
Tiki Roundtable Meeting
5)  15 Aug 2024 14:00 GMT-0000
Tiki Roundtable Meeting
6)  19 Sep 2024 14:00 GMT-0000
Tiki Roundtable Meeting
7) 
Tiki birthday
8)  17 Oct 2024 14:00 GMT-0000
Tiki Roundtable Meeting
9)  21 Nov 2024 14:00 GMT-0000
Tiki Roundtable Meeting
10)  19 Dec 2024 14:00 GMT-0000
Tiki Roundtable Meeting