DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:ltr

LTR Plugin

Compatible with DokuWiki

No compatibility info given!

plugin Left to right block when in RTL (eg. hebrew) setup.

Last updated on
2007-01-21
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.

Tagged with language

I set up a DokuWiki for personal use in Hebrew. This serves for both Hebrew and English articles. The problem was that there was no way to have content in a left-to-right direction as all pages were governed by a general RTL directive… I ended up writing a small plugin adding <LTR> and </LTR> tags to allow for a section to be displayed left to right (ie. English). I based it on the demo example (color) from the plugins tutorial.

Something I was not able to figure out is why I can't get the headings to work in it (for some reason they are left unparsed). If anyone can give me insight on this, I'd appreciate it.

Another issue I think I'll try to look at is adding a button in the formatting toolbar that will switch the direction of the input textbox (so that the user can decide what direction the editing input will be if the browser doesn't allow for this - like Firefox).

Here is the plugin (just create a directory called LTR under the plugins directory, create a file syntax.php in it and copy the following code into it):

<?php
  /**
   * Plugin Skeleton: changes to "ltr" direction
   *
   * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
   * @author     Ariel Kroszynski
   */
 
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_ltr extends DokuWiki_Syntax_Plugin {
 
  /**
   * return some info
   */
  function getInfo(){
    return array(
                 'author' => 'ariel kroszynski',
                 'email'  => 'galiel@gmail.com',
                 'date'   => '2007-01-21',
                 'name'   => 'LTR',
                 'desc'   => 'switch to ltr rendering within a rtl page',
                 'url'    => 'http://www.dokuwiki.org/plugin:ltr',
                 );
  }
 
  /**
   * What kind of syntax are we?
   */
  function getType(){
    return 'formatting';
  }
 
  /**
   * What kind of syntax do we allow (optional)
   */
  function getAllowedTypes() {
     return array('baseonly','container','substition','protected','disabled','formatting');
  }
 
  /**
   * What about paragraphs? (optional)
   */
  function getPType(){
     return 'normal';
  }
 
  /**
   * Where to sort in?
   */
  function getSort(){
    return 500;
  }
 
  /**
   * Connect pattern to lexer
   */
  function connectTo($mode) {
     $this->Lexer->addEntryPattern('<LTR>(?=.*?</LTR>)',$mode,'plugin_ltr');
  }
 
  function postConnect() {
    $this->Lexer->addExitPattern('</LTR>','plugin_ltr');
  }
 
  /**
   * Handle the match
   */
  function handle($match, $state, $pos, &$handler){
    switch ($state) {
    case DOKU_LEXER_ENTER :
      return array($state,"");
      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 :
             list($color, $background) = $match;
             $renderer->doc .= "<div style='direction : ltr;'>";
             break;
          case DOKU_LEXER_UNMATCHED :  $renderer->doc .= $renderer->_xmlEntities($match); break;
          case DOKU_LEXER_EXIT :       $renderer->doc .= "</div>"; break;
       }
 
      return true;
    }
    return false;
  }
}

Keep up the good work guys.

Ariel.

Discussion

  • Ariel : I was just planning to write a similar plugin which would allow <HE> in English texts and <EN> in Hebrew texts
    your plugin will save me a lot of sweat ;-)
    FYI : I work with IE6/IE7/Firefox under Windows with Hebrew support :
    In Edit Mode Ctrl-RightShift changes editing direction to RTL whereas Ctrl-LeftShift changes to LTR
    (and BTW Alt-AnyShift changes language mode independent of editing direction)
    I don't know what happens in other Operating systems
    Meiki bml040 strudel motorola dot com 2007-11-18 14:30

Just to note that the option $conf['htmlok'] has to be 1 in order for the plugin to work.

plugin/ltr.txt · Last modified: 2011-06-18 16:58 by ach