--- sidenote-old/syntax.php	2006-12-15 08:47:30.103410042 +1100
+++ sidenote/syntax.php	2006-12-15 09:02:33.062601994 +1100
@@ -7,6 +7,14 @@
  *
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  * @author     Stephane Chamberland <stephane.chamberland@ec.gc.ca>
+ * 
+ * Last Modified
+ * 2006-12-15 Adam Thomas <adam@alphacomplex.org>
+ *   Cleaned up some of the if{}elseif{}else{}statements with switches
+ *   Cleaned some of the regexes
+ *   Set the plugin type to 'container'
+ *   Set the PType to 'normal' - the output validates now.
+ *   Added 'protected' to the parser modes so I could include HTML within the sidenote
  */
  
 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
@@ -41,6 +49,7 @@
         $this->allowedModes = array_merge(
             $PARSER_MODES['formatting'],
             $PARSER_MODES['substition'],
+            $PARSER_MODES['protected'],
             $PARSER_MODES['disabled']
         );
     }
@@ -49,8 +58,7 @@
      * What kind of syntax are we?
      */
     function getType(){
-        //return 'container';
-        return 'formatting';
+        return 'container';
     }
  
    /**
@@ -66,7 +74,7 @@
     * @see Doku_Handler_Block
     */
     function getPType(){
-        return 'stack';
+        return 'normal';
     }
  
     /**
@@ -80,9 +88,7 @@
      * Connect pattern to lexer
      */
     function connectTo($mode) {
-        $this->Lexer->addEntryPattern('<side right>(?=.*\x3C/side\x3E)',$mode,'plugin_sidenote');
-        $this->Lexer->addEntryPattern('<side left>(?=.*\x3C/side\x3E)',$mode,'plugin_sidenote');
-        $this->Lexer->addEntryPattern('<side>(?=.*\x3C/side\x3E)',$mode,'plugin_sidenote');
+	    $this->Lexer->addEntryPattern('<side(?:\s+[^\r\n>]+)?>(?=.*</side>)',$mode,'plugin_sidenote');
     }
     function postConnect() {
         $this->Lexer->addExitPattern('</side>','plugin_sidenote');
@@ -94,21 +100,13 @@
     function handle($match, $state, $pos, &$handler){
         switch ( $state ) {
             case DOKU_LEXER_ENTER:
-                if (preg_match('/left>/', $match)>0) {
-                    return array('',$state,'left');
-                } else if (preg_match('/right>/', $match)>0) {
-                    return array('',$state,'right');
-                } else {
-                    return array('',$state,'');
-                }
-                break;
+                preg_match('/<side\s*([^\n\r>]+)>/',$match, $matches);
+                return array('',$state,$matches[1]);      
+            break;
+            
             case DOKU_LEXER_UNMATCHED:
-                //$matches = preg_split('/>/u',$match,2);
-                //$matches[0] = trim($matches[0]);
-                //$matches[1] = trim(implode('>',array_slice($matches,1)));
-                //return array($matches[1], $state,$matches[0]);
                 return array($match,$state,'');
-                break;
+            break;
         }
         return array('',$state,'');
     }
@@ -117,25 +115,33 @@
      * Create output
      */
     function render($mode, &$renderer, $data) {
-        if($mode == 'xhtml'){
-            if ($data[1] == DOKU_LEXER_ENTER){
-                if ($data[2] == 'right' ) {
-                    $renderer->doc .= '<span class="sideright">';
-                } else if ($data[2] == 'left') {
-                    $renderer->doc .= '<span class="sideleft">';
-                } else {
-                    $renderer->doc .= '<span class="sideboth">';
-                }
-            } else if ($data[1] == DOKU_LEXER_UNMATCHED){
-                $renderer->doc .= $data[0];
-            } else if ($data[1] == DOKU_LEXER_EXIT){
-                $renderer->doc .= '</span>';
+        if($mode == 'xhtml') {
+	        switch( $data[1] ) {
+        		case DOKU_LEXER_ENTER:
+        			switch( $data[2] ) {
+        			    case 'right':
+                            $renderer->doc .= '<span class="sideright">';
+        			    break;
+			    
+			            case 'left' :
+                            $renderer->doc .= '<span class="sideleft">';
+        			    break;
+			
+		        	    default:
+                            $renderer->doc .= '<span class="sideboth">';
+        			    break;
+		        	}
+		        break;
+
+        		case DOKU_LEXER_UNMATCHED:
+		        	$renderer->doc .= $data[0];
+        		break;
+		
+        		case DOKU_LEXER_EXIT:
+        			$renderer->doc .= '</span>';
+        		break;
             }
-            return true;
-        }
-        return false;
- 
-        if($mode == 'xhtml' && strlen($data[0]) > 1) {
+
             return true;
         }
         return false;
