French Typography plugin

Compatible with DokuWiki

2006-11-06; 2007-06-26

plugin Respect French typographical rules for non-breaking spaces.

Last updated on
2007-01-27
Provides
Syntax

Plugin name contains underscore, will not generate popularity points.

Tagged with language, typography

Details and Download

Code

This source code may not be up to date. This is posted here, just in case the link above will be broken.

File: syntax.php

<?php
/**
 * French typography plugin
 * Adds non-breaking spaces where needed by French typography rules .
 * GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * Philippe Debar
 */
 
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_frenchtypo extends DokuWiki_Syntax_Plugin {
 
    function getInfo(){
        return array(
            'author' => 'Philippe Debar',
            'date'   => '2007-01-27',
            'name'   => 'French Typography',
            'desc'   => 'Adds non-breaking spaces where needed by French typography rules .',
            'url'    => 'http://www.notamment.be/dokuwiki/plugin/frenchtypo',
        );
    }
 
    // Substitution type - with required back-compatibility typo ;o)
    function getType(){ return 'substition'; }
 
   // No nested modes allowed -> use default getAllowedTypes() {return array();}
   // Can be used inside paragraphs -> use defautl getPType() {return 'normal';}
 
    // When to apply - should experiment with this ?
    function getSort(){
        return 245;
    }
 
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern(' (?=[!?:;»])',$mode,'plugin_frenchtypo');
      $this->Lexer->addSpecialPattern(' (?=»)',$mode,'plugin_frenchtypo');
      $this->Lexer->addSpecialPattern('(?<=«) ',$mode,'plugin_frenchtypo');
      $this->Lexer->addSpecialPattern('(?<=«) ',$mode,'plugin_frenchtypo');
      $this->Lexer->addSpecialPattern('[<]{2} ',$mode,'plugin_frenchtypo');
      $this->Lexer->addSpecialPattern(' >>',$mode,'plugin_frenchtypo');
    }
 
    function handle($match, $state, $pos, &$handler){
        if ($state==DOKU_LEXER_SPECIAL){
            switch ($match) {
              case ' ':
                return 'Â ';
              case '<< ':
                return '« ';
              case ' >>':
                return ' »';
            }
        }
        return $match;
    }
 
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $renderer->doc .= $data;
            return true;
        }
        return false;
    }
}
?>
plugin/french_typography.txt · Last modified: 2010/10/10 14:52 by lupo49
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate