46Fermer48
SpipuLe 12/06/2007 à 16:31
voila le code :

<script type="text/javascript">
<!--
	function verif_balise(post)
	{
		var lst_balise = 'b,i,u,s,sup,sub,li,ul,code,em';
		lst_balise = lst_balise.split(',');
		
		var res_open = '';
		var res_close = '';
		var bal = '';
		var nb = 0;
		post = post.toLowerCase();
		
		for(var k=0; k<lst_balise.length; k++)
		{
			bal = lst_balise[k];
			nb	 = (post.split('['+bal+']').length) - (post.split('[/'+bal+']').length);
			if (nb>0)
			{
				while (nb>0)
				{
					res_close+= '[/'+bal+']';
					nb--;	
				}
			}
			else if (nb<0)
			{
				while (nb<0)
				{
					res_open+= '['+bal+']';
					nb++;	
				}
			}
		}
		
		return new Array(res_open, res_close);
	}

	function verifier()
	{
		var html = document.getElementById('post').value;
		var res = verif_balise(html);
		html = res[0]+html+res[1];
		document.getElementById('result').innerHTML = '<pre>'+html+'</pre>';
	}
-->
</script>
<textarea id="post" style="width: 400px; height: 100px; border: solid 1px black">	
voila un test à la con :
[i]Toto[/i]
[i][b]toto[u]titi[/u]rpo[/s]fdsf
</textarea>
<input type="button" value="verifier" onclick="verifier()" ><br >
<div id="result" style="width: 400px; height: 100px; border: solid 1px black">
</div>