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 ...
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 /** * 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; })();
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; } }
Partager