Not logged in. · Lost password · Register
Forum: General Help and Support Plugins RSS
Plugin development - Problem with 'Headline'
Avatar
PatB73 #1
Member since May 2012 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: Plugin development - Problem with 'Headline'
Hi everybody,

I developed a plugin (syntax) which allows automatic numbering. It works well, but not in the "Headline". I tried changing the return values ​​of the "getSort ()" function, but without success. English is not my first language ... so the documentation is a bit heavy to read for me.

Would someone have an idea?
You can find the code of my plugin at: https://www.dokuwiki.org/plugin:autonumbering.

For example, this code works well :
    This is line number ~~#~~
    This is line number ~~#~~
The result will be :
    This is line number 1
    This is line number 2

But not this one :
    ===== This is line number ~~#~~ =====


Thanks
Pat
Avatar
turnermm (Moderator) #2
Member since Oct 2009 · 4402 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
Because of the way headers are processed, anything found on the heading line will be treated as text and become part of the headline text.  And nothing except the header can be included on the header line -- it must be at the left-hand margin and can't have anything on the same line coming after:
=====header===== will fail
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
PatB73 #3
Member since May 2012 · 4 posts
Group memberships: Members
Show profile · Link to this post
So I'll forget the idea.
Thanks for your answer.

Regards
Avatar
nocnoc #4
Member since Mar 2013 · 2 posts
Group memberships: Members
Show profile · Link to this post
Too bad. This is a really useful plug-in, when it could also be used to enumerate headings. Someone else any ideas how to fix this?
Avatar
nocnoc #5
Member since Mar 2013 · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: Autonum headings modification
Because I really needed this function, I decided to develop my own. It was indeed a daunting task to reverse engineer, but I finally got it working. I use jQuery to do the job. Here's the code:


<?php
 /**
  * autonumber headings in DokuWiki modification, by nocnoc.
  *
  * Add this script to /lib/tpl/dokuwiki/main.php line92 just below <!-- /site -->
  *
  * @description         :   This modification allows autonumbering the headings
  *                          with multiples levels, within the same DokuWiki page.
  *
  * @syntax (Base)       :   ~~#~~
  *                              --> Where ~~#~~ will be replaced by a number.
  *                                  Auto increments on multiple usage within page.
  *                                  Use this when you require autonumbered headings.
  *
  * @syntax (multilevel) :   ~~##~~ or ~~###~~ or ~~####~~ or ~~#####~~
  *                              --> Where the num of # represent a sublevel and can be
  *                                  repeated up to 5 levels corresponding
  *                                  the 5 heading levels within DokuWiki.
  *
  * don't forget to make the following changes to /inc/html.php:
  *
  *     line237 FIND:       if($INFO['prependTOC']) $html = tpl_toc(true).$html;
  *     ABOVE ADD:          $html = '<div id="nocnoc">'.$html.'</div>';
  *
  *     line246 FIND:       if($INFO['prependTOC']) $html = tpl_toc(true).$html;
  *     ABOVE ADD:          $html = '<div id="nocnoc">'.$html.'</div>';
  *
  *     line1745 FIND:      $out .= '<div>'.DOKU_LF;
  *     CHANGE TO:          $out .= '<div><div id="toctoc">'.DOKU_LF;
  *
  *     Line1749 FIND:      $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
  *     CHANGE TO:          $out .= '</div></div>'.DOKU_LF.'</div>'.DOKU_LF;
  *
  *
  * @license             :   GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
  * @author              :   nocnoc - feel free to modify
  * @lastupdate          :   2013-03-17
  * @compatible          :   2012-10-13 "Adora Belle"
  */
?>
<script>
    //count the number of occurences
    function count( string, subString ) {
        if( subString.length <= 0 ) return string.length + 1;
        var n = 0, pos = 0;
        while(true){
            pos = string.indexOf(subString,pos);
            if(pos >= 0){ n++; pos+=1; } else break;
        }
        return(n);
    }
    //the autonumbering conversion function
    function autonumHeadings(s) {
        var a=0, b=0, c=0, d=0, e=0;
            var o=jQuery(s).html().split('\n'); //array of lines in o
            for (var i=0;i<o.length;i++) {  //scan every line
                var x=o[i].match(/~~#+~~/g);
                if ( x!=null ) {
                    x=x.toString();
                    if ( count(x,"#") == 5 ) {  e++; o[i] = o[i].replace(/~~#####~~/g, a + '.' + b + '.' + c + '.' + d + '.' + e + '. ' ); }
                    if ( count(x,"#") == 4 ) {  d++; o[i] = o[i].replace(/~~####~~/g, a + '.' + b + '.' + c + '.' + d + '. ' ); e=0; }
                    if ( count(x,"#") == 3 ) {  c++; o[i] = o[i].replace(/~~###~~/g, a + '.' + b + '.' + c + '. ' ); d = 0, e = 0; }
                    if ( count(x,"#") == 2 ) {  b++; o[i] = o[i].replace(/~~##~~/g, a+ '.' + b + '. ' ); c = 0, d = 0, e = 0; }
                    if ( count(x,"#") == 1 ) {  a++; o[i] = o[i].replace(/~~#~~/g, a + '. ' ); b = 0, c = 0, d = 0, e = 0;  }
                }
            }
            jQuery(s).html(o.join('\n'));
    }
    jQuery( function() {
        // don't forget to define the nocnoc & toctoc divs in the /inc/html.php, please see the instructions above !!!     
        if (jQuery('#dokuwiki__content').html().indexOf('<div id="toctoc">') != -1) autonumHeadings('#toctoc'); //skip pages with ~~NOTOC~~
        if (jQuery('#dokuwiki__content').html().indexOf('<div id="nocnoc">') != -1) autonumHeadings('#nocnoc'); //skip pages lacking nocnoc div
    });     //fire it up when the DOM is ready
   
</script>   <!-- end of autonumber headings in DokuWiki modification -->

cheers!
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2018-12-19, 03:09:44 (UTC +01:00)