Salut à tous,
Je réalise actuellement un script d'apercu en direct pour un formulaire dont voici le code :
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
var timer=0;
var ptag=String.fromCharCode(5,6,7);
function  visualisation() {
 t=document.formulaire.texte.value  
 t=code_to_html(t)
 if (document.getElementById) document.getElementById("previsualisation").innerHTML=t
 if (document.formulaire.auto.checked) timer=setTimeout(visualisation,1000)
}
function automatique() {
 if (document.formulaire.auto.checked) visualisation()
}
function code_to_html(t) {
 t=nl2khol(t)
// balise URL 
 t=remplace_tag(/\<lien=([^\s<>]+)\>(.+)\<\/lien\>/g,'<a href="$1" target="_blank">$2</a>',t)
// balise Gras
 t=deblaie(/(\<\/gras\>)/g,t)
 t=remplace_tag(/\<gras\>(.+)\<\/gras\>/g,'<b>$1</b>',t)  
 t=remblaie(t)
// balise Underline
 t=deblaie(/(\<\/souligne\>)/g,t)
 t=remplace_tag(/\<souligne\>(.+)\<\/souligne\>/g,'<u>$1</u>',t)  
 t=remblaie(t)
// balise Italique
 t=deblaie(/(\<\/italique\>)/g,t)
 t=remplace_tag(/\<italique\>(.+)\<\/italique\>/g,'<i>$1</i>',t)  
 t=remblaie(t)
 
// balise Barre
 t=deblaie(/(\<\/barre\>)/g,t)
 t=remplace_tag(/\<barre\>(.+)\<\/barre\>/g,'<strike>$1</strike>',t)  
 t=remblaie(t)
// balise quote
 t=deblaie(/(\<\/citation\>)/g,t)
 t=remplace_tag(/\<citation=(.+?)\>(.+)\<\/citation\>/g,'<strong>$1 :</strong><div id="citation">$2</div>',t)  
 t=remblaie(t)
// balise Img
 t=deblaie(/(\<\/image\>)/g,t)
 t=remplace_tag(/\<image\>(.+)\<\/image\>/g,'<img src="$1"/>',t)
 t=remblaie(t)
 
// balise Mail
 t=remplace_tag(/\<mail=([^\s<>]+)\>(.+)\<\/mail\>/g,'<a href="mailto:$1" target="_blank">$2</a>',t)
 
// balise Police 
 t=remplace_tag(/\<police=(.+)\>(.+)\<\/police\>/g,'<span style="font-family: $1;">$2</span>',t)
 
// balise Couleur 
 t=remplace_tag(/\<couleur=(.+)\>(.+)\<\/couleur\>/g,'<font color="$1">$2</font>',t)
 
// balise Police 
 t=remplace_tag(/\<taille=1\>(.+)\<\/taille\>/g,'<span style="font-size: 0.7em;">$1</span>',t)
 
// balise Police 
 t=remplace_tag(/\<taille=2\>(.+)\<\/taille\>/g,'<span style="font-size: 0.9em;">$1</span>',t)
// balise Police 
 t=remplace_tag(/\<taille=3\>(.+)\<\/taille\>/g,'<span style="font-size: 1em;">$1</span>',t)
// balise Police 
 t=remplace_tag(/\<taille=4\>(.+)\<\/taille\>/g,'<span style="font-size: 1.4em;">$1</span>',t)
// balise Police 
 t=remplace_tag(/\<taille=5\>(.+)\<\/taille\>/g,'<span style="font-size: 1.8em;">$1</span>',t)
 
// balise Alignement
 t=remplace_tag(/\<alignement=gauche\>(.+)\<\/alignement\>/g,'<div align="left">$1</div>',t)
// balise Alignement
 t=remplace_tag(/\<alignement=centre\>(.+)\<\/alignement\>/g,'<div align="center">$1</div>',t)
// balise Alignement
 t=remplace_tag(/\<alignement=droit\>(.+)\<\/alignement\>/g,'<div align="right">$1</div>',t)
// balise Alignement
 
 
 
// balise Couleur 
 t=remplace_tag(/\<liste\>(.+)\<\/liste\>/g,'<ul>$1</ul>',t)
// balise Couleur 
 t=remplace_tag(/\<puce\>(.+)\<\/puce\>/g,'<li>$1</li>',t)
 
 t=unkhol(t)
 t=nl2br(t)
 return t
}
function deblaie(reg,t) {
 texte=new String(t);
 return texte.replace(reg,'$1\n');
}
function remblaie(t) {
 texte=new String(t);
 return texte.replace(/\n/g,'');
}
function remplace_tag(reg,rep,t) {
 texte=new String(t);
 return texte.replace(reg,rep);
}
function nl2br(t) {
 texte=new String(t);
 return texte.replace(/\n/g,'<br/>');
}
function nl2khol(t) {
 texte=new String(t);
 return texte.replace(/\n/g,ptag);
}
function unkhol(t) {
 texte=new String(t);
 return texte.replace(new RegExp(ptag,'g'),'\n');
}
Or, quand je veux ajouter l'affichage des smilies, ca bloque ;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
 t=remplace_tag(/\:euh:/g,'<img src="<a href="http://www.belgofoot.com/forum/images/smiles/unsure.gif" target="_blank">http://www.belgofoot.com/forum/images/smiles/unsure.gif</a>" title="Smilies" alt="Smilies" />',t) 
// Là, cela ne bloque pas
 t=remplace_tag(/\:p/g,'<img src="<a href="http://www.belgofoot.com/forum/images/smiles/langue.png" target="_blank">http://www.belgofoot.com/forum/images/smiles/langue.png</a>" title="Smilies" alt="Smilies" />',t) 
// Là non plus
 t=remplace_tag(/\:)/g,'<img src="<a href="http://www.belgofoot.com/forum/images/smiles/content.png" target="_blank">http://www.belgofoot.com/forum/image...es/content.png</a>" title="Smilies" alt="Smilies" />',t) 
// Par contre, là, l'affichage en direct se bloque quand je rajoute la ligne
Merci de votre aide
@+
Magic33

PS : Il est evident que je supprimerais mes codes une fois le sujet clos pour libérer de la place sur le forum