Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/* AUTO-GENERATED. DO NOT MODIFY. */
2
/*
3
 
4
  The MIT License (MIT)
5
 
6
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
7
 
8
  Permission is hereby granted, free of charge, to any person
9
  obtaining a copy of this software and associated documentation files
10
  (the "Software"), to deal in the Software without restriction,
11
  including without limitation the rights to use, copy, modify, merge,
12
  publish, distribute, sublicense, and/or sell copies of the Software,
13
  and to permit persons to whom the Software is furnished to do so,
14
  subject to the following conditions:
15
 
16
  The above copyright notice and this permission notice shall be
17
  included in all copies or substantial portions of the Software.
18
 
19
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
  SOFTWARE.
27
 
28
 
29
 Style HTML
30
---------------
31
 
32
  Written by Nochum Sossonko, (nsossonko@hotmail.com)
33
 
34
  Based on code initially developed by: Einar Lielmanis, <einar@beautifier.io>
35
    https://beautifier.io/
36
 
37
  Usage:
38
    style_html(html_source);
39
 
40
    style_html(html_source, options);
41
 
42
  The options are:
43
    indent_inner_html (default false)  — indent <head> and <body> sections,
44
    indent_size (default 4)          — indentation size,
45
    indent_char (default space)      — character to indent with,
46
    wrap_line_length (default 250)            -  maximum amount of characters per line (0 = disable)
47
    brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none"
48
            put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are.
49
    inline (defaults to inline tags) - list of tags to be considered inline tags
50
    unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted
51
    content_unformatted (defaults to ["pre", "textarea"] tags) - list of tags, whose content shouldn't be reformatted
52
    indent_scripts (default normal)  - "keep"|"separate"|"normal"
53
    preserve_newlines (default true) - whether existing line breaks before elements should be preserved
54
                                        Only works before elements, not inside tags or for text.
55
    max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk
56
    indent_handlebars (default false) - format and indent {{#foo}} and {{/foo}}
57
    end_with_newline (false)          - end with a newline
58
    extra_liners (default [head,body,/html]) -List of tags that should have an extra newline before them.
59
 
60
    e.g.
61
 
62
    style_html(html_source, {
63
      'indent_inner_html': false,
64
      'indent_size': 2,
65
      'indent_char': ' ',
66
      'wrap_line_length': 78,
67
      'brace_style': 'expand',
68
      'preserve_newlines': true,
69
      'max_preserve_newlines': 5,
70
      'indent_handlebars': false,
71
      'extra_liners': ['/html']
72
    });
73
*/
74
 
75
(function() {
76
 
77
/* GENERATED_BUILD_OUTPUT */
78
var legacy_beautify_html;
79
/******/ (function() { // webpackBootstrap
80
/******/ 	"use strict";
81
/******/ 	var __webpack_modules__ = ([
82
/* 0 */,
83
/* 1 */,
84
/* 2 */
85
/***/ (function(module) {
86
 
87
/*jshint node:true */
88
/*
89
  The MIT License (MIT)
90
 
91
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
92
 
93
  Permission is hereby granted, free of charge, to any person
94
  obtaining a copy of this software and associated documentation files
95
  (the "Software"), to deal in the Software without restriction,
96
  including without limitation the rights to use, copy, modify, merge,
97
  publish, distribute, sublicense, and/or sell copies of the Software,
98
  and to permit persons to whom the Software is furnished to do so,
99
  subject to the following conditions:
100
 
101
  The above copyright notice and this permission notice shall be
102
  included in all copies or substantial portions of the Software.
103
 
104
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
105
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
106
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
107
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
108
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
109
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
110
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
111
  SOFTWARE.
112
*/
113
 
114
 
115
 
116
function OutputLine(parent) {
117
  this.__parent = parent;
118
  this.__character_count = 0;
119
  // use indent_count as a marker for this.__lines that have preserved indentation
120
  this.__indent_count = -1;
121
  this.__alignment_count = 0;
122
  this.__wrap_point_index = 0;
123
  this.__wrap_point_character_count = 0;
124
  this.__wrap_point_indent_count = -1;
125
  this.__wrap_point_alignment_count = 0;
126
 
127
  this.__items = [];
128
}
129
 
130
OutputLine.prototype.clone_empty = function() {
131
  var line = new OutputLine(this.__parent);
132
  line.set_indent(this.__indent_count, this.__alignment_count);
133
  return line;
134
};
135
 
136
OutputLine.prototype.item = function(index) {
137
  if (index < 0) {
138
    return this.__items[this.__items.length + index];
139
  } else {
140
    return this.__items[index];
141
  }
142
};
143
 
144
OutputLine.prototype.has_match = function(pattern) {
145
  for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
146
    if (this.__items[lastCheckedOutput].match(pattern)) {
147
      return true;
148
    }
149
  }
150
  return false;
151
};
152
 
153
OutputLine.prototype.set_indent = function(indent, alignment) {
154
  if (this.is_empty()) {
155
    this.__indent_count = indent || 0;
156
    this.__alignment_count = alignment || 0;
157
    this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
158
  }
159
};
160
 
161
OutputLine.prototype._set_wrap_point = function() {
162
  if (this.__parent.wrap_line_length) {
163
    this.__wrap_point_index = this.__items.length;
164
    this.__wrap_point_character_count = this.__character_count;
165
    this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
166
    this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
167
  }
168
};
169
 
170
OutputLine.prototype._should_wrap = function() {
171
  return this.__wrap_point_index &&
172
    this.__character_count > this.__parent.wrap_line_length &&
173
    this.__wrap_point_character_count > this.__parent.next_line.__character_count;
174
};
175
 
176
OutputLine.prototype._allow_wrap = function() {
177
  if (this._should_wrap()) {
178
    this.__parent.add_new_line();
179
    var next = this.__parent.current_line;
180
    next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
181
    next.__items = this.__items.slice(this.__wrap_point_index);
182
    this.__items = this.__items.slice(0, this.__wrap_point_index);
183
 
184
    next.__character_count += this.__character_count - this.__wrap_point_character_count;
185
    this.__character_count = this.__wrap_point_character_count;
186
 
187
    if (next.__items[0] === " ") {
188
      next.__items.splice(0, 1);
189
      next.__character_count -= 1;
190
    }
191
    return true;
192
  }
193
  return false;
194
};
195
 
196
OutputLine.prototype.is_empty = function() {
197
  return this.__items.length === 0;
198
};
199
 
200
OutputLine.prototype.last = function() {
201
  if (!this.is_empty()) {
202
    return this.__items[this.__items.length - 1];
203
  } else {
204
    return null;
205
  }
206
};
207
 
208
OutputLine.prototype.push = function(item) {
209
  this.__items.push(item);
210
  var last_newline_index = item.lastIndexOf('\n');
211
  if (last_newline_index !== -1) {
212
    this.__character_count = item.length - last_newline_index;
213
  } else {
214
    this.__character_count += item.length;
215
  }
216
};
217
 
218
OutputLine.prototype.pop = function() {
219
  var item = null;
220
  if (!this.is_empty()) {
221
    item = this.__items.pop();
222
    this.__character_count -= item.length;
223
  }
224
  return item;
225
};
226
 
227
 
228
OutputLine.prototype._remove_indent = function() {
229
  if (this.__indent_count > 0) {
230
    this.__indent_count -= 1;
231
    this.__character_count -= this.__parent.indent_size;
232
  }
233
};
234
 
235
OutputLine.prototype._remove_wrap_indent = function() {
236
  if (this.__wrap_point_indent_count > 0) {
237
    this.__wrap_point_indent_count -= 1;
238
  }
239
};
240
OutputLine.prototype.trim = function() {
241
  while (this.last() === ' ') {
242
    this.__items.pop();
243
    this.__character_count -= 1;
244
  }
245
};
246
 
247
OutputLine.prototype.toString = function() {
248
  var result = '';
249
  if (this.is_empty()) {
250
    if (this.__parent.indent_empty_lines) {
251
      result = this.__parent.get_indent_string(this.__indent_count);
252
    }
253
  } else {
254
    result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
255
    result += this.__items.join('');
256
  }
257
  return result;
258
};
259
 
260
function IndentStringCache(options, baseIndentString) {
261
  this.__cache = [''];
262
  this.__indent_size = options.indent_size;
263
  this.__indent_string = options.indent_char;
264
  if (!options.indent_with_tabs) {
265
    this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
266
  }
267
 
268
  // Set to null to continue support for auto detection of base indent
269
  baseIndentString = baseIndentString || '';
270
  if (options.indent_level > 0) {
271
    baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
272
  }
273
 
274
  this.__base_string = baseIndentString;
275
  this.__base_string_length = baseIndentString.length;
276
}
277
 
278
IndentStringCache.prototype.get_indent_size = function(indent, column) {
279
  var result = this.__base_string_length;
280
  column = column || 0;
281
  if (indent < 0) {
282
    result = 0;
283
  }
284
  result += indent * this.__indent_size;
285
  result += column;
286
  return result;
287
};
288
 
289
IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
290
  var result = this.__base_string;
291
  column = column || 0;
292
  if (indent_level < 0) {
293
    indent_level = 0;
294
    result = '';
295
  }
296
  column += indent_level * this.__indent_size;
297
  this.__ensure_cache(column);
298
  result += this.__cache[column];
299
  return result;
300
};
301
 
302
IndentStringCache.prototype.__ensure_cache = function(column) {
303
  while (column >= this.__cache.length) {
304
    this.__add_column();
305
  }
306
};
307
 
308
IndentStringCache.prototype.__add_column = function() {
309
  var column = this.__cache.length;
310
  var indent = 0;
311
  var result = '';
312
  if (this.__indent_size && column >= this.__indent_size) {
313
    indent = Math.floor(column / this.__indent_size);
314
    column -= indent * this.__indent_size;
315
    result = new Array(indent + 1).join(this.__indent_string);
316
  }
317
  if (column) {
318
    result += new Array(column + 1).join(' ');
319
  }
320
 
321
  this.__cache.push(result);
322
};
323
 
324
function Output(options, baseIndentString) {
325
  this.__indent_cache = new IndentStringCache(options, baseIndentString);
326
  this.raw = false;
327
  this._end_with_newline = options.end_with_newline;
328
  this.indent_size = options.indent_size;
329
  this.wrap_line_length = options.wrap_line_length;
330
  this.indent_empty_lines = options.indent_empty_lines;
331
  this.__lines = [];
332
  this.previous_line = null;
333
  this.current_line = null;
334
  this.next_line = new OutputLine(this);
335
  this.space_before_token = false;
336
  this.non_breaking_space = false;
337
  this.previous_token_wrapped = false;
338
  // initialize
339
  this.__add_outputline();
340
}
341
 
342
Output.prototype.__add_outputline = function() {
343
  this.previous_line = this.current_line;
344
  this.current_line = this.next_line.clone_empty();
345
  this.__lines.push(this.current_line);
346
};
347
 
348
Output.prototype.get_line_number = function() {
349
  return this.__lines.length;
350
};
351
 
352
Output.prototype.get_indent_string = function(indent, column) {
353
  return this.__indent_cache.get_indent_string(indent, column);
354
};
355
 
356
Output.prototype.get_indent_size = function(indent, column) {
357
  return this.__indent_cache.get_indent_size(indent, column);
358
};
359
 
360
Output.prototype.is_empty = function() {
361
  return !this.previous_line && this.current_line.is_empty();
362
};
363
 
364
Output.prototype.add_new_line = function(force_newline) {
365
  // never newline at the start of file
366
  // otherwise, newline only if we didn't just add one or we're forced
367
  if (this.is_empty() ||
368
    (!force_newline && this.just_added_newline())) {
369
    return false;
370
  }
371
 
372
  // if raw output is enabled, don't print additional newlines,
373
  // but still return True as though you had
374
  if (!this.raw) {
375
    this.__add_outputline();
376
  }
377
  return true;
378
};
379
 
380
Output.prototype.get_code = function(eol) {
381
  this.trim(true);
382
 
383
  // handle some edge cases where the last tokens
384
  // has text that ends with newline(s)
385
  var last_item = this.current_line.pop();
386
  if (last_item) {
387
    if (last_item[last_item.length - 1] === '\n') {
388
      last_item = last_item.replace(/\n+$/g, '');
389
    }
390
    this.current_line.push(last_item);
391
  }
392
 
393
  if (this._end_with_newline) {
394
    this.__add_outputline();
395
  }
396
 
397
  var sweet_code = this.__lines.join('\n');
398
 
399
  if (eol !== '\n') {
400
    sweet_code = sweet_code.replace(/[\n]/g, eol);
401
  }
402
  return sweet_code;
403
};
404
 
405
Output.prototype.set_wrap_point = function() {
406
  this.current_line._set_wrap_point();
407
};
408
 
409
Output.prototype.set_indent = function(indent, alignment) {
410
  indent = indent || 0;
411
  alignment = alignment || 0;
412
 
413
  // Next line stores alignment values
414
  this.next_line.set_indent(indent, alignment);
415
 
416
  // Never indent your first output indent at the start of the file
417
  if (this.__lines.length > 1) {
418
    this.current_line.set_indent(indent, alignment);
419
    return true;
420
  }
421
 
422
  this.current_line.set_indent();
423
  return false;
424
};
425
 
426
Output.prototype.add_raw_token = function(token) {
427
  for (var x = 0; x < token.newlines; x++) {
428
    this.__add_outputline();
429
  }
430
  this.current_line.set_indent(-1);
431
  this.current_line.push(token.whitespace_before);
432
  this.current_line.push(token.text);
433
  this.space_before_token = false;
434
  this.non_breaking_space = false;
435
  this.previous_token_wrapped = false;
436
};
437
 
438
Output.prototype.add_token = function(printable_token) {
439
  this.__add_space_before_token();
440
  this.current_line.push(printable_token);
441
  this.space_before_token = false;
442
  this.non_breaking_space = false;
443
  this.previous_token_wrapped = this.current_line._allow_wrap();
444
};
445
 
446
Output.prototype.__add_space_before_token = function() {
447
  if (this.space_before_token && !this.just_added_newline()) {
448
    if (!this.non_breaking_space) {
449
      this.set_wrap_point();
450
    }
451
    this.current_line.push(' ');
452
  }
453
};
454
 
455
Output.prototype.remove_indent = function(index) {
456
  var output_length = this.__lines.length;
457
  while (index < output_length) {
458
    this.__lines[index]._remove_indent();
459
    index++;
460
  }
461
  this.current_line._remove_wrap_indent();
462
};
463
 
464
Output.prototype.trim = function(eat_newlines) {
465
  eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
466
 
467
  this.current_line.trim();
468
 
469
  while (eat_newlines && this.__lines.length > 1 &&
470
    this.current_line.is_empty()) {
471
    this.__lines.pop();
472
    this.current_line = this.__lines[this.__lines.length - 1];
473
    this.current_line.trim();
474
  }
475
 
476
  this.previous_line = this.__lines.length > 1 ?
477
    this.__lines[this.__lines.length - 2] : null;
478
};
479
 
480
Output.prototype.just_added_newline = function() {
481
  return this.current_line.is_empty();
482
};
483
 
484
Output.prototype.just_added_blankline = function() {
485
  return this.is_empty() ||
486
    (this.current_line.is_empty() && this.previous_line.is_empty());
487
};
488
 
489
Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
490
  var index = this.__lines.length - 2;
491
  while (index >= 0) {
492
    var potentialEmptyLine = this.__lines[index];
493
    if (potentialEmptyLine.is_empty()) {
494
      break;
495
    } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
496
      potentialEmptyLine.item(-1) !== ends_with) {
497
      this.__lines.splice(index + 1, 0, new OutputLine(this));
498
      this.previous_line = this.__lines[this.__lines.length - 2];
499
      break;
500
    }
501
    index--;
502
  }
503
};
504
 
505
module.exports.Output = Output;
506
 
507
 
508
/***/ }),
509
/* 3 */
510
/***/ (function(module) {
511
 
512
/*jshint node:true */
513
/*
514
 
515
  The MIT License (MIT)
516
 
517
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
518
 
519
  Permission is hereby granted, free of charge, to any person
520
  obtaining a copy of this software and associated documentation files
521
  (the "Software"), to deal in the Software without restriction,
522
  including without limitation the rights to use, copy, modify, merge,
523
  publish, distribute, sublicense, and/or sell copies of the Software,
524
  and to permit persons to whom the Software is furnished to do so,
525
  subject to the following conditions:
526
 
527
  The above copyright notice and this permission notice shall be
528
  included in all copies or substantial portions of the Software.
529
 
530
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
531
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
532
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
533
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
534
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
535
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
536
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
537
  SOFTWARE.
538
*/
539
 
540
 
541
 
542
function Token(type, text, newlines, whitespace_before) {
543
  this.type = type;
544
  this.text = text;
545
 
546
  // comments_before are
547
  // comments that have a new line before them
548
  // and may or may not have a newline after
549
  // this is a set of comments before
550
  this.comments_before = null; /* inline comment*/
551
 
552
 
553
  // this.comments_after =  new TokenStream(); // no new line before and newline after
554
  this.newlines = newlines || 0;
555
  this.whitespace_before = whitespace_before || '';
556
  this.parent = null;
557
  this.next = null;
558
  this.previous = null;
559
  this.opened = null;
560
  this.closed = null;
561
  this.directives = null;
562
}
563
 
564
 
565
module.exports.Token = Token;
566
 
567
 
568
/***/ }),
569
/* 4 */,
570
/* 5 */,
571
/* 6 */
572
/***/ (function(module) {
573
 
574
/*jshint node:true */
575
/*
576
 
577
  The MIT License (MIT)
578
 
579
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
580
 
581
  Permission is hereby granted, free of charge, to any person
582
  obtaining a copy of this software and associated documentation files
583
  (the "Software"), to deal in the Software without restriction,
584
  including without limitation the rights to use, copy, modify, merge,
585
  publish, distribute, sublicense, and/or sell copies of the Software,
586
  and to permit persons to whom the Software is furnished to do so,
587
  subject to the following conditions:
588
 
589
  The above copyright notice and this permission notice shall be
590
  included in all copies or substantial portions of the Software.
591
 
592
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
593
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
594
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
595
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
596
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
597
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
598
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
599
  SOFTWARE.
600
*/
601
 
602
 
603
 
604
function Options(options, merge_child_field) {
605
  this.raw_options = _mergeOpts(options, merge_child_field);
606
 
607
  // Support passing the source text back with no change
608
  this.disabled = this._get_boolean('disabled');
609
 
610
  this.eol = this._get_characters('eol', 'auto');
611
  this.end_with_newline = this._get_boolean('end_with_newline');
612
  this.indent_size = this._get_number('indent_size', 4);
613
  this.indent_char = this._get_characters('indent_char', ' ');
614
  this.indent_level = this._get_number('indent_level');
615
 
616
  this.preserve_newlines = this._get_boolean('preserve_newlines', true);
617
  this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
618
  if (!this.preserve_newlines) {
619
    this.max_preserve_newlines = 0;
620
  }
621
 
622
  this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
623
  if (this.indent_with_tabs) {
624
    this.indent_char = '\t';
625
 
626
    // indent_size behavior changed after 1.8.6
627
    // It used to be that indent_size would be
628
    // set to 1 for indent_with_tabs. That is no longer needed and
629
    // actually doesn't make sense - why not use spaces? Further,
630
    // that might produce unexpected behavior - tabs being used
631
    // for single-column alignment. So, when indent_with_tabs is true
632
    // and indent_size is 1, reset indent_size to 4.
633
    if (this.indent_size === 1) {
634
      this.indent_size = 4;
635
    }
636
  }
637
 
638
  // Backwards compat with 1.3.x
639
  this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
640
 
641
  this.indent_empty_lines = this._get_boolean('indent_empty_lines');
642
 
643
  // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty', 'angular']
644
  // For now, 'auto' = all off for javascript, all except angular on for html (and inline javascript/css).
645
  // other values ignored
646
  this.templating = this._get_selection_list('templating', ['auto', 'none', 'angular', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
647
}
648
 
649
Options.prototype._get_array = function(name, default_value) {
650
  var option_value = this.raw_options[name];
651
  var result = default_value || [];
652
  if (typeof option_value === 'object') {
653
    if (option_value !== null && typeof option_value.concat === 'function') {
654
      result = option_value.concat();
655
    }
656
  } else if (typeof option_value === 'string') {
657
    result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
658
  }
659
  return result;
660
};
661
 
662
Options.prototype._get_boolean = function(name, default_value) {
663
  var option_value = this.raw_options[name];
664
  var result = option_value === undefined ? !!default_value : !!option_value;
665
  return result;
666
};
667
 
668
Options.prototype._get_characters = function(name, default_value) {
669
  var option_value = this.raw_options[name];
670
  var result = default_value || '';
671
  if (typeof option_value === 'string') {
672
    result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
673
  }
674
  return result;
675
};
676
 
677
Options.prototype._get_number = function(name, default_value) {
678
  var option_value = this.raw_options[name];
679
  default_value = parseInt(default_value, 10);
680
  if (isNaN(default_value)) {
681
    default_value = 0;
682
  }
683
  var result = parseInt(option_value, 10);
684
  if (isNaN(result)) {
685
    result = default_value;
686
  }
687
  return result;
688
};
689
 
690
Options.prototype._get_selection = function(name, selection_list, default_value) {
691
  var result = this._get_selection_list(name, selection_list, default_value);
692
  if (result.length !== 1) {
693
    throw new Error(
694
      "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
695
      selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
696
  }
697
 
698
  return result[0];
699
};
700
 
701
 
702
Options.prototype._get_selection_list = function(name, selection_list, default_value) {
703
  if (!selection_list || selection_list.length === 0) {
704
    throw new Error("Selection list cannot be empty.");
705
  }
706
 
707
  default_value = default_value || [selection_list[0]];
708
  if (!this._is_valid_selection(default_value, selection_list)) {
709
    throw new Error("Invalid Default Value!");
710
  }
711
 
712
  var result = this._get_array(name, default_value);
713
  if (!this._is_valid_selection(result, selection_list)) {
714
    throw new Error(
715
      "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
716
      selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
717
  }
718
 
719
  return result;
720
};
721
 
722
Options.prototype._is_valid_selection = function(result, selection_list) {
723
  return result.length && selection_list.length &&
724
    !result.some(function(item) { return selection_list.indexOf(item) === -1; });
725
};
726
 
727
 
728
// merges child options up with the parent options object
729
// Example: obj = {a: 1, b: {a: 2}}
730
//          mergeOpts(obj, 'b')
731
//
732
//          Returns: {a: 2}
733
function _mergeOpts(allOptions, childFieldName) {
734
  var finalOpts = {};
735
  allOptions = _normalizeOpts(allOptions);
736
  var name;
737
 
738
  for (name in allOptions) {
739
    if (name !== childFieldName) {
740
      finalOpts[name] = allOptions[name];
741
    }
742
  }
743
 
744
  //merge in the per type settings for the childFieldName
745
  if (childFieldName && allOptions[childFieldName]) {
746
    for (name in allOptions[childFieldName]) {
747
      finalOpts[name] = allOptions[childFieldName][name];
748
    }
749
  }
750
  return finalOpts;
751
}
752
 
753
function _normalizeOpts(options) {
754
  var convertedOpts = {};
755
  var key;
756
 
757
  for (key in options) {
758
    var newKey = key.replace(/-/g, "_");
759
    convertedOpts[newKey] = options[key];
760
  }
761
  return convertedOpts;
762
}
763
 
764
module.exports.Options = Options;
765
module.exports.normalizeOpts = _normalizeOpts;
766
module.exports.mergeOpts = _mergeOpts;
767
 
768
 
769
/***/ }),
770
/* 7 */,
771
/* 8 */
772
/***/ (function(module) {
773
 
774
/*jshint node:true */
775
/*
776
 
777
  The MIT License (MIT)
778
 
779
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
780
 
781
  Permission is hereby granted, free of charge, to any person
782
  obtaining a copy of this software and associated documentation files
783
  (the "Software"), to deal in the Software without restriction,
784
  including without limitation the rights to use, copy, modify, merge,
785
  publish, distribute, sublicense, and/or sell copies of the Software,
786
  and to permit persons to whom the Software is furnished to do so,
787
  subject to the following conditions:
788
 
789
  The above copyright notice and this permission notice shall be
790
  included in all copies or substantial portions of the Software.
791
 
792
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
793
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
794
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
795
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
796
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
797
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
798
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
799
  SOFTWARE.
800
*/
801
 
802
 
803
 
804
var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
805
 
806
function InputScanner(input_string) {
807
  this.__input = input_string || '';
808
  this.__input_length = this.__input.length;
809
  this.__position = 0;
810
}
811
 
812
InputScanner.prototype.restart = function() {
813
  this.__position = 0;
814
};
815
 
816
InputScanner.prototype.back = function() {
817
  if (this.__position > 0) {
818
    this.__position -= 1;
819
  }
820
};
821
 
822
InputScanner.prototype.hasNext = function() {
823
  return this.__position < this.__input_length;
824
};
825
 
826
InputScanner.prototype.next = function() {
827
  var val = null;
828
  if (this.hasNext()) {
829
    val = this.__input.charAt(this.__position);
830
    this.__position += 1;
831
  }
832
  return val;
833
};
834
 
835
InputScanner.prototype.peek = function(index) {
836
  var val = null;
837
  index = index || 0;
838
  index += this.__position;
839
  if (index >= 0 && index < this.__input_length) {
840
    val = this.__input.charAt(index);
841
  }
842
  return val;
843
};
844
 
845
// This is a JavaScript only helper function (not in python)
846
// Javascript doesn't have a match method
847
// and not all implementation support "sticky" flag.
848
// If they do not support sticky then both this.match() and this.test() method
849
// must get the match and check the index of the match.
850
// If sticky is supported and set, this method will use it.
851
// Otherwise it will check that global is set, and fall back to the slower method.
852
InputScanner.prototype.__match = function(pattern, index) {
853
  pattern.lastIndex = index;
854
  var pattern_match = pattern.exec(this.__input);
855
 
856
  if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
857
    if (pattern_match.index !== index) {
858
      pattern_match = null;
859
    }
860
  }
861
 
862
  return pattern_match;
863
};
864
 
865
InputScanner.prototype.test = function(pattern, index) {
866
  index = index || 0;
867
  index += this.__position;
868
 
869
  if (index >= 0 && index < this.__input_length) {
870
    return !!this.__match(pattern, index);
871
  } else {
872
    return false;
873
  }
874
};
875
 
876
InputScanner.prototype.testChar = function(pattern, index) {
877
  // test one character regex match
878
  var val = this.peek(index);
879
  pattern.lastIndex = 0;
880
  return val !== null && pattern.test(val);
881
};
882
 
883
InputScanner.prototype.match = function(pattern) {
884
  var pattern_match = this.__match(pattern, this.__position);
885
  if (pattern_match) {
886
    this.__position += pattern_match[0].length;
887
  } else {
888
    pattern_match = null;
889
  }
890
  return pattern_match;
891
};
892
 
893
InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
894
  var val = '';
895
  var match;
896
  if (starting_pattern) {
897
    match = this.match(starting_pattern);
898
    if (match) {
899
      val += match[0];
900
    }
901
  }
902
  if (until_pattern && (match || !starting_pattern)) {
903
    val += this.readUntil(until_pattern, until_after);
904
  }
905
  return val;
906
};
907
 
908
InputScanner.prototype.readUntil = function(pattern, until_after) {
909
  var val = '';
910
  var match_index = this.__position;
911
  pattern.lastIndex = this.__position;
912
  var pattern_match = pattern.exec(this.__input);
913
  if (pattern_match) {
914
    match_index = pattern_match.index;
915
    if (until_after) {
916
      match_index += pattern_match[0].length;
917
    }
918
  } else {
919
    match_index = this.__input_length;
920
  }
921
 
922
  val = this.__input.substring(this.__position, match_index);
923
  this.__position = match_index;
924
  return val;
925
};
926
 
927
InputScanner.prototype.readUntilAfter = function(pattern) {
928
  return this.readUntil(pattern, true);
929
};
930
 
931
InputScanner.prototype.get_regexp = function(pattern, match_from) {
932
  var result = null;
933
  var flags = 'g';
934
  if (match_from && regexp_has_sticky) {
935
    flags = 'y';
936
  }
937
  // strings are converted to regexp
938
  if (typeof pattern === "string" && pattern !== '') {
939
    // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
940
    result = new RegExp(pattern, flags);
941
  } else if (pattern) {
942
    result = new RegExp(pattern.source, flags);
943
  }
944
  return result;
945
};
946
 
947
InputScanner.prototype.get_literal_regexp = function(literal_string) {
948
  return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
949
};
950
 
951
/* css beautifier legacy helpers */
952
InputScanner.prototype.peekUntilAfter = function(pattern) {
953
  var start = this.__position;
954
  var val = this.readUntilAfter(pattern);
955
  this.__position = start;
956
  return val;
957
};
958
 
959
InputScanner.prototype.lookBack = function(testVal) {
960
  var start = this.__position - 1;
961
  return start >= testVal.length && this.__input.substring(start - testVal.length, start)
962
    .toLowerCase() === testVal;
963
};
964
 
965
module.exports.InputScanner = InputScanner;
966
 
967
 
968
/***/ }),
969
/* 9 */
970
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
971
 
972
/*jshint node:true */
973
/*
974
 
975
  The MIT License (MIT)
976
 
977
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
978
 
979
  Permission is hereby granted, free of charge, to any person
980
  obtaining a copy of this software and associated documentation files
981
  (the "Software"), to deal in the Software without restriction,
982
  including without limitation the rights to use, copy, modify, merge,
983
  publish, distribute, sublicense, and/or sell copies of the Software,
984
  and to permit persons to whom the Software is furnished to do so,
985
  subject to the following conditions:
986
 
987
  The above copyright notice and this permission notice shall be
988
  included in all copies or substantial portions of the Software.
989
 
990
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
991
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
992
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
993
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
994
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
995
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
996
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
997
  SOFTWARE.
998
*/
999
 
1000
 
1001
 
1002
var InputScanner = (__webpack_require__(8).InputScanner);
1003
var Token = (__webpack_require__(3).Token);
1004
var TokenStream = (__webpack_require__(10).TokenStream);
1005
var WhitespacePattern = (__webpack_require__(11).WhitespacePattern);
1006
 
1007
var TOKEN = {
1008
  START: 'TK_START',
1009
  RAW: 'TK_RAW',
1010
  EOF: 'TK_EOF'
1011
};
1012
 
1013
var Tokenizer = function(input_string, options) {
1014
  this._input = new InputScanner(input_string);
1015
  this._options = options || {};
1016
  this.__tokens = null;
1017
 
1018
  this._patterns = {};
1019
  this._patterns.whitespace = new WhitespacePattern(this._input);
1020
};
1021
 
1022
Tokenizer.prototype.tokenize = function() {
1023
  this._input.restart();
1024
  this.__tokens = new TokenStream();
1025
 
1026
  this._reset();
1027
 
1028
  var current;
1029
  var previous = new Token(TOKEN.START, '');
1030
  var open_token = null;
1031
  var open_stack = [];
1032
  var comments = new TokenStream();
1033
 
1034
  while (previous.type !== TOKEN.EOF) {
1035
    current = this._get_next_token(previous, open_token);
1036
    while (this._is_comment(current)) {
1037
      comments.add(current);
1038
      current = this._get_next_token(previous, open_token);
1039
    }
1040
 
1041
    if (!comments.isEmpty()) {
1042
      current.comments_before = comments;
1043
      comments = new TokenStream();
1044
    }
1045
 
1046
    current.parent = open_token;
1047
 
1048
    if (this._is_opening(current)) {
1049
      open_stack.push(open_token);
1050
      open_token = current;
1051
    } else if (open_token && this._is_closing(current, open_token)) {
1052
      current.opened = open_token;
1053
      open_token.closed = current;
1054
      open_token = open_stack.pop();
1055
      current.parent = open_token;
1056
    }
1057
 
1058
    current.previous = previous;
1059
    previous.next = current;
1060
 
1061
    this.__tokens.add(current);
1062
    previous = current;
1063
  }
1064
 
1065
  return this.__tokens;
1066
};
1067
 
1068
 
1069
Tokenizer.prototype._is_first_token = function() {
1070
  return this.__tokens.isEmpty();
1071
};
1072
 
1073
Tokenizer.prototype._reset = function() {};
1074
 
1075
Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
1076
  this._readWhitespace();
1077
  var resulting_string = this._input.read(/.+/g);
1078
  if (resulting_string) {
1079
    return this._create_token(TOKEN.RAW, resulting_string);
1080
  } else {
1081
    return this._create_token(TOKEN.EOF, '');
1082
  }
1083
};
1084
 
1085
Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
1086
  return false;
1087
};
1088
 
1089
Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
1090
  return false;
1091
};
1092
 
1093
Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
1094
  return false;
1095
};
1096
 
1097
Tokenizer.prototype._create_token = function(type, text) {
1098
  var token = new Token(type, text,
1099
    this._patterns.whitespace.newline_count,
1100
    this._patterns.whitespace.whitespace_before_token);
1101
  return token;
1102
};
1103
 
1104
Tokenizer.prototype._readWhitespace = function() {
1105
  return this._patterns.whitespace.read();
1106
};
1107
 
1108
 
1109
 
1110
module.exports.Tokenizer = Tokenizer;
1111
module.exports.TOKEN = TOKEN;
1112
 
1113
 
1114
/***/ }),
1115
/* 10 */
1116
/***/ (function(module) {
1117
 
1118
/*jshint node:true */
1119
/*
1120
 
1121
  The MIT License (MIT)
1122
 
1123
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
1124
 
1125
  Permission is hereby granted, free of charge, to any person
1126
  obtaining a copy of this software and associated documentation files
1127
  (the "Software"), to deal in the Software without restriction,
1128
  including without limitation the rights to use, copy, modify, merge,
1129
  publish, distribute, sublicense, and/or sell copies of the Software,
1130
  and to permit persons to whom the Software is furnished to do so,
1131
  subject to the following conditions:
1132
 
1133
  The above copyright notice and this permission notice shall be
1134
  included in all copies or substantial portions of the Software.
1135
 
1136
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1137
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1138
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1139
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1140
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1141
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1142
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1143
  SOFTWARE.
1144
*/
1145
 
1146
 
1147
 
1148
function TokenStream(parent_token) {
1149
  // private
1150
  this.__tokens = [];
1151
  this.__tokens_length = this.__tokens.length;
1152
  this.__position = 0;
1153
  this.__parent_token = parent_token;
1154
}
1155
 
1156
TokenStream.prototype.restart = function() {
1157
  this.__position = 0;
1158
};
1159
 
1160
TokenStream.prototype.isEmpty = function() {
1161
  return this.__tokens_length === 0;
1162
};
1163
 
1164
TokenStream.prototype.hasNext = function() {
1165
  return this.__position < this.__tokens_length;
1166
};
1167
 
1168
TokenStream.prototype.next = function() {
1169
  var val = null;
1170
  if (this.hasNext()) {
1171
    val = this.__tokens[this.__position];
1172
    this.__position += 1;
1173
  }
1174
  return val;
1175
};
1176
 
1177
TokenStream.prototype.peek = function(index) {
1178
  var val = null;
1179
  index = index || 0;
1180
  index += this.__position;
1181
  if (index >= 0 && index < this.__tokens_length) {
1182
    val = this.__tokens[index];
1183
  }
1184
  return val;
1185
};
1186
 
1187
TokenStream.prototype.add = function(token) {
1188
  if (this.__parent_token) {
1189
    token.parent = this.__parent_token;
1190
  }
1191
  this.__tokens.push(token);
1192
  this.__tokens_length += 1;
1193
};
1194
 
1195
module.exports.TokenStream = TokenStream;
1196
 
1197
 
1198
/***/ }),
1199
/* 11 */
1200
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
1201
 
1202
/*jshint node:true */
1203
/*
1204
 
1205
  The MIT License (MIT)
1206
 
1207
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
1208
 
1209
  Permission is hereby granted, free of charge, to any person
1210
  obtaining a copy of this software and associated documentation files
1211
  (the "Software"), to deal in the Software without restriction,
1212
  including without limitation the rights to use, copy, modify, merge,
1213
  publish, distribute, sublicense, and/or sell copies of the Software,
1214
  and to permit persons to whom the Software is furnished to do so,
1215
  subject to the following conditions:
1216
 
1217
  The above copyright notice and this permission notice shall be
1218
  included in all copies or substantial portions of the Software.
1219
 
1220
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1221
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1222
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1223
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1224
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1225
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1226
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1227
  SOFTWARE.
1228
*/
1229
 
1230
 
1231
 
1232
var Pattern = (__webpack_require__(12).Pattern);
1233
 
1234
function WhitespacePattern(input_scanner, parent) {
1235
  Pattern.call(this, input_scanner, parent);
1236
  if (parent) {
1237
    this._line_regexp = this._input.get_regexp(parent._line_regexp);
1238
  } else {
1239
    this.__set_whitespace_patterns('', '');
1240
  }
1241
 
1242
  this.newline_count = 0;
1243
  this.whitespace_before_token = '';
1244
}
1245
WhitespacePattern.prototype = new Pattern();
1246
 
1247
WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
1248
  whitespace_chars += '\\t ';
1249
  newline_chars += '\\n\\r';
1250
 
1251
  this._match_pattern = this._input.get_regexp(
1252
    '[' + whitespace_chars + newline_chars + ']+', true);
1253
  this._newline_regexp = this._input.get_regexp(
1254
    '\\r\\n|[' + newline_chars + ']');
1255
};
1256
 
1257
WhitespacePattern.prototype.read = function() {
1258
  this.newline_count = 0;
1259
  this.whitespace_before_token = '';
1260
 
1261
  var resulting_string = this._input.read(this._match_pattern);
1262
  if (resulting_string === ' ') {
1263
    this.whitespace_before_token = ' ';
1264
  } else if (resulting_string) {
1265
    var matches = this.__split(this._newline_regexp, resulting_string);
1266
    this.newline_count = matches.length - 1;
1267
    this.whitespace_before_token = matches[this.newline_count];
1268
  }
1269
 
1270
  return resulting_string;
1271
};
1272
 
1273
WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
1274
  var result = this._create();
1275
  result.__set_whitespace_patterns(whitespace_chars, newline_chars);
1276
  result._update();
1277
  return result;
1278
};
1279
 
1280
WhitespacePattern.prototype._create = function() {
1281
  return new WhitespacePattern(this._input, this);
1282
};
1283
 
1284
WhitespacePattern.prototype.__split = function(regexp, input_string) {
1285
  regexp.lastIndex = 0;
1286
  var start_index = 0;
1287
  var result = [];
1288
  var next_match = regexp.exec(input_string);
1289
  while (next_match) {
1290
    result.push(input_string.substring(start_index, next_match.index));
1291
    start_index = next_match.index + next_match[0].length;
1292
    next_match = regexp.exec(input_string);
1293
  }
1294
 
1295
  if (start_index < input_string.length) {
1296
    result.push(input_string.substring(start_index, input_string.length));
1297
  } else {
1298
    result.push('');
1299
  }
1300
 
1301
  return result;
1302
};
1303
 
1304
 
1305
 
1306
module.exports.WhitespacePattern = WhitespacePattern;
1307
 
1308
 
1309
/***/ }),
1310
/* 12 */
1311
/***/ (function(module) {
1312
 
1313
/*jshint node:true */
1314
/*
1315
 
1316
  The MIT License (MIT)
1317
 
1318
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
1319
 
1320
  Permission is hereby granted, free of charge, to any person
1321
  obtaining a copy of this software and associated documentation files
1322
  (the "Software"), to deal in the Software without restriction,
1323
  including without limitation the rights to use, copy, modify, merge,
1324
  publish, distribute, sublicense, and/or sell copies of the Software,
1325
  and to permit persons to whom the Software is furnished to do so,
1326
  subject to the following conditions:
1327
 
1328
  The above copyright notice and this permission notice shall be
1329
  included in all copies or substantial portions of the Software.
1330
 
1331
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1332
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1333
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1334
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1335
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1336
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1337
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1338
  SOFTWARE.
1339
*/
1340
 
1341
 
1342
 
1343
function Pattern(input_scanner, parent) {
1344
  this._input = input_scanner;
1345
  this._starting_pattern = null;
1346
  this._match_pattern = null;
1347
  this._until_pattern = null;
1348
  this._until_after = false;
1349
 
1350
  if (parent) {
1351
    this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
1352
    this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
1353
    this._until_pattern = this._input.get_regexp(parent._until_pattern);
1354
    this._until_after = parent._until_after;
1355
  }
1356
}
1357
 
1358
Pattern.prototype.read = function() {
1359
  var result = this._input.read(this._starting_pattern);
1360
  if (!this._starting_pattern || result) {
1361
    result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
1362
  }
1363
  return result;
1364
};
1365
 
1366
Pattern.prototype.read_match = function() {
1367
  return this._input.match(this._match_pattern);
1368
};
1369
 
1370
Pattern.prototype.until_after = function(pattern) {
1371
  var result = this._create();
1372
  result._until_after = true;
1373
  result._until_pattern = this._input.get_regexp(pattern);
1374
  result._update();
1375
  return result;
1376
};
1377
 
1378
Pattern.prototype.until = function(pattern) {
1379
  var result = this._create();
1380
  result._until_after = false;
1381
  result._until_pattern = this._input.get_regexp(pattern);
1382
  result._update();
1383
  return result;
1384
};
1385
 
1386
Pattern.prototype.starting_with = function(pattern) {
1387
  var result = this._create();
1388
  result._starting_pattern = this._input.get_regexp(pattern, true);
1389
  result._update();
1390
  return result;
1391
};
1392
 
1393
Pattern.prototype.matching = function(pattern) {
1394
  var result = this._create();
1395
  result._match_pattern = this._input.get_regexp(pattern, true);
1396
  result._update();
1397
  return result;
1398
};
1399
 
1400
Pattern.prototype._create = function() {
1401
  return new Pattern(this._input, this);
1402
};
1403
 
1404
Pattern.prototype._update = function() {};
1405
 
1406
module.exports.Pattern = Pattern;
1407
 
1408
 
1409
/***/ }),
1410
/* 13 */
1411
/***/ (function(module) {
1412
 
1413
/*jshint node:true */
1414
/*
1415
 
1416
  The MIT License (MIT)
1417
 
1418
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
1419
 
1420
  Permission is hereby granted, free of charge, to any person
1421
  obtaining a copy of this software and associated documentation files
1422
  (the "Software"), to deal in the Software without restriction,
1423
  including without limitation the rights to use, copy, modify, merge,
1424
  publish, distribute, sublicense, and/or sell copies of the Software,
1425
  and to permit persons to whom the Software is furnished to do so,
1426
  subject to the following conditions:
1427
 
1428
  The above copyright notice and this permission notice shall be
1429
  included in all copies or substantial portions of the Software.
1430
 
1431
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1432
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1433
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1434
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1435
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1436
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1437
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1438
  SOFTWARE.
1439
*/
1440
 
1441
 
1442
 
1443
function Directives(start_block_pattern, end_block_pattern) {
1444
  start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
1445
  end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
1446
  this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
1447
  this.__directive_pattern = / (\w+)[:](\w+)/g;
1448
 
1449
  this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
1450
}
1451
 
1452
Directives.prototype.get_directives = function(text) {
1453
  if (!text.match(this.__directives_block_pattern)) {
1454
    return null;
1455
  }
1456
 
1457
  var directives = {};
1458
  this.__directive_pattern.lastIndex = 0;
1459
  var directive_match = this.__directive_pattern.exec(text);
1460
 
1461
  while (directive_match) {
1462
    directives[directive_match[1]] = directive_match[2];
1463
    directive_match = this.__directive_pattern.exec(text);
1464
  }
1465
 
1466
  return directives;
1467
};
1468
 
1469
Directives.prototype.readIgnored = function(input) {
1470
  return input.readUntilAfter(this.__directives_end_ignore_pattern);
1471
};
1472
 
1473
 
1474
module.exports.Directives = Directives;
1475
 
1476
 
1477
/***/ }),
1478
/* 14 */
1479
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
1480
 
1481
/*jshint node:true */
1482
/*
1483
 
1484
  The MIT License (MIT)
1485
 
1486
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
1487
 
1488
  Permission is hereby granted, free of charge, to any person
1489
  obtaining a copy of this software and associated documentation files
1490
  (the "Software"), to deal in the Software without restriction,
1491
  including without limitation the rights to use, copy, modify, merge,
1492
  publish, distribute, sublicense, and/or sell copies of the Software,
1493
  and to permit persons to whom the Software is furnished to do so,
1494
  subject to the following conditions:
1495
 
1496
  The above copyright notice and this permission notice shall be
1497
  included in all copies or substantial portions of the Software.
1498
 
1499
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1500
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1501
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1502
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1503
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1504
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1505
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1506
  SOFTWARE.
1507
*/
1508
 
1509
 
1510
 
1511
var Pattern = (__webpack_require__(12).Pattern);
1512
 
1513
 
1514
var template_names = {
1515
  django: false,
1516
  erb: false,
1517
  handlebars: false,
1518
  php: false,
1519
  smarty: false,
1520
  angular: false
1521
};
1522
 
1523
// This lets templates appear anywhere we would do a readUntil
1524
// The cost is higher but it is pay to play.
1525
function TemplatablePattern(input_scanner, parent) {
1526
  Pattern.call(this, input_scanner, parent);
1527
  this.__template_pattern = null;
1528
  this._disabled = Object.assign({}, template_names);
1529
  this._excluded = Object.assign({}, template_names);
1530
 
1531
  if (parent) {
1532
    this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
1533
    this._excluded = Object.assign(this._excluded, parent._excluded);
1534
    this._disabled = Object.assign(this._disabled, parent._disabled);
1535
  }
1536
  var pattern = new Pattern(input_scanner);
1537
  this.__patterns = {
1538
    handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
1539
    handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
1540
    handlebars: pattern.starting_with(/{{/).until_after(/}}/),
1541
    php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
1542
    erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
1543
    // django coflicts with handlebars a bit.
1544
    django: pattern.starting_with(/{%/).until_after(/%}/),
1545
    django_value: pattern.starting_with(/{{/).until_after(/}}/),
1546
    django_comment: pattern.starting_with(/{#/).until_after(/#}/),
1547
    smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
1548
    smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
1549
    smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
1550
  };
1551
}
1552
TemplatablePattern.prototype = new Pattern();
1553
 
1554
TemplatablePattern.prototype._create = function() {
1555
  return new TemplatablePattern(this._input, this);
1556
};
1557
 
1558
TemplatablePattern.prototype._update = function() {
1559
  this.__set_templated_pattern();
1560
};
1561
 
1562
TemplatablePattern.prototype.disable = function(language) {
1563
  var result = this._create();
1564
  result._disabled[language] = true;
1565
  result._update();
1566
  return result;
1567
};
1568
 
1569
TemplatablePattern.prototype.read_options = function(options) {
1570
  var result = this._create();
1571
  for (var language in template_names) {
1572
    result._disabled[language] = options.templating.indexOf(language) === -1;
1573
  }
1574
  result._update();
1575
  return result;
1576
};
1577
 
1578
TemplatablePattern.prototype.exclude = function(language) {
1579
  var result = this._create();
1580
  result._excluded[language] = true;
1581
  result._update();
1582
  return result;
1583
};
1584
 
1585
TemplatablePattern.prototype.read = function() {
1586
  var result = '';
1587
  if (this._match_pattern) {
1588
    result = this._input.read(this._starting_pattern);
1589
  } else {
1590
    result = this._input.read(this._starting_pattern, this.__template_pattern);
1591
  }
1592
  var next = this._read_template();
1593
  while (next) {
1594
    if (this._match_pattern) {
1595
      next += this._input.read(this._match_pattern);
1596
    } else {
1597
      next += this._input.readUntil(this.__template_pattern);
1598
    }
1599
    result += next;
1600
    next = this._read_template();
1601
  }
1602
 
1603
  if (this._until_after) {
1604
    result += this._input.readUntilAfter(this._until_pattern);
1605
  }
1606
  return result;
1607
};
1608
 
1609
TemplatablePattern.prototype.__set_templated_pattern = function() {
1610
  var items = [];
1611
 
1612
  if (!this._disabled.php) {
1613
    items.push(this.__patterns.php._starting_pattern.source);
1614
  }
1615
  if (!this._disabled.handlebars) {
1616
    items.push(this.__patterns.handlebars._starting_pattern.source);
1617
  }
1618
  if (!this._disabled.erb) {
1619
    items.push(this.__patterns.erb._starting_pattern.source);
1620
  }
1621
  if (!this._disabled.django) {
1622
    items.push(this.__patterns.django._starting_pattern.source);
1623
    // The starting pattern for django is more complex because it has different
1624
    // patterns for value, comment, and other sections
1625
    items.push(this.__patterns.django_value._starting_pattern.source);
1626
    items.push(this.__patterns.django_comment._starting_pattern.source);
1627
  }
1628
  if (!this._disabled.smarty) {
1629
    items.push(this.__patterns.smarty._starting_pattern.source);
1630
  }
1631
 
1632
  if (this._until_pattern) {
1633
    items.push(this._until_pattern.source);
1634
  }
1635
  this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
1636
};
1637
 
1638
TemplatablePattern.prototype._read_template = function() {
1639
  var resulting_string = '';
1640
  var c = this._input.peek();
1641
  if (c === '<') {
1642
    var peek1 = this._input.peek(1);
1643
    //if we're in a comment, do something special
1644
    // We treat all comments as literals, even more than preformatted tags
1645
    // we just look for the appropriate close tag
1646
    if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
1647
      resulting_string = resulting_string ||
1648
        this.__patterns.php.read();
1649
    }
1650
    if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
1651
      resulting_string = resulting_string ||
1652
        this.__patterns.erb.read();
1653
    }
1654
  } else if (c === '{') {
1655
    if (!this._disabled.handlebars && !this._excluded.handlebars) {
1656
      resulting_string = resulting_string ||
1657
        this.__patterns.handlebars_comment.read();
1658
      resulting_string = resulting_string ||
1659
        this.__patterns.handlebars_unescaped.read();
1660
      resulting_string = resulting_string ||
1661
        this.__patterns.handlebars.read();
1662
    }
1663
    if (!this._disabled.django) {
1664
      // django coflicts with handlebars a bit.
1665
      if (!this._excluded.django && !this._excluded.handlebars) {
1666
        resulting_string = resulting_string ||
1667
          this.__patterns.django_value.read();
1668
      }
1669
      if (!this._excluded.django) {
1670
        resulting_string = resulting_string ||
1671
          this.__patterns.django_comment.read();
1672
        resulting_string = resulting_string ||
1673
          this.__patterns.django.read();
1674
      }
1675
    }
1676
    if (!this._disabled.smarty) {
1677
      // smarty cannot be enabled with django or handlebars enabled
1678
      if (this._disabled.django && this._disabled.handlebars) {
1679
        resulting_string = resulting_string ||
1680
          this.__patterns.smarty_comment.read();
1681
        resulting_string = resulting_string ||
1682
          this.__patterns.smarty_literal.read();
1683
        resulting_string = resulting_string ||
1684
          this.__patterns.smarty.read();
1685
      }
1686
    }
1687
  }
1688
  return resulting_string;
1689
};
1690
 
1691
 
1692
module.exports.TemplatablePattern = TemplatablePattern;
1693
 
1694
 
1695
/***/ }),
1696
/* 15 */,
1697
/* 16 */,
1698
/* 17 */,
1699
/* 18 */
1700
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
1701
 
1702
/*jshint node:true */
1703
/*
1704
 
1705
  The MIT License (MIT)
1706
 
1707
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
1708
 
1709
  Permission is hereby granted, free of charge, to any person
1710
  obtaining a copy of this software and associated documentation files
1711
  (the "Software"), to deal in the Software without restriction,
1712
  including without limitation the rights to use, copy, modify, merge,
1713
  publish, distribute, sublicense, and/or sell copies of the Software,
1714
  and to permit persons to whom the Software is furnished to do so,
1715
  subject to the following conditions:
1716
 
1717
  The above copyright notice and this permission notice shall be
1718
  included in all copies or substantial portions of the Software.
1719
 
1720
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1721
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1722
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1723
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1724
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1725
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1726
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1727
  SOFTWARE.
1728
*/
1729
 
1730
 
1731
 
1732
var Beautifier = (__webpack_require__(19).Beautifier),
1733
  Options = (__webpack_require__(20).Options);
1734
 
1735
function style_html(html_source, options, js_beautify, css_beautify) {
1736
  var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
1737
  return beautifier.beautify();
1738
}
1739
 
1740
module.exports = style_html;
1741
module.exports.defaultOptions = function() {
1742
  return new Options();
1743
};
1744
 
1745
 
1746
/***/ }),
1747
/* 19 */
1748
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
1749
 
1750
/*jshint node:true */
1751
/*
1752
 
1753
  The MIT License (MIT)
1754
 
1755
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
1756
 
1757
  Permission is hereby granted, free of charge, to any person
1758
  obtaining a copy of this software and associated documentation files
1759
  (the "Software"), to deal in the Software without restriction,
1760
  including without limitation the rights to use, copy, modify, merge,
1761
  publish, distribute, sublicense, and/or sell copies of the Software,
1762
  and to permit persons to whom the Software is furnished to do so,
1763
  subject to the following conditions:
1764
 
1765
  The above copyright notice and this permission notice shall be
1766
  included in all copies or substantial portions of the Software.
1767
 
1768
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1769
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1770
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1771
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1772
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1773
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1774
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1775
  SOFTWARE.
1776
*/
1777
 
1778
 
1779
 
1780
var Options = (__webpack_require__(20).Options);
1781
var Output = (__webpack_require__(2).Output);
1782
var Tokenizer = (__webpack_require__(21).Tokenizer);
1783
var TOKEN = (__webpack_require__(21).TOKEN);
1784
 
1785
var lineBreak = /\r\n|[\r\n]/;
1786
var allLineBreaks = /\r\n|[\r\n]/g;
1787
 
1788
var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions
1789
 
1790
  this.indent_level = 0;
1791
  this.alignment_size = 0;
1792
  this.max_preserve_newlines = options.max_preserve_newlines;
1793
  this.preserve_newlines = options.preserve_newlines;
1794
 
1795
  this._output = new Output(options, base_indent_string);
1796
 
1797
};
1798
 
1799
Printer.prototype.current_line_has_match = function(pattern) {
1800
  return this._output.current_line.has_match(pattern);
1801
};
1802
 
1803
Printer.prototype.set_space_before_token = function(value, non_breaking) {
1804
  this._output.space_before_token = value;
1805
  this._output.non_breaking_space = non_breaking;
1806
};
1807
 
1808
Printer.prototype.set_wrap_point = function() {
1809
  this._output.set_indent(this.indent_level, this.alignment_size);
1810
  this._output.set_wrap_point();
1811
};
1812
 
1813
 
1814
Printer.prototype.add_raw_token = function(token) {
1815
  this._output.add_raw_token(token);
1816
};
1817
 
1818
Printer.prototype.print_preserved_newlines = function(raw_token) {
1819
  var newlines = 0;
1820
  if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
1821
    newlines = raw_token.newlines ? 1 : 0;
1822
  }
1823
 
1824
  if (this.preserve_newlines) {
1825
    newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
1826
  }
1827
  for (var n = 0; n < newlines; n++) {
1828
    this.print_newline(n > 0);
1829
  }
1830
 
1831
  return newlines !== 0;
1832
};
1833
 
1834
Printer.prototype.traverse_whitespace = function(raw_token) {
1835
  if (raw_token.whitespace_before || raw_token.newlines) {
1836
    if (!this.print_preserved_newlines(raw_token)) {
1837
      this._output.space_before_token = true;
1838
    }
1839
    return true;
1840
  }
1841
  return false;
1842
};
1843
 
1844
Printer.prototype.previous_token_wrapped = function() {
1845
  return this._output.previous_token_wrapped;
1846
};
1847
 
1848
Printer.prototype.print_newline = function(force) {
1849
  this._output.add_new_line(force);
1850
};
1851
 
1852
Printer.prototype.print_token = function(token) {
1853
  if (token.text) {
1854
    this._output.set_indent(this.indent_level, this.alignment_size);
1855
    this._output.add_token(token.text);
1856
  }
1857
};
1858
 
1859
Printer.prototype.indent = function() {
1860
  this.indent_level++;
1861
};
1862
 
1863
Printer.prototype.deindent = function() {
1864
  if (this.indent_level > 0) {
1865
    this.indent_level--;
1866
    this._output.set_indent(this.indent_level, this.alignment_size);
1867
  }
1868
};
1869
 
1870
Printer.prototype.get_full_indent = function(level) {
1871
  level = this.indent_level + (level || 0);
1872
  if (level < 1) {
1873
    return '';
1874
  }
1875
 
1876
  return this._output.get_indent_string(level);
1877
};
1878
 
1879
var get_type_attribute = function(start_token) {
1880
  var result = null;
1881
  var raw_token = start_token.next;
1882
 
1883
  // Search attributes for a type attribute
1884
  while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
1885
    if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
1886
      if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
1887
        raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
1888
        result = raw_token.next.next.text;
1889
      }
1890
      break;
1891
    }
1892
    raw_token = raw_token.next;
1893
  }
1894
 
1895
  return result;
1896
};
1897
 
1898
var get_custom_beautifier_name = function(tag_check, raw_token) {
1899
  var typeAttribute = null;
1900
  var result = null;
1901
 
1902
  if (!raw_token.closed) {
1903
    return null;
1904
  }
1905
 
1906
  if (tag_check === 'script') {
1907
    typeAttribute = 'text/javascript';
1908
  } else if (tag_check === 'style') {
1909
    typeAttribute = 'text/css';
1910
  }
1911
 
1912
  typeAttribute = get_type_attribute(raw_token) || typeAttribute;
1913
 
1914
  // For script and style tags that have a type attribute, only enable custom beautifiers for matching values
1915
  // For those without a type attribute use default;
1916
  if (typeAttribute.search('text/css') > -1) {
1917
    result = 'css';
1918
  } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
1919
    result = 'javascript';
1920
  } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
1921
    result = 'html';
1922
  } else if (typeAttribute.search(/test\/null/) > -1) {
1923
    // Test only mime-type for testing the beautifier when null is passed as beautifing function
1924
    result = 'null';
1925
  }
1926
 
1927
  return result;
1928
};
1929
 
1930
function in_array(what, arr) {
1931
  return arr.indexOf(what) !== -1;
1932
}
1933
 
1934
function TagFrame(parent, parser_token, indent_level) {
1935
  this.parent = parent || null;
1936
  this.tag = parser_token ? parser_token.tag_name : '';
1937
  this.indent_level = indent_level || 0;
1938
  this.parser_token = parser_token || null;
1939
}
1940
 
1941
function TagStack(printer) {
1942
  this._printer = printer;
1943
  this._current_frame = null;
1944
}
1945
 
1946
TagStack.prototype.get_parser_token = function() {
1947
  return this._current_frame ? this._current_frame.parser_token : null;
1948
};
1949
 
1950
TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object
1951
  var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
1952
  this._current_frame = new_frame;
1953
};
1954
 
1955
TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer
1956
  var parser_token = null;
1957
 
1958
  if (frame) {
1959
    parser_token = frame.parser_token;
1960
    this._printer.indent_level = frame.indent_level;
1961
    this._current_frame = frame.parent;
1962
  }
1963
 
1964
  return parser_token;
1965
};
1966
 
1967
TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer
1968
  var frame = this._current_frame;
1969
 
1970
  while (frame) { //till we reach '' (the initial value);
1971
    if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it
1972
      break;
1973
    } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
1974
      frame = null;
1975
      break;
1976
    }
1977
    frame = frame.parent;
1978
  }
1979
 
1980
  return frame;
1981
};
1982
 
1983
TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer
1984
  var frame = this._get_frame([tag], stop_list);
1985
  return this._try_pop_frame(frame);
1986
};
1987
 
1988
TagStack.prototype.indent_to_tag = function(tag_list) {
1989
  var frame = this._get_frame(tag_list);
1990
  if (frame) {
1991
    this._printer.indent_level = frame.indent_level;
1992
  }
1993
};
1994
 
1995
function Beautifier(source_text, options, js_beautify, css_beautify) {
1996
  //Wrapper function to invoke all the necessary constructors and deal with the output.
1997
  this._source_text = source_text || '';
1998
  options = options || {};
1999
  this._js_beautify = js_beautify;
2000
  this._css_beautify = css_beautify;
2001
  this._tag_stack = null;
2002
 
2003
  // Allow the setting of language/file-type specific options
2004
  // with inheritance of overall settings
2005
  var optionHtml = new Options(options, 'html');
2006
 
2007
  this._options = optionHtml;
2008
 
2009
  this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
2010
  this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
2011
  this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
2012
  this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
2013
  this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
2014
  this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
2015
}
2016
 
2017
Beautifier.prototype.beautify = function() {
2018
 
2019
  // if disabled, return the input unchanged.
2020
  if (this._options.disabled) {
2021
    return this._source_text;
2022
  }
2023
 
2024
  var source_text = this._source_text;
2025
  var eol = this._options.eol;
2026
  if (this._options.eol === 'auto') {
2027
    eol = '\n';
2028
    if (source_text && lineBreak.test(source_text)) {
2029
      eol = source_text.match(lineBreak)[0];
2030
    }
2031
  }
2032
 
2033
  // HACK: newline parsing inconsistent. This brute force normalizes the input.
2034
  source_text = source_text.replace(allLineBreaks, '\n');
2035
 
2036
  var baseIndentString = source_text.match(/^[\t ]*/)[0];
2037
 
2038
  var last_token = {
2039
    text: '',
2040
    type: ''
2041
  };
2042
 
2043
  var last_tag_token = new TagOpenParserToken();
2044
 
2045
  var printer = new Printer(this._options, baseIndentString);
2046
  var tokens = new Tokenizer(source_text, this._options).tokenize();
2047
 
2048
  this._tag_stack = new TagStack(printer);
2049
 
2050
  var parser_token = null;
2051
  var raw_token = tokens.next();
2052
  while (raw_token.type !== TOKEN.EOF) {
2053
 
2054
    if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
2055
      parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
2056
      last_tag_token = parser_token;
2057
    } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
2058
      (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
2059
      parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
2060
    } else if (raw_token.type === TOKEN.TAG_CLOSE) {
2061
      parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
2062
    } else if (raw_token.type === TOKEN.TEXT) {
2063
      parser_token = this._handle_text(printer, raw_token, last_tag_token);
2064
    } else if (raw_token.type === TOKEN.CONTROL_FLOW_OPEN) {
2065
      parser_token = this._handle_control_flow_open(printer, raw_token);
2066
    } else if (raw_token.type === TOKEN.CONTROL_FLOW_CLOSE) {
2067
      parser_token = this._handle_control_flow_close(printer, raw_token);
2068
    } else {
2069
      // This should never happen, but if it does. Print the raw token
2070
      printer.add_raw_token(raw_token);
2071
    }
2072
 
2073
    last_token = parser_token;
2074
 
2075
    raw_token = tokens.next();
2076
  }
2077
  var sweet_code = printer._output.get_code(eol);
2078
 
2079
  return sweet_code;
2080
};
2081
 
2082
Beautifier.prototype._handle_control_flow_open = function(printer, raw_token) {
2083
  var parser_token = {
2084
    text: raw_token.text,
2085
    type: raw_token.type
2086
  };
2087
  printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
2088
  if (raw_token.newlines) {
2089
    printer.print_preserved_newlines(raw_token);
2090
  } else {
2091
    printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
2092
  }
2093
  printer.print_token(raw_token);
2094
  printer.indent();
2095
  return parser_token;
2096
};
2097
 
2098
Beautifier.prototype._handle_control_flow_close = function(printer, raw_token) {
2099
  var parser_token = {
2100
    text: raw_token.text,
2101
    type: raw_token.type
2102
  };
2103
 
2104
  printer.deindent();
2105
  if (raw_token.newlines) {
2106
    printer.print_preserved_newlines(raw_token);
2107
  } else {
2108
    printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
2109
  }
2110
  printer.print_token(raw_token);
2111
  return parser_token;
2112
};
2113
 
2114
Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
2115
  var parser_token = {
2116
    text: raw_token.text,
2117
    type: raw_token.type
2118
  };
2119
  printer.alignment_size = 0;
2120
  last_tag_token.tag_complete = true;
2121
 
2122
  printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
2123
  if (last_tag_token.is_unformatted) {
2124
    printer.add_raw_token(raw_token);
2125
  } else {
2126
    if (last_tag_token.tag_start_char === '<') {
2127
      printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
2128
      if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
2129
        printer.print_newline(false);
2130
      }
2131
    }
2132
    printer.print_token(raw_token);
2133
 
2134
  }
2135
 
2136
  if (last_tag_token.indent_content &&
2137
    !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
2138
    printer.indent();
2139
 
2140
    // only indent once per opened tag
2141
    last_tag_token.indent_content = false;
2142
  }
2143
 
2144
  if (!last_tag_token.is_inline_element &&
2145
    !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
2146
    printer.set_wrap_point();
2147
  }
2148
 
2149
  return parser_token;
2150
};
2151
 
2152
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
2153
  var wrapped = last_tag_token.has_wrapped_attrs;
2154
  var parser_token = {
2155
    text: raw_token.text,
2156
    type: raw_token.type
2157
  };
2158
 
2159
  printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
2160
  if (last_tag_token.is_unformatted) {
2161
    printer.add_raw_token(raw_token);
2162
  } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
2163
    // For the insides of handlebars allow newlines or a single space between open and contents
2164
    if (printer.print_preserved_newlines(raw_token)) {
2165
      raw_token.newlines = 0;
2166
      printer.add_raw_token(raw_token);
2167
    } else {
2168
      printer.print_token(raw_token);
2169
    }
2170
  } else {
2171
    if (raw_token.type === TOKEN.ATTRIBUTE) {
2172
      printer.set_space_before_token(true);
2173
    } else if (raw_token.type === TOKEN.EQUALS) { //no space before =
2174
      printer.set_space_before_token(false);
2175
    } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
2176
      printer.set_space_before_token(false);
2177
    }
2178
 
2179
    if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
2180
      if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
2181
        printer.traverse_whitespace(raw_token);
2182
        wrapped = wrapped || raw_token.newlines !== 0;
2183
      }
2184
 
2185
      // Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
2186
      // 1. always wrap the second and beyond attributes
2187
      // 2. wrap the first attribute only if 'force-expand-multiline' is specified
2188
      if (this._is_wrap_attributes_force &&
2189
        last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
2190
        (last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
2191
          this._is_wrap_attributes_force_expand_multiline)) {
2192
        printer.print_newline(false);
2193
        wrapped = true;
2194
      }
2195
    }
2196
    printer.print_token(raw_token);
2197
    wrapped = wrapped || printer.previous_token_wrapped();
2198
    last_tag_token.has_wrapped_attrs = wrapped;
2199
  }
2200
  return parser_token;
2201
};
2202
 
2203
Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
2204
  var parser_token = {
2205
    text: raw_token.text,
2206
    type: 'TK_CONTENT'
2207
  };
2208
  if (last_tag_token.custom_beautifier_name) { //check if we need to format javascript
2209
    this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
2210
  } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
2211
    printer.add_raw_token(raw_token);
2212
  } else {
2213
    printer.traverse_whitespace(raw_token);
2214
    printer.print_token(raw_token);
2215
  }
2216
  return parser_token;
2217
};
2218
 
2219
Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
2220
  var local = this;
2221
  if (raw_token.text !== '') {
2222
 
2223
    var text = raw_token.text,
2224
      _beautifier,
2225
      script_indent_level = 1,
2226
      pre = '',
2227
      post = '';
2228
    if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
2229
      _beautifier = this._js_beautify;
2230
    } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
2231
      _beautifier = this._css_beautify;
2232
    } else if (last_tag_token.custom_beautifier_name === 'html') {
2233
      _beautifier = function(html_source, options) {
2234
        var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
2235
        return beautifier.beautify();
2236
      };
2237
    }
2238
 
2239
    if (this._options.indent_scripts === "keep") {
2240
      script_indent_level = 0;
2241
    } else if (this._options.indent_scripts === "separate") {
2242
      script_indent_level = -printer.indent_level;
2243
    }
2244
 
2245
    var indentation = printer.get_full_indent(script_indent_level);
2246
 
2247
    // if there is at least one empty line at the end of this text, strip it
2248
    // we'll be adding one back after the text but before the containing tag.
2249
    text = text.replace(/\n[ \t]*$/, '');
2250
 
2251
    // Handle the case where content is wrapped in a comment or cdata.
2252
    if (last_tag_token.custom_beautifier_name !== 'html' &&
2253
      text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
2254
      var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
2255
 
2256
      // if we start to wrap but don't finish, print raw
2257
      if (!matched) {
2258
        printer.add_raw_token(raw_token);
2259
        return;
2260
      }
2261
 
2262
      pre = indentation + matched[1] + '\n';
2263
      text = matched[4];
2264
      if (matched[5]) {
2265
        post = indentation + matched[5];
2266
      }
2267
 
2268
      // if there is at least one empty line at the end of this text, strip it
2269
      // we'll be adding one back after the text but before the containing tag.
2270
      text = text.replace(/\n[ \t]*$/, '');
2271
 
2272
      if (matched[2] || matched[3].indexOf('\n') !== -1) {
2273
        // if the first line of the non-comment text has spaces
2274
        // use that as the basis for indenting in null case.
2275
        matched = matched[3].match(/[ \t]+$/);
2276
        if (matched) {
2277
          raw_token.whitespace_before = matched[0];
2278
        }
2279
      }
2280
    }
2281
 
2282
    if (text) {
2283
      if (_beautifier) {
2284
 
2285
        // call the Beautifier if avaliable
2286
        var Child_options = function() {
2287
          this.eol = '\n';
2288
        };
2289
        Child_options.prototype = this._options.raw_options;
2290
        var child_options = new Child_options();
2291
        text = _beautifier(indentation + text, child_options);
2292
      } else {
2293
        // simply indent the string otherwise
2294
        var white = raw_token.whitespace_before;
2295
        if (white) {
2296
          text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
2297
        }
2298
 
2299
        text = indentation + text.replace(/\n/g, '\n' + indentation);
2300
      }
2301
    }
2302
 
2303
    if (pre) {
2304
      if (!text) {
2305
        text = pre + post;
2306
      } else {
2307
        text = pre + text + '\n' + post;
2308
      }
2309
    }
2310
 
2311
    printer.print_newline(false);
2312
    if (text) {
2313
      raw_token.text = text;
2314
      raw_token.whitespace_before = '';
2315
      raw_token.newlines = 0;
2316
      printer.add_raw_token(raw_token);
2317
      printer.print_newline(true);
2318
    }
2319
  }
2320
};
2321
 
2322
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
2323
  var parser_token = this._get_tag_open_token(raw_token);
2324
 
2325
  if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
2326
    !last_tag_token.is_empty_element &&
2327
    raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
2328
    // End element tags for unformatted or content_unformatted elements
2329
    // are printed raw to keep any newlines inside them exactly the same.
2330
    printer.add_raw_token(raw_token);
2331
    parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
2332
  } else {
2333
    printer.traverse_whitespace(raw_token);
2334
    this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
2335
    if (!parser_token.is_inline_element) {
2336
      printer.set_wrap_point();
2337
    }
2338
    printer.print_token(raw_token);
2339
  }
2340
 
2341
  // count the number of attributes
2342
  if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
2343
    var peek_index = 0;
2344
    var peek_token;
2345
    do {
2346
      peek_token = tokens.peek(peek_index);
2347
      if (peek_token.type === TOKEN.ATTRIBUTE) {
2348
        parser_token.attr_count += 1;
2349
      }
2350
      peek_index += 1;
2351
    } while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
2352
  }
2353
 
2354
  //indent attributes an auto, forced, aligned or forced-align line-wrap
2355
  if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
2356
    parser_token.alignment_size = raw_token.text.length + 1;
2357
  }
2358
 
2359
  if (!parser_token.tag_complete && !parser_token.is_unformatted) {
2360
    printer.alignment_size = parser_token.alignment_size;
2361
  }
2362
 
2363
  return parser_token;
2364
};
2365
 
2366
var TagOpenParserToken = function(parent, raw_token) {
2367
  this.parent = parent || null;
2368
  this.text = '';
2369
  this.type = 'TK_TAG_OPEN';
2370
  this.tag_name = '';
2371
  this.is_inline_element = false;
2372
  this.is_unformatted = false;
2373
  this.is_content_unformatted = false;
2374
  this.is_empty_element = false;
2375
  this.is_start_tag = false;
2376
  this.is_end_tag = false;
2377
  this.indent_content = false;
2378
  this.multiline_content = false;
2379
  this.custom_beautifier_name = null;
2380
  this.start_tag_token = null;
2381
  this.attr_count = 0;
2382
  this.has_wrapped_attrs = false;
2383
  this.alignment_size = 0;
2384
  this.tag_complete = false;
2385
  this.tag_start_char = '';
2386
  this.tag_check = '';
2387
 
2388
  if (!raw_token) {
2389
    this.tag_complete = true;
2390
  } else {
2391
    var tag_check_match;
2392
 
2393
    this.tag_start_char = raw_token.text[0];
2394
    this.text = raw_token.text;
2395
 
2396
    if (this.tag_start_char === '<') {
2397
      tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
2398
      this.tag_check = tag_check_match ? tag_check_match[1] : '';
2399
    } else {
2400
      tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/);
2401
      this.tag_check = tag_check_match ? tag_check_match[1] : '';
2402
 
2403
      // handle "{{#> myPartial}}" or "{{~#> myPartial}}"
2404
      if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
2405
        if (this.tag_check === '>' && raw_token.next !== null) {
2406
          this.tag_check = raw_token.next.text.split(' ')[0];
2407
        } else {
2408
          this.tag_check = raw_token.text.split('>')[1];
2409
        }
2410
      }
2411
    }
2412
 
2413
    this.tag_check = this.tag_check.toLowerCase();
2414
 
2415
    if (raw_token.type === TOKEN.COMMENT) {
2416
      this.tag_complete = true;
2417
    }
2418
 
2419
    this.is_start_tag = this.tag_check.charAt(0) !== '/';
2420
    this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
2421
    this.is_end_tag = !this.is_start_tag ||
2422
      (raw_token.closed && raw_token.closed.text === '/>');
2423
 
2424
    // if whitespace handler ~ included (i.e. {{~#if true}}), handlebars tags start at pos 3 not pos 2
2425
    var handlebar_starts = 2;
2426
    if (this.tag_start_char === '{' && this.text.length >= 3) {
2427
      if (this.text.charAt(2) === '~') {
2428
        handlebar_starts = 3;
2429
      }
2430
    }
2431
 
2432
    // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
2433
    this.is_end_tag = this.is_end_tag ||
2434
      (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
2435
  }
2436
};
2437
 
2438
Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
2439
  var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
2440
 
2441
  parser_token.alignment_size = this._options.wrap_attributes_indent_size;
2442
 
2443
  parser_token.is_end_tag = parser_token.is_end_tag ||
2444
    in_array(parser_token.tag_check, this._options.void_elements);
2445
 
2446
  parser_token.is_empty_element = parser_token.tag_complete ||
2447
    (parser_token.is_start_tag && parser_token.is_end_tag);
2448
 
2449
  parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
2450
  parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
2451
  parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
2452
 
2453
  return parser_token;
2454
};
2455
 
2456
Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
2457
 
2458
  if (!parser_token.is_empty_element) {
2459
    if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
2460
      parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors
2461
    } else { // it's a start-tag
2462
      // check if this tag is starting an element that has optional end element
2463
      // and do an ending needed
2464
      if (this._do_optional_end_element(parser_token)) {
2465
        if (!parser_token.is_inline_element) {
2466
          printer.print_newline(false);
2467
        }
2468
      }
2469
 
2470
      this._tag_stack.record_tag(parser_token); //push it on the tag stack
2471
 
2472
      if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
2473
        !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
2474
        parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
2475
      }
2476
    }
2477
  }
2478
 
2479
  if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line
2480
    printer.print_newline(false);
2481
    if (!printer._output.just_added_blankline()) {
2482
      printer.print_newline(true);
2483
    }
2484
  }
2485
 
2486
  if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /)
2487
 
2488
    // if you hit an else case, reset the indent level if you are inside an:
2489
    // 'if', 'unless', or 'each' block.
2490
    if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
2491
      this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
2492
      parser_token.indent_content = true;
2493
      // Don't add a newline if opening {{#if}} tag is on the current line
2494
      var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
2495
      if (!foundIfOnCurrentLine) {
2496
        printer.print_newline(false);
2497
      }
2498
    }
2499
 
2500
    // Don't add a newline before elements that should remain where they are.
2501
    if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
2502
      last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) {
2503
      //Do nothing. Leave comments on same line.
2504
    } else {
2505
      if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
2506
        printer.print_newline(false);
2507
      }
2508
      this._calcluate_parent_multiline(printer, parser_token);
2509
    }
2510
  } else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
2511
    var do_end_expand = false;
2512
 
2513
    // deciding whether a block is multiline should not be this hard
2514
    do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
2515
    do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
2516
      !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
2517
      !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
2518
      last_token.type !== 'TK_CONTENT'
2519
    );
2520
 
2521
    if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
2522
      do_end_expand = false;
2523
    }
2524
 
2525
    if (do_end_expand) {
2526
      printer.print_newline(false);
2527
    }
2528
  } else { // it's a start-tag
2529
    parser_token.indent_content = !parser_token.custom_beautifier_name;
2530
 
2531
    if (parser_token.tag_start_char === '<') {
2532
      if (parser_token.tag_name === 'html') {
2533
        parser_token.indent_content = this._options.indent_inner_html;
2534
      } else if (parser_token.tag_name === 'head') {
2535
        parser_token.indent_content = this._options.indent_head_inner_html;
2536
      } else if (parser_token.tag_name === 'body') {
2537
        parser_token.indent_content = this._options.indent_body_inner_html;
2538
      }
2539
    }
2540
 
2541
    if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
2542
      (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
2543
      printer.print_newline(false);
2544
    }
2545
 
2546
    this._calcluate_parent_multiline(printer, parser_token);
2547
  }
2548
};
2549
 
2550
Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
2551
  if (parser_token.parent && printer._output.just_added_newline() &&
2552
    !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
2553
    parser_token.parent.multiline_content = true;
2554
  }
2555
};
2556
 
2557
//To be used for <p> tag special case:
2558
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
2559
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
2560
 
2561
Beautifier.prototype._do_optional_end_element = function(parser_token) {
2562
  var result = null;
2563
  // NOTE: cases of "if there is no more content in the parent element"
2564
  // are handled automatically by the beautifier.
2565
  // It assumes parent or ancestor close tag closes all children.
2566
  // https://www.w3.org/TR/html5/syntax.html#optional-tags
2567
  if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
2568
    return;
2569
 
2570
  }
2571
 
2572
  if (parser_token.tag_name === 'body') {
2573
    // A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
2574
    result = result || this._tag_stack.try_pop('head');
2575
 
2576
    //} else if (parser_token.tag_name === 'body') {
2577
    // DONE: A body element’s end tag may be omitted if the body element is not immediately followed by a comment.
2578
 
2579
  } else if (parser_token.tag_name === 'li') {
2580
    // An li element’s end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.
2581
    result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
2582
 
2583
  } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
2584
    // A dd element’s end tag may be omitted if the dd element is immediately followed by another dd element or a dt element, or if there is no more content in the parent element.
2585
    // A dt element’s end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.
2586
    result = result || this._tag_stack.try_pop('dt', ['dl']);
2587
    result = result || this._tag_stack.try_pop('dd', ['dl']);
2588
 
2589
 
2590
  } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
2591
    // IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
2592
    // check for the parent element is an HTML element that is not an <a>, <audio>, <del>, <ins>, <map>, <noscript>, or <video> element,  or an autonomous custom element.
2593
    // To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
2594
    // But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
2595
    var p_parent = parser_token.parent.parent;
2596
    if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
2597
      result = result || this._tag_stack.try_pop('p');
2598
    }
2599
  } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
2600
    // An rt element’s end tag may be omitted if the rt element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
2601
    // An rp element’s end tag may be omitted if the rp element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
2602
    result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
2603
    result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
2604
 
2605
  } else if (parser_token.tag_name === 'optgroup') {
2606
    // An optgroup element’s end tag may be omitted if the optgroup element is immediately followed by another optgroup element, or if there is no more content in the parent element.
2607
    // An option element’s end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
2608
    result = result || this._tag_stack.try_pop('optgroup', ['select']);
2609
    //result = result || this._tag_stack.try_pop('option', ['select']);
2610
 
2611
  } else if (parser_token.tag_name === 'option') {
2612
    // An option element’s end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
2613
    result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
2614
 
2615
  } else if (parser_token.tag_name === 'colgroup') {
2616
    // DONE: A colgroup element’s end tag may be omitted if the colgroup element is not immediately followed by a space character or a comment.
2617
    // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
2618
    result = result || this._tag_stack.try_pop('caption', ['table']);
2619
 
2620
  } else if (parser_token.tag_name === 'thead') {
2621
    // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
2622
    // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
2623
    result = result || this._tag_stack.try_pop('caption', ['table']);
2624
    result = result || this._tag_stack.try_pop('colgroup', ['table']);
2625
 
2626
    //} else if (parser_token.tag_name === 'caption') {
2627
    // DONE: A caption element’s end tag may be omitted if the caption element is not immediately followed by a space character or a comment.
2628
 
2629
  } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
2630
    // A thead element’s end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.
2631
    // A tbody element’s end tag may be omitted if the tbody element is immediately followed by a tbody or tfoot element, or if there is no more content in the parent element.
2632
    // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
2633
    // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
2634
    result = result || this._tag_stack.try_pop('caption', ['table']);
2635
    result = result || this._tag_stack.try_pop('colgroup', ['table']);
2636
    result = result || this._tag_stack.try_pop('thead', ['table']);
2637
    result = result || this._tag_stack.try_pop('tbody', ['table']);
2638
 
2639
    //} else if (parser_token.tag_name === 'tfoot') {
2640
    // DONE: A tfoot element’s end tag may be omitted if there is no more content in the parent element.
2641
 
2642
  } else if (parser_token.tag_name === 'tr') {
2643
    // A tr element’s end tag may be omitted if the tr element is immediately followed by another tr element, or if there is no more content in the parent element.
2644
    // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
2645
    // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
2646
    result = result || this._tag_stack.try_pop('caption', ['table']);
2647
    result = result || this._tag_stack.try_pop('colgroup', ['table']);
2648
    result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
2649
 
2650
  } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
2651
    // A td element’s end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
2652
    // A th element’s end tag may be omitted if the th element is immediately followed by a td or th element, or if there is no more content in the parent element.
2653
    result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
2654
    result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
2655
  }
2656
 
2657
  // Start element omission not handled currently
2658
  // A head element’s start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.
2659
  // A tbody element’s start tag may be omitted if the first thing inside the tbody element is a tr element, and if the element is not immediately preceded by a tbody, thead, or tfoot element whose end tag has been omitted. (It can’t be omitted if the element is empty.)
2660
  // A colgroup element’s start tag may be omitted if the first thing inside the colgroup element is a col element, and if the element is not immediately preceded by another colgroup element whose end tag has been omitted. (It can’t be omitted if the element is empty.)
2661
 
2662
  // Fix up the parent of the parser token
2663
  parser_token.parent = this._tag_stack.get_parser_token();
2664
 
2665
  return result;
2666
};
2667
 
2668
module.exports.Beautifier = Beautifier;
2669
 
2670
 
2671
/***/ }),
2672
/* 20 */
2673
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
2674
 
2675
/*jshint node:true */
2676
/*
2677
 
2678
  The MIT License (MIT)
2679
 
2680
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
2681
 
2682
  Permission is hereby granted, free of charge, to any person
2683
  obtaining a copy of this software and associated documentation files
2684
  (the "Software"), to deal in the Software without restriction,
2685
  including without limitation the rights to use, copy, modify, merge,
2686
  publish, distribute, sublicense, and/or sell copies of the Software,
2687
  and to permit persons to whom the Software is furnished to do so,
2688
  subject to the following conditions:
2689
 
2690
  The above copyright notice and this permission notice shall be
2691
  included in all copies or substantial portions of the Software.
2692
 
2693
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2694
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2695
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2696
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2697
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2698
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2699
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2700
  SOFTWARE.
2701
*/
2702
 
2703
 
2704
 
2705
var BaseOptions = (__webpack_require__(6).Options);
2706
 
2707
function Options(options) {
2708
  BaseOptions.call(this, options, 'html');
2709
  if (this.templating.length === 1 && this.templating[0] === 'auto') {
2710
    this.templating = ['django', 'erb', 'handlebars', 'php'];
2711
  }
2712
 
2713
  this.indent_inner_html = this._get_boolean('indent_inner_html');
2714
  this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
2715
  this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
2716
 
2717
  this.indent_handlebars = this._get_boolean('indent_handlebars', true);
2718
  this.wrap_attributes = this._get_selection('wrap_attributes',
2719
    ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
2720
  this.wrap_attributes_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
2721
  this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
2722
  this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
2723
 
2724
  // Block vs inline elements
2725
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
2726
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
2727
  // https://www.w3.org/TR/html5/dom.html#phrasing-content
2728
  this.inline = this._get_array('inline', [
2729
    'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
2730
    'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
2731
    'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
2732
    'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
2733
    'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
2734
    'video', 'wbr', 'text',
2735
    // obsolete inline tags
2736
    'acronym', 'big', 'strike', 'tt'
2737
  ]);
2738
  this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
2739
  this.void_elements = this._get_array('void_elements', [
2740
    // HTLM void elements - aka self-closing tags - aka singletons
2741
    // https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
2742
    'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
2743
    'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
2744
    // NOTE: Optional tags are too complex for a simple list
2745
    // they are hard coded in _do_optional_end_element
2746
 
2747
    // Doctype and xml elements
2748
    '!doctype', '?xml',
2749
 
2750
    // obsolete tags
2751
    // basefont: https://www.computerhope.com/jargon/h/html-basefont-tag.htm
2752
    // isndex: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex
2753
    'basefont', 'isindex'
2754
  ]);
2755
  this.unformatted = this._get_array('unformatted', []);
2756
  this.content_unformatted = this._get_array('content_unformatted', [
2757
    'pre', 'textarea'
2758
  ]);
2759
  this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
2760
  this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
2761
 
2762
}
2763
Options.prototype = new BaseOptions();
2764
 
2765
 
2766
 
2767
module.exports.Options = Options;
2768
 
2769
 
2770
/***/ }),
2771
/* 21 */
2772
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
2773
 
2774
/*jshint node:true */
2775
/*
2776
 
2777
  The MIT License (MIT)
2778
 
2779
  Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
2780
 
2781
  Permission is hereby granted, free of charge, to any person
2782
  obtaining a copy of this software and associated documentation files
2783
  (the "Software"), to deal in the Software without restriction,
2784
  including without limitation the rights to use, copy, modify, merge,
2785
  publish, distribute, sublicense, and/or sell copies of the Software,
2786
  and to permit persons to whom the Software is furnished to do so,
2787
  subject to the following conditions:
2788
 
2789
  The above copyright notice and this permission notice shall be
2790
  included in all copies or substantial portions of the Software.
2791
 
2792
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2793
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2794
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2795
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2796
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2797
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2798
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2799
  SOFTWARE.
2800
*/
2801
 
2802
 
2803
 
2804
var BaseTokenizer = (__webpack_require__(9).Tokenizer);
2805
var BASETOKEN = (__webpack_require__(9).TOKEN);
2806
var Directives = (__webpack_require__(13).Directives);
2807
var TemplatablePattern = (__webpack_require__(14).TemplatablePattern);
2808
var Pattern = (__webpack_require__(12).Pattern);
2809
 
2810
var TOKEN = {
2811
  TAG_OPEN: 'TK_TAG_OPEN',
2812
  TAG_CLOSE: 'TK_TAG_CLOSE',
2813
  CONTROL_FLOW_OPEN: 'TK_CONTROL_FLOW_OPEN',
2814
  CONTROL_FLOW_CLOSE: 'TK_CONTROL_FLOW_CLOSE',
2815
  ATTRIBUTE: 'TK_ATTRIBUTE',
2816
  EQUALS: 'TK_EQUALS',
2817
  VALUE: 'TK_VALUE',
2818
  COMMENT: 'TK_COMMENT',
2819
  TEXT: 'TK_TEXT',
2820
  UNKNOWN: 'TK_UNKNOWN',
2821
  START: BASETOKEN.START,
2822
  RAW: BASETOKEN.RAW,
2823
  EOF: BASETOKEN.EOF
2824
};
2825
 
2826
var directives_core = new Directives(/<\!--/, /-->/);
2827
 
2828
var Tokenizer = function(input_string, options) {
2829
  BaseTokenizer.call(this, input_string, options);
2830
  this._current_tag_name = '';
2831
 
2832
  // Words end at whitespace or when a tag starts
2833
  // if we are indenting handlebars, they are considered tags
2834
  var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
2835
  var pattern_reader = new Pattern(this._input);
2836
 
2837
  this.__patterns = {
2838
    word: templatable_reader.until(/[\n\r\t <]/),
2839
    word_control_flow_close_excluded: templatable_reader.until(/[\n\r\t <}]/),
2840
    single_quote: templatable_reader.until_after(/'/),
2841
    double_quote: templatable_reader.until_after(/"/),
2842
    attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
2843
    element_name: templatable_reader.until(/[\n\r\t >\/]/),
2844
 
2845
    angular_control_flow_start: pattern_reader.matching(/\@[a-zA-Z]+[^({]*[({]/),
2846
    handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
2847
    handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
2848
    handlebars_open: pattern_reader.until(/[\n\r\t }]/),
2849
    handlebars_raw_close: pattern_reader.until(/}}/),
2850
    comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
2851
    cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
2852
    // https://en.wikipedia.org/wiki/Conditional_comment
2853
    conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
2854
    processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
2855
  };
2856
 
2857
  if (this._options.indent_handlebars) {
2858
    this.__patterns.word = this.__patterns.word.exclude('handlebars');
2859
    this.__patterns.word_control_flow_close_excluded = this.__patterns.word_control_flow_close_excluded.exclude('handlebars');
2860
  }
2861
 
2862
  this._unformatted_content_delimiter = null;
2863
 
2864
  if (this._options.unformatted_content_delimiter) {
2865
    var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
2866
    this.__patterns.unformatted_content_delimiter =
2867
      pattern_reader.matching(literal_regexp)
2868
      .until_after(literal_regexp);
2869
  }
2870
};
2871
Tokenizer.prototype = new BaseTokenizer();
2872
 
2873
Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
2874
  return false; //current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.UNKNOWN;
2875
};
2876
 
2877
Tokenizer.prototype._is_opening = function(current_token) {
2878
  return current_token.type === TOKEN.TAG_OPEN || current_token.type === TOKEN.CONTROL_FLOW_OPEN;
2879
};
2880
 
2881
Tokenizer.prototype._is_closing = function(current_token, open_token) {
2882
  return (current_token.type === TOKEN.TAG_CLOSE &&
2883
    (open_token && (
2884
      ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
2885
      (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')))
2886
  ) || (current_token.type === TOKEN.CONTROL_FLOW_CLOSE &&
2887
    (current_token.text === '}' && open_token.text.endsWith('{')));
2888
};
2889
 
2890
Tokenizer.prototype._reset = function() {
2891
  this._current_tag_name = '';
2892
};
2893
 
2894
Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
2895
  var token = null;
2896
  this._readWhitespace();
2897
  var c = this._input.peek();
2898
 
2899
  if (c === null) {
2900
    return this._create_token(TOKEN.EOF, '');
2901
  }
2902
 
2903
  token = token || this._read_open_handlebars(c, open_token);
2904
  token = token || this._read_attribute(c, previous_token, open_token);
2905
  token = token || this._read_close(c, open_token);
2906
  token = token || this._read_control_flows(c, open_token);
2907
  token = token || this._read_raw_content(c, previous_token, open_token);
2908
  token = token || this._read_content_word(c, open_token);
2909
  token = token || this._read_comment_or_cdata(c);
2910
  token = token || this._read_processing(c);
2911
  token = token || this._read_open(c, open_token);
2912
  token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
2913
 
2914
  return token;
2915
};
2916
 
2917
Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
2918
  var token = null;
2919
  var resulting_string = null;
2920
  var directives = null;
2921
 
2922
  if (c === '<') {
2923
    var peek1 = this._input.peek(1);
2924
    // We treat all comments as literals, even more than preformatted tags
2925
    // we only look for the appropriate closing marker
2926
    if (peek1 === '!') {
2927
      resulting_string = this.__patterns.comment.read();
2928
 
2929
      // only process directive on html comments
2930
      if (resulting_string) {
2931
        directives = directives_core.get_directives(resulting_string);
2932
        if (directives && directives.ignore === 'start') {
2933
          resulting_string += directives_core.readIgnored(this._input);
2934
        }
2935
      } else {
2936
        resulting_string = this.__patterns.cdata.read();
2937
      }
2938
    }
2939
 
2940
    if (resulting_string) {
2941
      token = this._create_token(TOKEN.COMMENT, resulting_string);
2942
      token.directives = directives;
2943
    }
2944
  }
2945
 
2946
  return token;
2947
};
2948
 
2949
Tokenizer.prototype._read_processing = function(c) { // jshint unused:false
2950
  var token = null;
2951
  var resulting_string = null;
2952
  var directives = null;
2953
 
2954
  if (c === '<') {
2955
    var peek1 = this._input.peek(1);
2956
    if (peek1 === '!' || peek1 === '?') {
2957
      resulting_string = this.__patterns.conditional_comment.read();
2958
      resulting_string = resulting_string || this.__patterns.processing.read();
2959
    }
2960
 
2961
    if (resulting_string) {
2962
      token = this._create_token(TOKEN.COMMENT, resulting_string);
2963
      token.directives = directives;
2964
    }
2965
  }
2966
 
2967
  return token;
2968
};
2969
 
2970
Tokenizer.prototype._read_open = function(c, open_token) {
2971
  var resulting_string = null;
2972
  var token = null;
2973
  if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
2974
    if (c === '<') {
2975
 
2976
      resulting_string = this._input.next();
2977
      if (this._input.peek() === '/') {
2978
        resulting_string += this._input.next();
2979
      }
2980
      resulting_string += this.__patterns.element_name.read();
2981
      token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
2982
    }
2983
  }
2984
  return token;
2985
};
2986
 
2987
Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
2988
  var resulting_string = null;
2989
  var token = null;
2990
  if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
2991
    if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
2992
      if (this._input.peek(2) === '!') {
2993
        resulting_string = this.__patterns.handlebars_comment.read();
2994
        resulting_string = resulting_string || this.__patterns.handlebars.read();
2995
        token = this._create_token(TOKEN.COMMENT, resulting_string);
2996
      } else {
2997
        resulting_string = this.__patterns.handlebars_open.read();
2998
        token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
2999
      }
3000
    }
3001
  }
3002
  return token;
3003
};
3004
 
3005
Tokenizer.prototype._read_control_flows = function(c, open_token) {
3006
  var resulting_string = '';
3007
  var token = null;
3008
  // Only check for control flows if angular templating is set AND indenting is set
3009
  if (!this._options.templating.includes('angular') || !this._options.indent_handlebars) {
3010
    return token;
3011
  }
3012
 
3013
  if (c === '@') {
3014
    resulting_string = this.__patterns.angular_control_flow_start.read();
3015
    if (resulting_string === '') {
3016
      return token;
3017
    }
3018
 
3019
    var opening_parentheses_count = resulting_string.endsWith('(') ? 1 : 0;
3020
    var closing_parentheses_count = 0;
3021
    // The opening brace of the control flow is where the number of opening and closing parentheses equal
3022
    // e.g. @if({value: true} !== null) {
3023
    while (!(resulting_string.endsWith('{') && opening_parentheses_count === closing_parentheses_count)) {
3024
      var next_char = this._input.next();
3025
      if (next_char === null) {
3026
        break;
3027
      } else if (next_char === '(') {
3028
        opening_parentheses_count++;
3029
      } else if (next_char === ')') {
3030
        closing_parentheses_count++;
3031
      }
3032
      resulting_string += next_char;
3033
    }
3034
    token = this._create_token(TOKEN.CONTROL_FLOW_OPEN, resulting_string);
3035
  } else if (c === '}' && open_token && open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
3036
    resulting_string = this._input.next();
3037
    token = this._create_token(TOKEN.CONTROL_FLOW_CLOSE, resulting_string);
3038
  }
3039
  return token;
3040
};
3041
 
3042
 
3043
Tokenizer.prototype._read_close = function(c, open_token) {
3044
  var resulting_string = null;
3045
  var token = null;
3046
  if (open_token && open_token.type === TOKEN.TAG_OPEN) {
3047
    if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
3048
      resulting_string = this._input.next();
3049
      if (c === '/') { //  for close tag "/>"
3050
        resulting_string += this._input.next();
3051
      }
3052
      token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
3053
    } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
3054
      this._input.next();
3055
      this._input.next();
3056
      token = this._create_token(TOKEN.TAG_CLOSE, '}}');
3057
    }
3058
  }
3059
 
3060
  return token;
3061
};
3062
 
3063
Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
3064
  var token = null;
3065
  var resulting_string = '';
3066
  if (open_token && open_token.text[0] === '<') {
3067
 
3068
    if (c === '=') {
3069
      token = this._create_token(TOKEN.EQUALS, this._input.next());
3070
    } else if (c === '"' || c === "'") {
3071
      var content = this._input.next();
3072
      if (c === '"') {
3073
        content += this.__patterns.double_quote.read();
3074
      } else {
3075
        content += this.__patterns.single_quote.read();
3076
      }
3077
      token = this._create_token(TOKEN.VALUE, content);
3078
    } else {
3079
      resulting_string = this.__patterns.attribute.read();
3080
 
3081
      if (resulting_string) {
3082
        if (previous_token.type === TOKEN.EQUALS) {
3083
          token = this._create_token(TOKEN.VALUE, resulting_string);
3084
        } else {
3085
          token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
3086
        }
3087
      }
3088
    }
3089
  }
3090
  return token;
3091
};
3092
 
3093
Tokenizer.prototype._is_content_unformatted = function(tag_name) {
3094
  // void_elements have no content and so cannot have unformatted content
3095
  // script and style tags should always be read as unformatted content
3096
  // finally content_unformatted and unformatted element contents are unformatted
3097
  return this._options.void_elements.indexOf(tag_name) === -1 &&
3098
    (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
3099
      this._options.unformatted.indexOf(tag_name) !== -1);
3100
};
3101
 
3102
 
3103
Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
3104
  var resulting_string = '';
3105
  if (open_token && open_token.text[0] === '{') {
3106
    resulting_string = this.__patterns.handlebars_raw_close.read();
3107
  } else if (previous_token.type === TOKEN.TAG_CLOSE &&
3108
    previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
3109
    // ^^ empty tag has no content
3110
    var tag_name = previous_token.opened.text.substr(1).toLowerCase();
3111
    if (tag_name === 'script' || tag_name === 'style') {
3112
      // Script and style tags are allowed to have comments wrapping their content
3113
      // or just have regular content.
3114
      var token = this._read_comment_or_cdata(c);
3115
      if (token) {
3116
        token.type = TOKEN.TEXT;
3117
        return token;
3118
      }
3119
      resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
3120
    } else if (this._is_content_unformatted(tag_name)) {
3121
 
3122
      resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
3123
    }
3124
  }
3125
 
3126
  if (resulting_string) {
3127
    return this._create_token(TOKEN.TEXT, resulting_string);
3128
  }
3129
 
3130
  return null;
3131
};
3132
 
3133
Tokenizer.prototype._read_content_word = function(c, open_token) {
3134
  var resulting_string = '';
3135
  if (this._options.unformatted_content_delimiter) {
3136
    if (c === this._options.unformatted_content_delimiter[0]) {
3137
      resulting_string = this.__patterns.unformatted_content_delimiter.read();
3138
    }
3139
  }
3140
 
3141
  if (!resulting_string) {
3142
    resulting_string = (open_token && open_token.type === TOKEN.CONTROL_FLOW_OPEN) ? this.__patterns.word_control_flow_close_excluded.read() : this.__patterns.word.read();
3143
  }
3144
  if (resulting_string) {
3145
    return this._create_token(TOKEN.TEXT, resulting_string);
3146
  }
3147
};
3148
 
3149
module.exports.Tokenizer = Tokenizer;
3150
module.exports.TOKEN = TOKEN;
3151
 
3152
 
3153
/***/ })
3154
/******/ 	]);
3155
/************************************************************************/
3156
/******/ 	// The module cache
3157
/******/ 	var __webpack_module_cache__ = {};
3158
/******/
3159
/******/ 	// The require function
3160
/******/ 	function __webpack_require__(moduleId) {
3161
/******/ 		// Check if module is in cache
3162
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
3163
/******/ 		if (cachedModule !== undefined) {
3164
/******/ 			return cachedModule.exports;
3165
/******/ 		}
3166
/******/ 		// Create a new module (and put it into the cache)
3167
/******/ 		var module = __webpack_module_cache__[moduleId] = {
3168
/******/ 			// no module.id needed
3169
/******/ 			// no module.loaded needed
3170
/******/ 			exports: {}
3171
/******/ 		};
3172
/******/
3173
/******/ 		// Execute the module function
3174
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
3175
/******/
3176
/******/ 		// Return the exports of the module
3177
/******/ 		return module.exports;
3178
/******/ 	}
3179
/******/
3180
/************************************************************************/
3181
/******/
3182
/******/ 	// startup
3183
/******/ 	// Load entry module and return exports
3184
/******/ 	// This entry module is referenced by other modules so it can't be inlined
3185
/******/ 	var __webpack_exports__ = __webpack_require__(18);
3186
/******/ 	legacy_beautify_html = __webpack_exports__;
3187
/******/
3188
/******/ })()
3189
;
3190
var style_html = legacy_beautify_html;
3191
/* Footer */
3192
if (typeof define === "function" && define.amd) {
3193
    // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
3194
    define(["require", "./beautify", "./beautify-css"], function(requireamd) {
3195
        var js_beautify = requireamd("./beautify");
3196
        var css_beautify = requireamd("./beautify-css");
3197
 
3198
        return {
3199
            html_beautify: function(html_source, options) {
3200
                return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
3201
            }
3202
        };
3203
    });
3204
} else if (typeof exports !== "undefined") {
3205
    // Add support for CommonJS. Just put this file somewhere on your require.paths
3206
    // and you will be able to `var html_beautify = require("beautify").html_beautify`.
3207
    var js_beautify = require('./beautify.js');
3208
    var css_beautify = require('./beautify-css.js');
3209
 
3210
    exports.html_beautify = function(html_source, options) {
3211
        return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
3212
    };
3213
} else if (typeof window !== "undefined") {
3214
    // If we're running a web page and don't have either of the above, add our one global
3215
    window.html_beautify = function(html_source, options) {
3216
        return style_html(html_source, options, window.js_beautify, window.css_beautify);
3217
    };
3218
} else if (typeof global !== "undefined") {
3219
    // If we don't even have window, try global.
3220
    global.html_beautify = function(html_source, options) {
3221
        return style_html(html_source, options, global.js_beautify, global.css_beautify);
3222
    };
3223
}
3224
 
3225
}());