French Typography Plugin

This unambitious plugin replaces normal spaces by non-breaking spaces to follow French typographical rules. The plugin replaces spaces, so there should be no compatibility problems with English typographical rules.

That is:

  • before ? ! ; : » (>>)
  • after « (<<)

History

Last update : 27th of January 2007 : Another try to nail the Warning: Cannot modify header information - headers already sent by (output started at …\lib\plugins\frenchtypo\syntax.php:1) in …\inc\actions.php random error. I think this is the good one.

13th of January 2007 : fixed (I hope) the 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 error that appears randomly on page save.

Installation

You can install it using the plugin manager (tested).

frenchtypo.tar.gz

frenchtypo.zip

If you use this plugin, would you mind saying so on the discussion page?

Notes

  • The plugin performs its own ”<< ” → ”« ” and ” >>” → ” »” substitution, bypassing the usual DokuWiki subtitution. However, the ”<<” → ”«” and ”>>” → ”»” is still performed by DokuWiki. In other words, if << is followed by a space or if a space precedes >>, the plugin does the quote substitution and the space substitution in one go. Otherwise, Dokuwiki performs the quote substitution.
  • The plugin uses utf-8 quotes and non-breaking spaces, while Dokuwiki uses HTML entities (&laquo; and &raquo; ; see your entites.conf file).
  • The plugin also replaces spaces that precede / follow utf-8 quotes, but not HTML entities (&laquo; / &#171; / &raquo; / &#187;).

Any suggestion or comment welcome on the discussion page! TIA :-)

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;
    }
}
?>
Navigation
Print/export
Toolbox
Languages
Translations of this page: