DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:hidetext

Table of Contents

hidetext Plugin

Compatible with DokuWiki

2009-02-14b

plugin For hiding big text

Last updated on
2019-09-02
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 folded, hidden, outliner

Tagged with collapsible, hide

This plug-in allows to hide the big text.

Usage

<hidetext [some text]> Bla-bla-bla </hidetext>

  • Example 1
<hidetext info> This text is hidden </hidetext>

Result: info

  • Example 2
<hidetext> This text is hidden </hidetext>  

Result: > > >

Installation

Create a new directory hidetext inside your lib/plugins/ directory, and then copy the following source into syntax.php in that directory (/lib/plugins/hidetext/syntax.php):

For PHP 7:

/hidetext/syntax.php
<?php
/**
 * Plugin HideText: hiding big text <hidetext></hidetext>
 * @license    GPL2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Dmitry A. Vinogradov <vshekun@gmail.com>
 * Updated     Florin Chitiul, 2019-09-02
 * Format: <hidetext [some text]> Bla-bla-bla </hidetext>
 * Examples: <hidetext info> This text is hidden </hidetext>
 *           <hidetext> This text is hidden </hidetext> 
 */
 
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_hidetext extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Dmitry A. Vinogradov',
            'email'  => 'vshekun@gmail.com',
            'date'   => '2009-09-28',
            'name'   => 'HideText',
            'desc'   => 'for hiding big text',
            'url'    => 'http://www.dokuwiki.org/plugin:hidetext',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'formatting';
    }
   function getAllowedTypes() { 
      return array('container', 'formatting', 'substition', 'disabled', 'protected'); 
   }   
 
    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 201;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<hidetext *[^>]*>',$mode,'plugin_hidetext');
    }
 
    function postConnect() {
        $this->Lexer->addExitPattern('</hidetext>','plugin_hidetext');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, Doku_Handler $handler){
        switch ($state) {
            case DOKU_LEXER_ENTER : 
            return array($state, substr($match, 9, -1) );
            break;
            case DOKU_LEXER_UNMATCHED :
                return array($state, $match);
            break;
            case DOKU_LEXER_EXIT :
                return array($state, '');
            break;
        }
        return array();
    }
 
    /**
     * Create output
     */
    function render($mode, Doku_Renderer $renderer, $data) {
        if($mode == 'xhtml'){
 
           list($state, $match) = $data;
            switch ($state) {
                case DOKU_LEXER_ENTER :    
                    if ( $match == "" ) $match = '>>>';
                    $id = "hidetext".rand(100,500);
                    $renderer->doc .= "<span style=\"cursor:pointer;text-decoration: underline;\" onClick=\"with( document.getElementById('$id').style ){if ( display == 'block' ){ display = 'none' } else { display = 'block' };}\">";
                    $renderer->doc .= $match;
                    $renderer->doc .= "</span>";
                    $renderer->doc .= "<div id='$id' style=\"display: hide;\">";
                    $renderer->doc .= "<script type=\"text/javascript\">document.getElementById('$id').style.display='none';</script>";
                    break;
                case DOKU_LEXER_UNMATCHED :
                    $renderer->doc .= $renderer->_xmlEntities($match);
                    break;
                case DOKU_LEXER_EXIT :
                    $renderer->doc .= "</div>";
                    break;
            }
            return true;
        }
        return false;
    }
}
?>



For PHP 5 and 6:

/hidetext/syntax.php
<?php
/**
 * Plugin HideText: hiding big text <hidetext></hidetext>
 * 
 * @license    GPL2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Dmitry A. Vinogradov <vshekun@gmail.com>
 * 
 * Format: <hidetext [some text]> Bla-bla-bla </hidetext>
 * Examples: <hidetext info> This text is hidden </hidetext>
 *           <hidetext> This text is hidden </hidetext> 
 */
 
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_hidetext extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Dmitry A. Vinogradov',
            'email'  => 'vshekun@gmail.com',
            'date'   => '2009-09-28',
            'name'   => 'HideText',
            'desc'   => 'For hiding big text',
            'url'    => 'https://www.dokuwiki.org/plugin:hidetext',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'formatting';
    }
   function getAllowedTypes() { 
      return array('container', 'formatting', 'substition', 'disabled', 'protected'); 
   }   
 
    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 201;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<hidetext *[^>]*>',$mode,'plugin_hidetext');
    }
 
    function postConnect() {
        $this->Lexer->addExitPattern('</hidetext>','plugin_hidetext');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        switch ($state) {
            case DOKU_LEXER_ENTER : 
            return array($state, substr($match, 9, -1) );
            break;
            case DOKU_LEXER_UNMATCHED :
                return array($state, $match);
            break;
            case DOKU_LEXER_EXIT :
                return array($state, '');
            break;
        }
        return array();
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
 
           list($state, $match) = $data;
            switch ($state) {
                case DOKU_LEXER_ENTER :    
                    if ( $match == "" ) $match = '>>>';
                    $id = "hidetext".rand(100,500);
                    $renderer->doc .= "<span style=\"cursor:pointer;text-decoration: underline;\" onClick=\"with( document.getElementById('$id').style ){if ( display == 'block' ){ display = 'none' } else { display = 'block' };}\">";
                    $renderer->doc .= $match;
                    $renderer->doc .= "</span>";
                    $renderer->doc .= "<div id='$id' style=\"display: hide;\">";
                    $renderer->doc .= "<script type=\"text/javascript\">document.getElementById('$id').style.display='none';</script>";
                    break;
                case DOKU_LEXER_UNMATCHED :
                    $renderer->doc .= $renderer->_xmlEntities($match);
                    break;
                case DOKU_LEXER_EXIT :
                    $renderer->doc .= "</div>";
                    break;
            }
            return true;
        }
        return false;
    }
}
plugin/hidetext.txt · Last modified: 2020-07-17 00:51 by florious

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