Table des matières

Plugin de typographie française

Ce petit plugin remplace les espaces ordinaires par des espaces insécables pour respecter les règles de typographie française. (Comme le plugin remplace les espaces, il ne devrait pas y avoir de conflit avec les règles anglaises de typographie.)

C'est à dire :

Historique

Dernière mise à jour : 27 janvier 2007 : Un nouvel essai d'éliminer l'erreur aléatoire Warning: Cannot modify header information - headers already sent by (output started at …\lib\plugins\frenchtypo\syntax.php:1) in …\inc\actions.php error. Je pense que c'est le bon.

13 janvier 2007 : répare (j'espère) l'erreur Warning: Cannot modify header information - headers already sent by (output started at …\lib\plugins\frenchtypo\syntax.php:1) in …\inc\actions.php on line 287 qui apparaît aléatoirement lorsque l'on sauve une page.

Installation

Vous pouvez l'installer avec le gestionnaire de plugins (testé).

frenchtypo.tar.gz

frenchtypo.zip

Si vous utilisez ce plugin, voudriez-vous le signaler sur lapage de discussion ? Merci d'avance :-)

Remarques

Toutes suggestions et commentaires sont les bienvenus dans la page de discussion !

Code

<?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;
    }
}
?>