DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:pagebreak

This is an old revision of the document!


Pagebreak

Compatible with DokuWiki

adora belle

plugin Forces ('suggests') a pagebreak after the line where a <pagebreak> tag is inserted

Last updated on
2007-08-08
Provides
Syntax

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to pagebreak2, verinfo, wrap

Tagged with export, printing, typography

Description

This plugin inserts a 'suggested' pagebreak when printing a wiki page. Nothing new is visible from a browser. This seemed like a much needed addition to DokuWiki, since the main use of DokuWiki is documentation. This is intended to help in the creation of hard-copies of a wiki, possibly with some sort of pdf/ps/gs printer.

Use

Insert a <pagebreak> tag on a line by itself where you want a pagebreak. Check with print preview.

Code

syntax.php
<?php
/**
 * Plugin Tab: Inserts a pagebreak into the document for every <pagebreak> it encounters.  Based on the tab plugin by Tim Skoch <timskoch@hotmail.com>
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Jonathan McBride and Chris Sturm - The University of Texas at Austin
 * 
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_pagebreak extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Jonathan McBride and Chris Sturm',
            'email'  => 'j.mcbride@mail.utexas.edu',
            'date'   => '2007-08-08',
            'name'   => 'Pagebreak Plugin',
            'desc'   => 'Inserts " <br style="page-break-after:always;"> " into the html of the document for every <pagebreak> it encounters',
            'url'    => 'NA',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * What kind of syntax do we allow (optional)
     */
//    function getAllowedTypes() {
//        return array();
//    }
 
    /**
     * What about paragraphs? (optional)
     */
//    function getPType(){
//        return 'normal';
//    }
 
    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 999;
    }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern('<pagebreak>',$mode,'plugin_pagebreak');
//      $this->Lexer->addEntryPattern('<TEST>',$mode,'plugin_test');
    }
 
//    function postConnect() {
//      $this->Lexer->addExitPattern('</TEST>','plugin_test');
//    }
 
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        switch ($state) {
          case DOKU_LEXER_ENTER : 
            break;
          case DOKU_LEXER_MATCHED :
            break;
          case DOKU_LEXER_UNMATCHED :
            break;
          case DOKU_LEXER_EXIT :
            break;
          case DOKU_LEXER_SPECIAL :
            break;
        }
        return array();
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $renderer->doc .= "<br style=\"page-break-after:always;\">";            // ptype = 'normal'
//            $renderer->doc .= "<p>Hello World!</p>";     // ptype = 'block'
            return true;
        }
        return false;
    }
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :

Installation

The above code is included in this zip file, which can be imported via the plugin manager. To install manually, create a new folder “lib/plugins/pagebreak”, and create a file “syntax.php” with the above code as its contents.

Discussion

This plugin is hugely based on the tab plugin by Tim Skoch. A good 90% of this is probably his untouched code. Many thanks to Tim for giving us a starting point for this plugin.

There's a problem with the zipped syntax.php: it contains four leading whitespaces on each line, even before the <?php opening tag.
Apart from being bad style this can also break the XMLRPC api: The four whitespaces appear in the generated response, right before the <?xml opening tag. This might cause an error, depending on the xml parser used on the other side. E.g. the DokuJClient API for java projects can't handle the responses (see here). — fmueller 2015-03-10
plugin/pagebreak.1425991848.txt.gz · Last modified: 2015-03-10 13:50 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki