DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:reproduce

Reproduce Plugin

Compatible with DokuWiki

2012-01-25 "Angua", 2012-10-13 "Adora Belle"

plugin This plugin allows to reproduce a code marked with a label, located within the same source page or in an other source page specified by its ID

Last updated on
2012-07-18
Provides
Syntax
Requires
label

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

Tagged with copy, label, replicate, reproduce

Requirements

This plugin requires Label Plugin, writen by Pascal Bihler.

Syntax and Use

<reproduce LABEL [PAGEID] />
  • Where LABEL refers to a label name defined with <label NAME> ... </label> (see Label Plugin).
    • Where NAME is an identifier consisting of letters (a-z, A-Z), number (0-9) and underscore (_).
    • Where ... refers to the wikicode to reproduce.
  • Where [PAGEID] (optional) refers to a source page ID, consisting of letters (a-z, A-Z), number (0-9), underscore (_), dash (-) and colon (:).
    • If PAGEID is omitted, the current page will be used as the source.

Example 1

<label table1>
^ ID    ^ Description ^
| Lorem | Ipsum       |
| dolor | sit amet.   |
</label>

  (some code ...)

<reproduce table1 />

Example 2

The <reproduce ... /> tag can be placed before source label.

<reproduce table1 />

  (some code ...)

<label table1>
^ ID    ^ Description ^
| Lorem | Ipsum       |
| dolor | sit amet.   |
</label>

Example 3

If the wikicode to reproduce is located in the wikipage « report:page1 », then …

<reproduce table1 report:page1 />

Code

syntax.php
<?php
/**
 * DokuWiki Plugin reproduce (Syntax Component)
 *
 * @description  :  This plugin allows to reproduce a code marked with a label
 *                  located within the same source page, or in an other source
 *                  page specified by its ID.
 *
 * @requires     :  "Plugin label", writen by Pascal Bihler <bihler@iai.uni-bonn.de>.
 *
 * @sytnax       :  <reproduce LABEL [PAGEID] />
 *                      --> Where LABEL refers to a label name defined with <label NAME> ... </label>.
 *                          --> Where NAME matches the regular expression [a-zA-Z0-9_]+
 *                          --> Where ... refers to the code to reproduce.
 *                      --> Where [PAGEID] (optional) refers to a source page ID
 *                          that matches the regular expression [a-zA-Z0-9_:-]*.
 *                          If PAGEID is omitted, the current page will be used.
 *
 * @license       :  GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author        :  Patrice Bonneau <patrice.bonneau@live.ca>
 * @lastupdate    :  2012-07-18
 * @compatible    :  2012-01-25 "Angua"
 */
 
// must be run within Dokuwiki
if (!defined('DOKU_INC'))     die();
if (!defined('DOKU_LF'))      define('DOKU_LF', "\n");
if (!defined('DOKU_TAB'))     define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN'))  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
require_once DOKU_PLUGIN.'syntax.php';
 
 
class syntax_plugin_reproduce extends DokuWiki_Syntax_Plugin {
 
    var $LABEL_PATTERN = "[a-zA-Z0-9_]+";
    var $PAGE_ID_PATTERN = "[a-zA-Z0-9_:-]*";
 
 
    public function getType()    { return 'substition'; }
    public function getPType()   { return 'normal'; }
    public function getSort()    { return 100; }
    public function getInfo()    {
        return array(
            'author' => 'Patrice Bonneau',
            'email'  => 'patrice.bonneau@live.ca',
            'date'   => '2012-05-18',
            'name'   => 'Reproduce Plugin',
            'desc'   => 'Allows to reproduce a code marked with a label located within the same source page, or in an other source page specified by its ID.',
            'url'    => 'http://www.dokuwiki.org/plugin:reproduce',
        );
    }
 
 
    public function connectTo($mode) {
        $this->Lexer->addSpecialPattern('<reproduce\s+' . $this->LABEL_PATTERN . '\s*' . $this->PAGE_ID_PATTERN . '\s*/>', $mode, 'plugin_reproduce');
    }
 
 
    public function handle($match, $state, $pos, &$handler){
        switch ($state) {
            case DOKU_LEXER_SPECIAL :
 
                // Find the label name and the optional source page ID in the <reproduce ... /> tag
                if (preg_match('/<reproduce\s+(' . $this->LABEL_PATTERN . ')\s*(' . $this->PAGE_ID_PATTERN . ')\s*\/>/', $match, $matches)) {
                    $labelName = $matches[1];
                    $sourcePageID = $matches[2];
 
                    if (!empty($sourcePageID)) {
                        $sourcePageContent = io_readfile(wikiFN($sourcePageID));
                    } else {
                        // Load the source code of the current DokuWiki page
                        global $ID;        // This is the current page ID
                        $sourcePageContent = io_readfile(wikiFN($ID));
                    }
 
                    // To be compatible with the plugin « autonumbering ».
                    // This will make sure to keep the original numbering and not restart
                    // numbering at 1, by doing the numbering before to reproduce the code.
                    $pluginList = plugin_list();
                    if (in_array('autonumbering', $pluginList)) {
                        $autonumbering = new syntax_plugin_autonumbering();
                        $sourcePageContent = $autonumbering->doNumbering($sourcePageContent);
                    }
 
                    // Find the corresponding <label> and get its content
                    if (preg_match('/<label\s+' . $labelName . '\s*>(.*?)<\/label>/ms', $sourcePageContent, $matches)) {
                        $labelContent = $matches[1];
                    } else {
                        $labelContent = '\\\ 
| @orange:**ERROR !**         | @orange:The source for **%%' . $match . '%%** can\'t be found. |
| @yellow:\\\ **Syntax : **%%<reproduce LABEL [PAGEID] />%% \\\ \\\ --- Where LABEL refers to a label name defined with %%<label NAME> ... </label>%%. \\\ --------- Where NAME is an identifier consisting of letters (a-z, A-Z), number (0-9) and underscore (_). \\\ --------- Where **...** refers to the wikicode to reproduce. \\\ \\\ --- Where [PAGEID] (optional) refers to a source page ID, consisting of letters (a-z, A-Z), number (0-9), underscore (_) and a colon (:). \\\ --------- If PAGEID is omitted, the current page will be used. \\\\ \\\ ||
|  @orange:**Contact your admin.**  ||
\\\ 
\\\ 
';
                    }
                    return array($labelName, $labelContent);
                }
            break;
        }
        return array();
    }
 
 
    public function render($mode, &$renderer, $data) {
        if(($mode == 'xhtml') && (!empty($data))) {
            list($labelName, $labelContent) = $data;
            $renderer->doc .= p_render('xhtml', p_get_instructions($labelContent), $info);
            return true;
        }
        return false;
    }
}

Bugs

After changing what was in label, the reproduce is not automatically show the new content, You need to change somethine on page where the reproduce is invoked to show the changes made in label (especially when reproduce is being invoked for other page). — Sebastian Szary 2013/04/05 00:29

plugin/reproduce.txt · Last modified: 2018-05-20 17:06 by Aleksandr

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