Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1613... Línea 1613...
1613
    items.push(this.__patterns.php._starting_pattern.source);
1613
    items.push(this.__patterns.php._starting_pattern.source);
1614
  }
1614
  }
1615
  if (!this._disabled.handlebars) {
1615
  if (!this._disabled.handlebars) {
1616
    items.push(this.__patterns.handlebars._starting_pattern.source);
1616
    items.push(this.__patterns.handlebars._starting_pattern.source);
1617
  }
1617
  }
-
 
1618
  if (!this._disabled.angular) {
-
 
1619
    // Handlebars ('{{' and '}}') are also special tokens in Angular)
-
 
1620
    items.push(this.__patterns.handlebars._starting_pattern.source);
-
 
1621
  }
1618
  if (!this._disabled.erb) {
1622
  if (!this._disabled.erb) {
1619
    items.push(this.__patterns.erb._starting_pattern.source);
1623
    items.push(this.__patterns.erb._starting_pattern.source);
1620
  }
1624
  }
1621
  if (!this._disabled.django) {
1625
  if (!this._disabled.django) {
1622
    items.push(this.__patterns.django._starting_pattern.source);
1626
    items.push(this.__patterns.django._starting_pattern.source);
Línea 2038... Línea 2042...
2038
  var last_token = {
2042
  var last_token = {
2039
    text: '',
2043
    text: '',
2040
    type: ''
2044
    type: ''
2041
  };
2045
  };
Línea 2042... Línea 2046...
2042
 
2046
 
Línea 2043... Línea 2047...
2043
  var last_tag_token = new TagOpenParserToken();
2047
  var last_tag_token = new TagOpenParserToken(this._options);
2044
 
2048
 
Línea 2045... Línea 2049...
2045
  var printer = new Printer(this._options, baseIndentString);
2049
  var printer = new Printer(this._options, baseIndentString);
Línea 2361... Línea 2365...
2361
  }
2365
  }
Línea 2362... Línea 2366...
2362
 
2366
 
2363
  return parser_token;
2367
  return parser_token;
Línea 2364... Línea 2368...
2364
};
2368
};
2365
 
2369
 
2366
var TagOpenParserToken = function(parent, raw_token) {
2370
var TagOpenParserToken = function(options, parent, raw_token) {
2367
  this.parent = parent || null;
2371
  this.parent = parent || null;
2368
  this.text = '';
2372
  this.text = '';
2369
  this.type = 'TK_TAG_OPEN';
2373
  this.type = 'TK_TAG_OPEN';
Línea 2428... Línea 2432...
2428
        handlebar_starts = 3;
2432
        handlebar_starts = 3;
2429
      }
2433
      }
2430
    }
2434
    }
Línea 2431... Línea 2435...
2431
 
2435
 
-
 
2436
    // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
2432
    // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
2437
    // if they start with # or ^, they are still considered single tags if indenting of handlebars is set to false
2433
    this.is_end_tag = this.is_end_tag ||
2438
    this.is_end_tag = this.is_end_tag ||
2434
      (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
2439
      (this.tag_start_char === '{' && (!options.indent_handlebars || this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
2435
  }
2440
  }
Línea 2436... Línea 2441...
2436
};
2441
};
2437
 
2442
 
Línea 2438... Línea 2443...
2438
Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
2443
Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
Línea 2439... Línea 2444...
2439
  var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
2444
  var parser_token = new TagOpenParserToken(this._options, this._tag_stack.get_parser_token(), raw_token);
2440
 
2445
 
Línea 2901... Línea 2906...
2901
  }
2906
  }
Línea 2902... Línea 2907...
2902
 
2907
 
2903
  token = token || this._read_open_handlebars(c, open_token);
2908
  token = token || this._read_open_handlebars(c, open_token);
2904
  token = token || this._read_attribute(c, previous_token, open_token);
2909
  token = token || this._read_attribute(c, previous_token, open_token);
-
 
2910
  token = token || this._read_close(c, open_token);
2905
  token = token || this._read_close(c, open_token);
2911
  token = token || this._read_script_and_style(c, previous_token);
2906
  token = token || this._read_control_flows(c, open_token);
2912
  token = token || this._read_control_flows(c, open_token);
2907
  token = token || this._read_raw_content(c, previous_token, open_token);
2913
  token = token || this._read_raw_content(c, previous_token, open_token);
2908
  token = token || this._read_content_word(c, open_token);
2914
  token = token || this._read_content_word(c, open_token);
2909
  token = token || this._read_comment_or_cdata(c);
2915
  token = token || this._read_comment_or_cdata(c);
Línea 2986... Línea 2992...
2986
 
2992
 
2987
Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
2993
Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
2988
  var resulting_string = null;
2994
  var resulting_string = null;
2989
  var token = null;
2995
  var token = null;
2990
  if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
2996
  if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
2991
    if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
2997
    if ((this._options.templating.includes('angular') || this._options.indent_handlebars) && c === '{' && this._input.peek(1) === '{') {
2992
      if (this._input.peek(2) === '!') {
2998
      if (this._options.indent_handlebars && this._input.peek(2) === '!') {
2993
        resulting_string = this.__patterns.handlebars_comment.read();
2999
        resulting_string = this.__patterns.handlebars_comment.read();
2994
        resulting_string = resulting_string || this.__patterns.handlebars.read();
3000
        resulting_string = resulting_string || this.__patterns.handlebars.read();
2995
        token = this._create_token(TOKEN.COMMENT, resulting_string);
3001
        token = this._create_token(TOKEN.COMMENT, resulting_string);
2996
      } else {
3002
      } else {
Línea 3003... Línea 3009...
3003
};
3009
};
Línea 3004... Línea 3010...
3004
 
3010
 
3005
Tokenizer.prototype._read_control_flows = function(c, open_token) {
3011
Tokenizer.prototype._read_control_flows = function(c, open_token) {
3006
  var resulting_string = '';
3012
  var resulting_string = '';
3007
  var token = null;
3013
  var token = null;
3008
  // Only check for control flows if angular templating is set AND indenting is set
3014
  // Only check for control flows if angular templating is set
3009
  if (!this._options.templating.includes('angular') || !this._options.indent_handlebars) {
3015
  if (!this._options.templating.includes('angular')) {
3010
    return token;
3016
    return token;
Línea 3011... Línea 3017...
3011
  }
3017
  }
3012
 
3018
 
Línea 3097... Línea 3103...
3097
  return this._options.void_elements.indexOf(tag_name) === -1 &&
3103
  return this._options.void_elements.indexOf(tag_name) === -1 &&
3098
    (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
3104
    (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
3099
      this._options.unformatted.indexOf(tag_name) !== -1);
3105
      this._options.unformatted.indexOf(tag_name) !== -1);
3100
};
3106
};
Línea 3101... Línea -...
3101
 
-
 
3102
 
3107
 
3103
Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
3108
Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
3104
  var resulting_string = '';
3109
  var resulting_string = '';
3105
  if (open_token && open_token.text[0] === '{') {
3110
  if (open_token && open_token.text[0] === '{') {
3106
    resulting_string = this.__patterns.handlebars_raw_close.read();
3111
    resulting_string = this.__patterns.handlebars_raw_close.read();
3107
  } else if (previous_token.type === TOKEN.TAG_CLOSE &&
3112
  } else if (previous_token.type === TOKEN.TAG_CLOSE &&
3108
    previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
3113
    previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
3109
    // ^^ empty tag has no content 
3114
    // ^^ empty tag has no content 
-
 
3115
    var tag_name = previous_token.opened.text.substr(1).toLowerCase();
-
 
3116
    if (this._is_content_unformatted(tag_name)) {
-
 
3117
 
-
 
3118
      resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
-
 
3119
    }
-
 
3120
  }
-
 
3121
 
-
 
3122
  if (resulting_string) {
-
 
3123
    return this._create_token(TOKEN.TEXT, resulting_string);
-
 
3124
  }
-
 
3125
 
-
 
3126
  return null;
-
 
3127
};
-
 
3128
 
-
 
3129
Tokenizer.prototype._read_script_and_style = function(c, previous_token) { // jshint unused:false 
-
 
3130
  if (previous_token.type === TOKEN.TAG_CLOSE && previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
3110
    var tag_name = previous_token.opened.text.substr(1).toLowerCase();
3131
    var tag_name = previous_token.opened.text.substr(1).toLowerCase();
3111
    if (tag_name === 'script' || tag_name === 'style') {
3132
    if (tag_name === 'script' || tag_name === 'style') {
3112
      // Script and style tags are allowed to have comments wrapping their content
3133
      // Script and style tags are allowed to have comments wrapping their content
3113
      // or just have regular content.
3134
      // or just have regular content.
3114
      var token = this._read_comment_or_cdata(c);
3135
      var token = this._read_comment_or_cdata(c);
3115
      if (token) {
3136
      if (token) {
3116
        token.type = TOKEN.TEXT;
3137
        token.type = TOKEN.TEXT;
3117
        return token;
3138
        return token;
3118
      }
3139
      }
3119
      resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
3140
      var resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
3120
    } else if (this._is_content_unformatted(tag_name)) {
-
 
3121
 
3141
      if (resulting_string) {
-
 
3142
        return this._create_token(TOKEN.TEXT, resulting_string);
3122
      resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
3143
      }
3123
    }
3144
    }
3124
  }
-
 
3125
 
-
 
3126
  if (resulting_string) {
-
 
3127
    return this._create_token(TOKEN.TEXT, resulting_string);
-
 
3128
  }
-
 
3129
 
3145
  }
3130
  return null;
3146
  return null;
Línea 3131... Línea 3147...
3131
};
3147
};
3132
 
3148
 
Línea 3142... Línea 3158...
3142
    resulting_string = (open_token && open_token.type === TOKEN.CONTROL_FLOW_OPEN) ? this.__patterns.word_control_flow_close_excluded.read() : this.__patterns.word.read();
3158
    resulting_string = (open_token && open_token.type === TOKEN.CONTROL_FLOW_OPEN) ? this.__patterns.word_control_flow_close_excluded.read() : this.__patterns.word.read();
3143
  }
3159
  }
3144
  if (resulting_string) {
3160
  if (resulting_string) {
3145
    return this._create_token(TOKEN.TEXT, resulting_string);
3161
    return this._create_token(TOKEN.TEXT, resulting_string);
3146
  }
3162
  }
-
 
3163
  return null;
3147
};
3164
};
Línea 3148... Línea 3165...
3148
 
3165
 
3149
module.exports.Tokenizer = Tokenizer;
3166
module.exports.Tokenizer = Tokenizer;