LTR Plugin

Совместим с «Докувики»

Нет информации о совместимости!

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

Последнее обновление:
2007-01-21
Предоставляет
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.

Это расширение не обновлялось более двух лет. Возможно, оно больше не разрабатывается или не поддерживается; возможны проблемы совместимости.

Похож на wrap

Теги: 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

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