DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:xterm2

xterm2 plugin

Compatible with DokuWiki

2009-02-14

plugin FIXME

Last updated on
2009-05-18
Provides
Syntax

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 cli, note, xterm

Tagged with code, formatting

Download and Installation

Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.

Show the plugin in action : http://wiki.opensi.org/doku.php?id=playground:playground

About

This plugin is totally derived from the note plugin.

Thanks to the authors of the note plugin

FIXME Complete the page

Code

<?php
/**
 * Add Note capability to DokuWiki
 *
 * <xterm2>This is a console</xterm2>
 * <xterm2 root>This is a ROOT console</xterm2>
 *
 * Authors of the note plugin
 *----------------------------*
 * by Olivier Cortès <olive@deep-ocean.net>
 * under the terms of the GNU GPL v2.
 *
 * Originally derived from the work of :
 * Stephane Chamberland <stephane.chamberland@ec.gc.ca> (Side Notes PlugIn)
 * Carl-Christian Salvesen <calle@ioslo.net> (Graphviz plugin)
 *
 * Contributions by Eric Hameleers <alien [at] slackware [dot] com> :
 *   use <div> instead of <table>,
 *   contain the images and stylesheet inside the plugin,
 *   permit nesting of notes,
 *
 * Contributed by Christopher Smith <chris [at] jalakai [dot] co [dot] uk>
 *   fix some parsing problems and a security hole.
 *   make note types case independent
 *   simplify code reading
 *   modernise the plugin for changes/fixes/improvements to the underlying Dokuwiki plugin class,
 *   improve efficiency.
 *
 * Contributed by Aurélien Bompard <aurelien [at] bompard [dot] org>
 *   support for the ODT output format.
 *
 * @license    GNU_GPL_v2
 * @author     Olivier Cortes <olive@deep-ocean.net>
 */
 
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');
 
 
class syntax_plugin_xterm2 extends DokuWiki_Syntax_Plugin {
 
    var $notes = array(
		'xterm2user'	=> array('', 'user'),
		'xterm2root'	=> array('root', 'admin')
      );
 
    var $default = 'xterm2user';
 
    function getInfo(){
        return array(
            'author' => 'Olivier Cortès / Eric Hameleers / Christopher Smith / Aurélien Bompard',
            'email'  => 'olive@deep-ocean.net',
            'date'   => '2006-03-29',
            'name'   => 'Xterm2 Plugin',
            'desc'   => 'Add console root or user Capability <xterm2 root> for root console(DIV+CSS box)\n Adapted by Xarkam',
            'url'    => 'http://wiki.splitbrain.org/plugin:xterm2',
        );
    }
 
 
    function getType(){ return 'container'; }
    function getPType(){ return 'normal'; }
    function getAllowedTypes() { 
        return array('container','substition','protected','disabled','formatting','paragraphs');
    }
    function getSort(){ return 195; }
 
    // override default accepts() method to allow nesting 
    // - ie, to get the plugin accepts its own entry syntax
    function accepts($mode) {
      if ($mode == substr(get_class($this), 7)) return true;
        return parent::accepts($mode);
      }
 
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<xterm2.*?>(?=.*?</xterm2>)',$mode,'plugin_xterm2');
    }
    function postConnect() {
        $this->Lexer->addExitPattern('</xterm2>','plugin_xterm2');
    }
 
    function handle($match, $state, $pos, &$handler){
 
        switch ($state) {
 
          case DOKU_LEXER_ENTER : 
            $note = strtolower(trim(substr($match,7,-1)));
 
            foreach( $this->notes as $class => $names ) {
              if (in_array($note, $names))
                return array($state, $class);
            }            
 
            return array($state, $this->default);          
 
          case DOKU_LEXER_UNMATCHED :
            return array($state, $match);
 
          default:
            return array($state);
        }
    }
 
    function render($mode, &$renderer, $indata) {
 
        if($mode == 'xhtml'){
 
          list($state, $data) = $indata;
 
          switch ($state) {
            case DOKU_LEXER_ENTER :
              $renderer->doc .= '<pre class="'.$data.'">';
              break;
 
            case DOKU_LEXER_UNMATCHED :
              $renderer->doc .= $renderer->_xmlEntities($data);
              break;
 
            case DOKU_LEXER_EXIT :
              $renderer->doc .= "</pre>";
              break;
          }
          return true;
 
        }         
        // unsupported $mode
        return false;
    } 
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>

Css

div.dokuwiki pre.xterm2user {
  background-image: url(images/terminal.png);
  background-repeat: no-repeat;
  /*background-attachment:fixed;*/
  background-position: 6px 50%;
  font-family:"Lucida Console",Monospace,"DejaVu Sans Mono","Courier New",MiscFixed;
  font-size: 12px;
  white-space:pre;
  padding: 0.5em;
  border: 1px #CCCCCC;
  border-style: solid none;
  color: #000000;
  overflow: auto;
  padding-left: 60px;
  background-color: #E9E9FF;
  min-height: 40px;
}
 
div.dokuwiki pre.xterm2root {
  background-image: url(images/terminal.png);
  background-repeat: no-repeat;
  /*background-attachment:fixed;*/
  background-position: 6px 50%;
  font-family:"Lucida Console",Monospace,"DejaVu Sans Mono","Courier New",MiscFixed;
  font-size: 12px;
  white-space:pre;
  padding: 0.5em;
  border: 1px #CCCCCC;
  border-style: solid none;
  color: #000000;
  overflow: auto;
  padding-left: 60px;
  background-color: #FFE9E9;
  min-height: 40px;
}

Discussion

ok, there are a lot of bugs in current version (05.07.2009):

  • www-links inside will be formatted like normal external links. that isn't like a terminal
  • repeated asterisk will be shown as a single-asterisk (not handled, that ** is a shortcut for bold text)
  • lines with 2 starting blanks become a new own box → see non-parsing blocks
  • commands containing 2 slashes (eg: dvd:) “destroy” box
plugin/xterm2.txt · Last modified: 2014-03-20 17:45 by Aleksandr