Wikini

SyntaxeSpip

PagePrincipale :: DerniersChangements :: DerniersCommentaires :: ParametresUtilisateur :: Vous êtes ec2-18-224-63-87.us-east-2.compute.amazonaws.com

Introduction


Cette contribution est issue de l'idée suivante, proposée par GiJo dans DialecteWiki : On connait déjà les formatages spéciaux de WikiNi qui permettent de rendre du code Delphi, PHP, etc. Je souhaiterais que l'on généralise ces possibilités à d'autres formats. (...) J'en prendrai 2 comme exemple : la syntaxe simplifiée SPIP, et la syntaxe élaborée wiki2xhtml, car je les cite souvent., du travail d'adaptation de WikiNi pour Spip - Spikini - par Fil, Ben et Piif (en espérant n'oublier personne) : http://www.spip-contrib.net/spikini/PagePrincipale ainsi que des discussions de la page RendreModulaireLeFormateur.

L'objectif donc est de pouvoir insérer dans une page de wikini du texte au format spip.

Avantages attendus :


Mise en oeuvre


L'essentiel du travail a déjà été fait par l'équipe de spikini, il s'agit juste d'adapter ces modifications de façon à les intégrer au mieux à Wikini. La syntaxe retenue est la suivante :

%%(spip)
texte au format spip
%%


Un exemple d'utilisation est visible ici :

http://david.delon.free.fr/wikini/wakka.php?wiki=PagePrincipale (vous pouvez modifier la page, c'est un wiki de test)



Creation d'un formatter : syntax_spip.php


<?php
/*
syntax_spip.php
Copyright 2004 David DELON
Copyright 2004 Piif aka Christian LEFEBVRE 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

if (!function_exists("spip_callback"))
{
    function 
spip_callback($things)
    {
        
$thing $things[1];
        
$result='';

        static 
$oldIndentLevel 0;
        static 
$oldIndentLength0;
        static 
$indentClosers = array();
        static 
$newIndentSpace= array();
        static 
$br 1;

        global 
$wiki;
    
         if (
$thing == "##")
          {
              static 
$monospace 0;
              return (++
$monospace "<tt>" "</tt>");
          }
        
// Deleted 
        
else 
        if (
$thing == "@@")
        {
                static 
$deleted 0;
                return (++
$deleted "<span class=\"del\">" "</span>");
        }
        
// Inserted
        
else if ($thing == "££")
        {
                static 
$inserted 0;
                return (++
$inserted "<span class=\"add\">" "</span>");
        }
        
// escaped text
        
else if (preg_match("/^\"\"(.*)\"\"$/s"$thing$matches))
        {
            return 
$matches[1];
        }
        
// raw inclusion from another wiki
        // (regexp documentation : see "forced link" below)
        
else if (preg_match("/^\[\[\|(\S*)(\s+(.+))?\]\]$/"$thing$matches))
        {
            list (,
$url,,$text) = $matches;
            if (!
$text$text "404";
            if (
$url)
            {
                    
$url.="/wakka.php?wiki=".$text."/raw";
                return 
$wiki->Format($wiki->Format($url"raw"),"wakka");
            }
            else
            {
                return 
"";
            }
        }
        
// forced links
        // \S : any character that is not a whitespace character
        // \s : any whitespace character
        
else if (preg_match("/^\[\[(\S*)(\s+(.+))?\]\]$/"$thing$matches))
        {
            list (, 
$url, , $text) = $matches;
            if (
$url)
            {
                if (
$url!=($url=(preg_replace("/@@|££|\[\[/","",$url))))$result="</span>";
                if (!
$text$text $url;
                
$text=preg_replace("/@@|££|\[\[/","",$text);
                return 
$result.$wiki->Link($url""$text);
            }
            else
            {
                return 
"";
            }
        }
        else if (
preg_match("/^\(\((.*?)\)\)$/s"$thing$matches))

        {
            if (
$matches[1])
                return 
$wiki->Action($matches[1]);
            else
                return 
"{{}}";
        }
        
// interwiki links!
                
else if (preg_match("/^[A-Z][A-Z,a-z]+[:]([A-Z,a-z,0-9]*)$/s"$thing))

        {
            return 
$wiki->Link($thing);
        }
        
// wiki links!
        
else if (preg_match("/^[A-Z][a-z]+[A-Z,0-9][A-Z,a-z,0-9]*$/s"$thing))
        {
            return 
$wiki->Link($thing);
        }
        
// if we reach this point, it must have been an accident.
        
return $thing;
    }
}

if (!
function_exists("include_ecrire"))
{
    function 
include_ecrire($file) {
        include_once(
$file);
    }
    
}

if (!
function_exists("lire_meta"))
{
    function 
lire_meta($nom) {
        return;
    }
}


$text str_replace("\r"""$text);
$text chop($text)."\n";

$text preg_replace_callback(
    
"/(\%\%.*?\%\%|".
    
"\"\".*?\"\"|".
    
"\[\[.*?\]\]|".
    
"\b[a-z]+:\/\/\S+|".
    
"\#\#|@@|££|".
    
"\n(\t+|([ ]{1})+)(-|[0-9,a-z,A-Z]+\))?|".
    
"^(\t+|([ ]{1})+)(-|[0-9,a-z,A-Z]+\))?|".
    
"\(\(.*?\)\)|".
        
"\b[A-Z][A-Z,a-z]+[:]([A-Z,a-z,0-9]*)\b|".
    
"\b([A-Z][a-z]+[A-Z,0-9][A-Z,a-z,0-9]*)\b|".
    
"\n)/ms""spip_callback"$text);


// we're cutting the last <br />
$text preg_replace("/<br \/>$/",""trim($text));

global 
$spip_lang$lang_typo$lang_dir;
$spip_lang$lang_typo'fr';
$lang_dir='ltr';

include_ecrire("inc_texte.php3");
$text interdire_scripts(propre("\n\n".$text."\n\n"));
// liens locaux
$text ereg_replace("(<a href\=\")([^>]*. class\=.spip_in.)""\\1../\\2",$text);
$text ereg_replace("(<(a href|img src)\=\')(IMG/)""\\1../\\3"$text);

echo 
$text ;


?>


Modification de formatters/wakka.php


<?php
            
// Select formatter for syntax hightlighting
            
if (file_exists("formatters/coloration_".$language.".php")){
                
$formatter "coloration_".$language;
            } else { 
                if (
file_exists("formatters/syntax_".$language.".php")){
                    
$formatter "syntax_".$language;
                    
$output .= $wiki->Format(trim($code), $formatter);
                    return 
$output;
                } else {
                    
$formatter "code";
                }
            }
            
$output "<div class=\"code\">";
            
$output .= $wiki->Format(trim($code), $formatter);
            
$output .= "</div>";
?>


Ajout des fonctions de formatage de spip dans le repertoire formatters


Récupérez inc_filtres.php3 et inc_text.php3 de la distribution spip 1.7 (http://www.spip.net) et copiez les dans le dossier formatter de wikini

Discussion / Bug


A revoir ? :
Pour ma part je trouve que l'intégration de la syntaxe SPIP à WikiNi est une excellente idée ! On aime beaucoup SPIP aussi à mon boulot... ;-) Pour le choix du nom de fichier, peut importe pour le moment, puisque faire ainsi est déjà une bidouille... Pour ma part je pense qu'il faudrait s'orienter vers l'ajout de meta-info sur la page pour pouvoir lui indiquer son formatter (une page formatée en WikiNi, une autre en SPIP, une encore en wiki2xhtml, etc). Je m'orienterais plus dans cette direction car nous aurons plein d'autres meta-infos à ajouter petit à petit : jeu de caractère utilisé pour l'encodage, langue principale du contenu de la page, etc. Mais bon... On peut commencer par ce hack, oui. -- ProgFou

Il n'y a pas de commentaire sur cette page. [Afficher commentaires/formulaire]