/************************************

  "waka" is a Japanese poetry 
         composed of 31 syllables. 

  (c) 2005 Pixel-Apes.

  -----------------------------------

  Decoration multiline markup, 
  that glues to words:
  
  --strike out--
  !!background highlighting!!
  ??color hightlighting??

  !!(red)background!!


  -- must not works in such cases (see leading space?)--

*************************************/


function wakaDecorationGlue() {}
         wakaDecorationGlue.prototype = new wakaToken();
         wakaDecorationGlue.prototype.constructor = 
         wakaDecorationGlue;

// static
wakaDecorationGlue.prototype.getRegexpPart = function()
{
  return "((^|\\s)--[^ \t\n\r\\-]((.|\n)*?[^ \t\n\r\\-])?--($|\\s|[,.!\\?]))"+
         "|"+
         "((^|\\s)!!\\S((.|\n)*?\\S)?!!($|\\s|[,.!\\?]))"+
         "|"+
         "((^|\\s)\\?\\?\\S((.|\n)*?\\S)?\\?\\?($|\\s|[,.!\\?]))";
}
                                     //1    23      45         67
wakaDecorationGlue.prototype.isRE1 = /^(\s?)((-){2})((.|\n)*)\2((\s|[,.!\\?])?)$/;
                                     //1    23         4  5                   67         89
wakaDecorationGlue.prototype.isRE2 = /^(\s?)((\?|!){2})(\((red|blue|green)\))?((.|\n)*)\2((\s|[,.!\\?])?)$/;
wakaDecorationGlue.prototype.is = function( outerText )
{
  var matches = this.isRE1.exec( outerText );
  if (matches !== null) 
  {
    return {
            whitespaceBefore : matches[1],
            whitespaceAfter  : matches[6],

            inner : matches[4],
            type  : "-",
            text  : outerText
           };
  }

  var matches = this.isRE2.exec( outerText );
  if (matches !== null) 
  {
    var _css = "back";
    if (matches[3] == "!") _css = "fore";
    if (matches[5]) _css += "-"+matches[5];
    return {
            whitespaceBefore : matches[1],
            whitespaceAfter  : matches[8],

            inner : matches[6],
            type  : matches[3],
            css   : _css,
            text  : outerText
           };
  }
  
  return false;
}



// private (compilation)
wakaDecorationGlue.prototype._compile   = function()
{
  var inner = this.wf.format( this._data.inner, "default" );

  if (this._data.type == "-") 
    this._html = "<s>"+inner+"</s>";
  else
    this._html = '<span class="'+this.wf.cssPrefix+this._data.css+
                                 this.wf.cssPostfix+'">' + inner + '</span>';

  if (this._data.whitespaceBefore) 
    this._html = this.wf.format(this._data.whitespaceBefore) + this._html;
  if (this._data.whitespaceAfter) 
    this._html = this._html + this.wf.format(this._data.whitespaceAfter);
}







