Skeeve: Problem mit RegExp

Beitrag lesen

Moin!

Hier mal ein Beispiel damit Du loslegen kannst.

Das Blinddiv ist aber noch nicht blind, damit Du siehst, was passiert.

  
<html>  
<head>  
<script language="JavaScript" type="text/JavaScript" >  

  
 function bbcode() {  
  html= document.mainform.eingabe.value;  
  blinddiv= document.getElementById('blinddiv');  
  blinddiv.innerHTML= html;  
  document.mainform.ausgabe.value= convert_to_bbcode( blinddiv );  
 }  
 function convert_to_bbcode( p ) {  
  var preresult= '';  
  var postresult= '';  
  var result= '';  
  switch( p.nodeName ) {  
  case 'DIV':  
   var align= p.getAttribute( 'align' );  
   if ( align ) {  
    preresult= '[' + align.toUpperCase() + ']';  
    postresult= '[/' + align.toUpperCase() + ']';  
   }  
   break;  
  case 'B':  
   preresult= '[B]';  
   postresult='[/B]';  
   break;  
  case '#text':  
   return p.textContent;  
   break;  
  default:  
   preresult= ' ?? ' + p.nodeName + ' ?? ';  
   break;  
  }  
  var child= p.firstChild;  
  while (child) {  
   result+= convert_to_bbcode( child );  
   child= child.nextSibling;  
  }  
  return preresult + result + postresult;  
 }  

  
</script>  
</head>  
<body>  
<form method="post" name="mainform" action="http://www.google.de/" onsubmit="return false;">  
 <textarea id="eingabe"          cols="75" rows="10">  
  <b>  
   bold  
   <div align="left">  
    left  
    <div align="right">  
     right  
     <div align="center">  
      center  
     </div>  
    </div>  
   </div>  
  </b>  
 </textarea>  
 <button onclick="bbcode()">mach</button>  
 <textarea id="ausgabe" readonly cols="75" rows="10"></textarea>  
</form>  
<div id="blinddiv"></div>  
</body>  
</html>  

Das ' ?? ' + p.nodeName + ' ?? ' dient dazu, Dir zu helfen, noch nicht implementierte Elemente zu identifizieren. Ich habe ja bisher nur <b> und <div> implementiert. Wieso eigentlich div und nicht span?
-- Skeeve