/************************************

  "waka" is a Japanese poetry 
         composed of 31 syllables. 

  (c) 2005 Pixel-Apes.

  -----------------------------------

  Ordered and unordered lists markup:
  
  * two spaces and asterisk
  * one more
    1. plus two spaces
    2. number-dot
  * list item

  1.#9 custom numeration supported

*************************************/

function wakaLists() {}
         wakaLists.prototype = new wakaToken();
         wakaLists.prototype.constructor = 
         wakaLists;

// static
wakaLists.prototype.getRegexpPart = function()
{
  return "((^|\n)(  )*(\\*|[0-9]+\\.)(#[0-9]+)? .*)";
}
                              //12     3   4          5          6
wakaLists.prototype.isRE = /^\n?((  )*)(\*|([0-9]+\.))(#[0-9]+)? (.*)$/;
wakaLists.prototype.is = function( outerText )
{
  var matches = this.isRE.exec( outerText );
  if (matches === null) return false;

  var li_type = "ul";
  if (matches[4]) li_type = "ol";

  return {
            inner : matches[6],
            type  : li_type,
            level : matches[1].length/2,
            start : matches[5]?matches[5].substr(1):false,
            text  : outerText
         };
}

// private (up to parent)
wakaLists.prototype._glue = function()
{
  // glue only if prev is wakaList with lesser deep
  if (this._prev && (this._prev.constructor == this.constructor)
                 && (this._prev._data.level < this._data.level))
    return this._prev.glueChild( this );
  else
    return false;
}

// this is a hack to trim newlines after <li>
wakaLists.prototype.hack_separateTrimNextNewline = true;

// returns separation from a given "next"
wakaLists.prototype.separateFromNext   = function( next )
{
  if (!next || next.constructor != this.constructor 
            || next._data.type  != this._data.type)
  {
    return "</" + this._data.type +">";
  }

  return "";
}

// private (compilation)
wakaLists.prototype._compile   = function()
{
  var inner = this.wf.format( this._data.inner, "default" );
  var glued = this.wf.formatTree( this._tree, "default" );

  var listStartIfAny = "";
  if (!this._prev || (this._prev.constructor != this.constructor )
                  || (this._prev._data.type != this._data.type)) 
  {
    listStartIfAny = "<"+this._data.type+
        (this._data.start?(" start=\""+this._data.start+"\" "):"")+
                     ">";
  }
      
  this._html = listStartIfAny+
               "<li>"+ 
               inner+
               glued+
               "</li>";
}
