* Adapted by Frank Luithle  \n";
  // state vars
  $li_o = "";
  $tbl_o = 0;
  $post = "";
  $wm_whole_line = array( "!!!" => "h2",
                          "!!"  => "h3",
                          "!"   => "h4",
                          " "   => "tt",
                          ";:"  => 'div style="left-margin:10pt;"' );
  $table_defaults = 'cellpadding="2" border="1" cellspacing="0"';
  // these tags will be preserved if the $safe_html_allowed argument
  // is set to 'true'
  $rescue_html = array( "tt", "b", "i", "strong", "em", "s", "kbd", "var",
                        "xmp", "sup", "sub", "pre", "q", "h2", "h3", "h4",
                        "h5", "h6", "cite", "code", "u" );
  $syn_htmlentities = array( "&" => "&",
                             ">" => ">",
                             "<" => "<",
                             "%%%" => " ";
    } elseif ( strpos( $line, "----" ) === 0 ) {
      $o .= "
" );
  $wm_list = array( "-" => array('ul type="square"', "", "li"),
                    "*" => array('ul type="circle"', "", "li"),
                    "#" => array("ol", "", "li"),
                    ":" => array("dl", "dt", "dd") );
  $wm_text_style = array( "'''" => array("''__", "__''"),
                          "___" => array("''__", "__''"),
                          "''" => array("", ""),
                          "__" => array("", ""),
                          // "^^" => array("", ""),
                          // "***" => array("", ""),
                          // "###" => array("", ""),
                          "**" => array("", ""),
                          "##" => array("", ""),
                          "��" => array("", "") );
  $link_regex = "#(!?\[[^[\]\n]+\])|((?:!?[a-z]{2,6}://|mailto:)[^\s\[\]\'\"\)\,<]+)#";
  #$link_regex = "#(!?\[[^[\]\n]+\])|((?:!?[".EWIKI_CHARS_U."]+[".EWIKI_CHARS_L.
  #  ":]+){2}[\w\d]*)|((?:!?[a-z]{2,6}://|mailto:)[^\s\[\]\'\"\)\,<]+)#";
  // eliminate html
  foreach ( $syn_htmlentities as $find => $replace ) {
    $wiki_source = str_replace( $find, $replace, $wiki_source );
  }
  array_pop( $syn_htmlentities );
  // unescape allowed html
  if ( $safe_html_allowed ) {
    foreach ( $rescue_html as $tag ) {
      foreach( array( $tag, "/$tag", ( $tag = strtoupper($tag) ), "/$tag" )
               as $tag ) {
        $wiki_source = str_replace( '<' . $tag . '>',
                                    "<" . $tag . ">",
                                    $wiki_source );
      }
    }
  }
  $wiki_source = trim( $wiki_source ) . "\n";
  foreach ( explode( "\n", $wiki_source ) as $line ) {
    $line = rtrim( $line );
    $post = "";
    // paragraphs
    if ( empty($line) ) {
      $post .= "
\n";
      continue;
    } elseif ( strpos( $line, "<!--" ) === 0 ) {
      $o .= "\n";
      continue;
    }
    // unescape html markup || tables wiki markup
    if ( strlen( $line ) && ( $line[0] == "|" ) ) {
      if ( strlen( $line ) >
           strlen( trim( $line, "|" ) ) + 1 ) {
        $line = substr( $line, 1, strlen( $line ) - 2 );
        if ( !$tbl_o ) {
          $o .= "\n";
        }
        $line = "
\n";
      $tbl_o = 0;
    }
    // whole-line wikimarkup
    foreach ( $wm_whole_line as $find => $replace ) {
      if ( substr( $line, 0, strlen($find) ) == $find ) {
        $line = ltrim( substr( $line, strlen($find) ) );
        $o .= "<$replace>";
        $post = "" . strtok( $replace, " " ) . ">" . $post;
      }
    }
    // wiki list markup
    if ( strlen( $li_o ) ||
         strlen( $line ) && isset( $wm_list[@$line[0]] ) ) {
      $n = 0;
      $li = "";
      // count differences to previous list wikimarkup
      while ( strlen( $line ) && ( $li0 = $line[0] ) && isset( $wm_list[$li0] ) ) {
        $li .= $li0;
        $n++;
        $line = substr($line, 1);
      }
      $line = ltrim($line);
      // fetch list definition
      if ( strlen( $li ) && ( $last_list_i = $li[strlen($li)-1] ) )
        list( $list_tag, $list_dt0, $list_entry_tag ) = $wm_list[$last_list_i];
      // output \n ";
        $tbl_o = 1;
      } elseif ( $table_html_allowed ) {
        $line = ltrim( substr( $line, 1 ) );
        foreach ( array_flip( $syn_htmlentities ) as $find => $replace ) {
          $line = str_replace( $find, $replace, $line );
        }
      }
    } elseif ($tbl_o) {
      $o .= "" . str_replace("|", " \n", $line) . " \n until new list wikimarkup rule matched
      while ( strlen($li_o) < strlen($li) ) {
        $add = $li[ strlen($li_o) ];
        $o .= "<" . $wm_list[ $add ][ 0 ] . ">\n";
        $li_o .= $add;
      }
      // close 
lists until "$li_o" == "$li" (list wikimarkup state var)
      while ( strlen($li_o) > strlen($li) ) {
        $del = $li_o[ strlen($li_o) - 1 ];
        $o .= "" . strtok( $wm_list[$del][0], " " ) . ">\n";
        $li_o = substr( $li_o, 0, strlen($li_o) - 1 );
      }
      // more work for lists
      if ( !empty($list_dt0) ) {
        list( $line_dt, $line ) = explode( $last_list_i, $line, 2 );
        $o .= "<$list_dt0>$line_dt$list_dt0>";
        $list_dt0 = $last_list_i = false;
      }
      // finally enclose current line in