IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques & Frameworks Discussion :

regex ajout brush SyntaxHightlither


Sujet :

Bibliothèques & Frameworks

  1. #1
    Invité
    Invité(e)
    Par défaut regex ajout brush SyntaxHightlither
    Bonjour

    Voilà je patine pas mal sur l'ajout d'une brush.
    En fait j'utilise un moteur de Template avec des fichiers TPL et quand je veux afficher du code html avec {VALEUR} alors celui-ci est transformer en html dans tinyMCE.
    J'ai quand même essayer de suivre les explication mais là je n'y arrive plus ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
     
    /**
     * SyntaxHighlighter
     * http://alexgorbatchev.com/SyntaxHighlighter
     *
     * SyntaxHighlighter is donationware. If you are using it, please donate.
     * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
     *
     * @version
     * 3.0.83 (July 02 2010)
     * 
     * @copyright
     * Copyright (C) 2004-2010 Alex Gorbatchev.
     *
     * @license
     * Dual licensed under the MIT and GPL licenses.
     */
    ;(function()
    {
        // CommonJS
        typeof (require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
     
     
    	function Brush()
    	{
    		function process(match, regexInfo)
    		{
    			var constructor = SyntaxHighlighter.Match,
    				code = match[0],
    				tag = new XRegExp('({|{)[\\s\\/\\?]*(?{name}[:\\w-\\.]+)', 'xg').exec(code),
    				result = []
    				;
     
    			if (match.attributes != null) 
    			{
    				var attributes,
    					regex = new XRegExp('(?{name} [\\w:\\-\\.]+)' +'\\s*=\\s*' +'(?{value} ".*?"|\'.*?\'|\\w+)','xg');
     
    				while ((attributes = regex.exec(code)) != null) 
    				{
    					result.push(new constructor(attributes.name, match.index + attributes.index, 'color1'));
    					result.push(new constructor(attributes.value, match.index + attributes.index + attributes[0].indexOf(attributes.value), 'string'));
    				}
    			}
     
    			if (tag != null)
    				result.push(
    					new constructor(tag.name, match.index + tag[0].indexOf(tag.name), 'keyword')
    				);
     
    			return result;
    		}
     
    		this.regexList = [
    			{ regex: new XRegExp('(\\{|{)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\\}|})', 'gm'),			css: 'color2' },	// <![ ... [ ... ]]>
    			{ regex: SyntaxHighlighter.regexLib.xmlComments,												css: 'comments' },	// <!-- ... -->
    			{ regex: new XRegExp('({|{)[\\s\\/\\?]*(\\w+)(?<attributes>.*?)[\\s\\/\\?]*(}|})', 'sg'), func: process }
    		];
    	};
     
        Brush.prototype = new SyntaxHighlighter.Highlighter();
        Brush.aliases = ['TPL','tpl'];
     
        SyntaxHighlighter.brushes.Tpl = Brush;
     
        // CommonJS
        typeof (exports) != 'undefined' ? exports.Brush = Brush : null;
     
    })();
    Au cas ou voici les regex de mon fichier Template :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
        // Définition des variables à transformer dans la page
        public function SetVar ( array $vars )
        {
            if ( !is_array ( $vars ) )
            {
                return false;
            }
     
            foreach ( $vars as $var => $val )
            {
                if ( preg_match ( "#^[A-Z\#_]{1,}$#" , $var ) )
                {
                    $this->vars[$var] = $val;
                }
            }
     
            return true;
        }
     
     
        // Retourne le texte de la page
        public function Parse ()
        {
            // Transformation des blocs
            foreach ( $this->blocks as $block_name => $block_content )
            {
                // Contenu du bloc
                $block_ctn = preg_replace ( "#^(.{0,})<!--" . $block_name . ":START-->(.+)<!--" . $block_name . ":END-->(.{0,})$#sU" , "$2" , $this->texte );
                $block_txt = '';
     
                // Pour chaque ligne du bloc
                foreach ( $block_content as $block_row )
                {
                    $block_txt .= $block_ctn;
     
                    // Pour chaque variable de la ligne
                    foreach ( $block_row as $var => $val )
                    {
                        $block_txt = str_replace ( '{' . $block_name . ':' . $var . '}' , $val , $block_txt );
                    }
                }
     
                $this->texte = preg_replace ( "#^(.{0,})<!--" . $block_name . ":START-->(.+)<!--" . $block_name . ":END-->(.{0,})$#sU" , "$1" . $block_txt . "$3" , $this->texte );
            }
     
            // Transformation des variables
            foreach ( $this->vars as $var => $val )
            {
                $this->texte = str_replace ( '{' . $var . '}' , $val , $this->texte );
            }
     
            return $this->texte;
        }
     
     
        // Définition d'un bloc
        public function SetBlock ( $name , array $vars )
        {
            if ( !is_array ( $vars ) || !preg_match ( "#^[A-Z\#_]{1,}$#" , $name ) )
            {
                return false;
            }
     
            if ( !isset ( $this->blocks[$name] ) )
            {
                $this->blocks[$name] = array ();
            }
     
            $this->blocks[$name][] = $vars;
     
            return true;
        }
    }

  2. #2
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 223
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 223
    Points : 15 516
    Points
    15 516
    Par défaut
    quelle est la question ?

Discussions similaires

  1. [RegExp] Ajouter l'underscore dans un regex existant
    Par beegees dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 03/03/2013, 21h36
  2. REGEX : ajout de liens dans un texte HTML
    Par Tororo73 dans le forum Langage
    Réponses: 2
    Dernier message: 24/06/2011, 13h46
  3. [système] Comment ajouter un item dans le context menu de Windows ?
    Par ddmicrolog dans le forum API, COM et SDKs
    Réponses: 8
    Dernier message: 29/06/2005, 18h03
  4. Connaitre l'unitée à ajouter dans USES
    Par DelphiCool dans le forum Langage
    Réponses: 7
    Dernier message: 01/08/2002, 14h48
  5. Ajouter une aide
    Par Mailgifson dans le forum C++Builder
    Réponses: 5
    Dernier message: 12/06/2002, 14h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo