-
Notifications
You must be signed in to change notification settings - Fork 4
/
beautify-html.js
3136 lines (2568 loc) · 107 KB
/
beautify-html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* AUTO-GENERATED. DO NOT MODIFY. */
/*
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Style HTML
---------------
Written by Nochum Sossonko, ([email protected])
Based on code initially developed by: Einar Lielmanis, <[email protected]>
https://beautifier.io/
Usage:
style_html(html_source);
style_html(html_source, options);
The options are:
indent_inner_html (default false) — indent <head> and <body> sections,
indent_size (default 4) — indentation size,
indent_char (default space) — character to indent with,
wrap_line_length (default 250) - maximum amount of characters per line (0 = disable)
brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none"
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.
inline (defaults to inline tags) - list of tags to be considered inline tags
unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted
content_unformatted (defaults to ["pre", "textarea"] tags) - list of tags, whose content shouldn't be reformatted
indent_scripts (default normal) - "keep"|"separate"|"normal"
preserve_newlines (default true) - whether existing line breaks before elements should be preserved
Only works before elements, not inside tags or for text.
max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk
indent_handlebars (default false) - format and indent {{#foo}} and {{/foo}}
end_with_newline (false) - end with a newline
extra_liners (default [head,body,/html]) -List of tags that should have an extra newline before them.
e.g.
style_html(html_source, {
'indent_inner_html': false,
'indent_size': 2,
'indent_char': ' ',
'wrap_line_length': 78,
'brace_style': 'expand',
'preserve_newlines': true,
'max_preserve_newlines': 5,
'indent_handlebars': false,
'extra_liners': ['/html']
});
*/
(function() {
/* GENERATED_BUILD_OUTPUT */
var legacy_beautify_html;
/******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
/* 0 */,
/* 1 */,
/* 2 */
/***/ (function(module) {
/*jshint node:true */
/*
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
function OutputLine(parent) {
this.__parent = parent;
this.__character_count = 0;
// use indent_count as a marker for this.__lines that have preserved indentation
this.__indent_count = -1;
this.__alignment_count = 0;
this.__wrap_point_index = 0;
this.__wrap_point_character_count = 0;
this.__wrap_point_indent_count = -1;
this.__wrap_point_alignment_count = 0;
this.__items = [];
}
OutputLine.prototype.clone_empty = function() {
var line = new OutputLine(this.__parent);
line.set_indent(this.__indent_count, this.__alignment_count);
return line;
};
OutputLine.prototype.item = function(index) {
if (index < 0) {
return this.__items[this.__items.length + index];
} else {
return this.__items[index];
}
};
OutputLine.prototype.has_match = function(pattern) {
for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
if (this.__items[lastCheckedOutput].match(pattern)) {
return true;
}
}
return false;
};
OutputLine.prototype.set_indent = function(indent, alignment) {
if (this.is_empty()) {
this.__indent_count = indent || 0;
this.__alignment_count = alignment || 0;
this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
}
};
OutputLine.prototype._set_wrap_point = function() {
if (this.__parent.wrap_line_length) {
this.__wrap_point_index = this.__items.length;
this.__wrap_point_character_count = this.__character_count;
this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
}
};
OutputLine.prototype._should_wrap = function() {
return this.__wrap_point_index &&
this.__character_count > this.__parent.wrap_line_length &&
this.__wrap_point_character_count > this.__parent.next_line.__character_count;
};
OutputLine.prototype._allow_wrap = function() {
if (this._should_wrap()) {
this.__parent.add_new_line();
var next = this.__parent.current_line;
next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
next.__items = this.__items.slice(this.__wrap_point_index);
this.__items = this.__items.slice(0, this.__wrap_point_index);
next.__character_count += this.__character_count - this.__wrap_point_character_count;
this.__character_count = this.__wrap_point_character_count;
if (next.__items[0] === " ") {
next.__items.splice(0, 1);
next.__character_count -= 1;
}
return true;
}
return false;
};
OutputLine.prototype.is_empty = function() {
return this.__items.length === 0;
};
OutputLine.prototype.last = function() {
if (!this.is_empty()) {
return this.__items[this.__items.length - 1];
} else {
return null;
}
};
OutputLine.prototype.push = function(item) {
this.__items.push(item);
var last_newline_index = item.lastIndexOf('\n');
if (last_newline_index !== -1) {
this.__character_count = item.length - last_newline_index;
} else {
this.__character_count += item.length;
}
};
OutputLine.prototype.pop = function() {
var item = null;
if (!this.is_empty()) {
item = this.__items.pop();
this.__character_count -= item.length;
}
return item;
};
OutputLine.prototype._remove_indent = function() {
if (this.__indent_count > 0) {
this.__indent_count -= 1;
this.__character_count -= this.__parent.indent_size;
}
};
OutputLine.prototype._remove_wrap_indent = function() {
if (this.__wrap_point_indent_count > 0) {
this.__wrap_point_indent_count -= 1;
}
};
OutputLine.prototype.trim = function() {
while (this.last() === ' ') {
this.__items.pop();
this.__character_count -= 1;
}
};
OutputLine.prototype.toString = function() {
var result = '';
if (this.is_empty()) {
if (this.__parent.indent_empty_lines) {
result = this.__parent.get_indent_string(this.__indent_count);
}
} else {
result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
result += this.__items.join('');
}
return result;
};
function IndentStringCache(options, baseIndentString) {
this.__cache = [''];
this.__indent_size = options.indent_size;
this.__indent_string = options.indent_char;
if (!options.indent_with_tabs) {
this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
}
// Set to null to continue support for auto detection of base indent
baseIndentString = baseIndentString || '';
if (options.indent_level > 0) {
baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
}
this.__base_string = baseIndentString;
this.__base_string_length = baseIndentString.length;
}
IndentStringCache.prototype.get_indent_size = function(indent, column) {
var result = this.__base_string_length;
column = column || 0;
if (indent < 0) {
result = 0;
}
result += indent * this.__indent_size;
result += column;
return result;
};
IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
var result = this.__base_string;
column = column || 0;
if (indent_level < 0) {
indent_level = 0;
result = '';
}
column += indent_level * this.__indent_size;
this.__ensure_cache(column);
result += this.__cache[column];
return result;
};
IndentStringCache.prototype.__ensure_cache = function(column) {
while (column >= this.__cache.length) {
this.__add_column();
}
};
IndentStringCache.prototype.__add_column = function() {
var column = this.__cache.length;
var indent = 0;
var result = '';
if (this.__indent_size && column >= this.__indent_size) {
indent = Math.floor(column / this.__indent_size);
column -= indent * this.__indent_size;
result = new Array(indent + 1).join(this.__indent_string);
}
if (column) {
result += new Array(column + 1).join(' ');
}
this.__cache.push(result);
};
function Output(options, baseIndentString) {
this.__indent_cache = new IndentStringCache(options, baseIndentString);
this.raw = false;
this._end_with_newline = options.end_with_newline;
this.indent_size = options.indent_size;
this.wrap_line_length = options.wrap_line_length;
this.indent_empty_lines = options.indent_empty_lines;
this.__lines = [];
this.previous_line = null;
this.current_line = null;
this.next_line = new OutputLine(this);
this.space_before_token = false;
this.non_breaking_space = false;
this.previous_token_wrapped = false;
// initialize
this.__add_outputline();
}
Output.prototype.__add_outputline = function() {
this.previous_line = this.current_line;
this.current_line = this.next_line.clone_empty();
this.__lines.push(this.current_line);
};
Output.prototype.get_line_number = function() {
return this.__lines.length;
};
Output.prototype.get_indent_string = function(indent, column) {
return this.__indent_cache.get_indent_string(indent, column);
};
Output.prototype.get_indent_size = function(indent, column) {
return this.__indent_cache.get_indent_size(indent, column);
};
Output.prototype.is_empty = function() {
return !this.previous_line && this.current_line.is_empty();
};
Output.prototype.add_new_line = function(force_newline) {
// never newline at the start of file
// otherwise, newline only if we didn't just add one or we're forced
if (this.is_empty() ||
(!force_newline && this.just_added_newline())) {
return false;
}
// if raw output is enabled, don't print additional newlines,
// but still return True as though you had
if (!this.raw) {
this.__add_outputline();
}
return true;
};
Output.prototype.get_code = function(eol) {
this.trim(true);
// handle some edge cases where the last tokens
// has text that ends with newline(s)
var last_item = this.current_line.pop();
if (last_item) {
if (last_item[last_item.length - 1] === '\n') {
last_item = last_item.replace(/\n+$/g, '');
}
this.current_line.push(last_item);
}
if (this._end_with_newline) {
this.__add_outputline();
}
var sweet_code = this.__lines.join('\n');
if (eol !== '\n') {
sweet_code = sweet_code.replace(/[\n]/g, eol);
}
return sweet_code;
};
Output.prototype.set_wrap_point = function() {
this.current_line._set_wrap_point();
};
Output.prototype.set_indent = function(indent, alignment) {
indent = indent || 0;
alignment = alignment || 0;
// Next line stores alignment values
this.next_line.set_indent(indent, alignment);
// Never indent your first output indent at the start of the file
if (this.__lines.length > 1) {
this.current_line.set_indent(indent, alignment);
return true;
}
this.current_line.set_indent();
return false;
};
Output.prototype.add_raw_token = function(token) {
for (var x = 0; x < token.newlines; x++) {
this.__add_outputline();
}
this.current_line.set_indent(-1);
this.current_line.push(token.whitespace_before);
this.current_line.push(token.text);
this.space_before_token = false;
this.non_breaking_space = false;
this.previous_token_wrapped = false;
};
Output.prototype.add_token = function(printable_token) {
this.__add_space_before_token();
this.current_line.push(printable_token);
this.space_before_token = false;
this.non_breaking_space = false;
this.previous_token_wrapped = this.current_line._allow_wrap();
};
Output.prototype.__add_space_before_token = function() {
if (this.space_before_token && !this.just_added_newline()) {
if (!this.non_breaking_space) {
this.set_wrap_point();
}
this.current_line.push(' ');
}
};
Output.prototype.remove_indent = function(index) {
var output_length = this.__lines.length;
while (index < output_length) {
this.__lines[index]._remove_indent();
index++;
}
this.current_line._remove_wrap_indent();
};
Output.prototype.trim = function(eat_newlines) {
eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
this.current_line.trim();
while (eat_newlines && this.__lines.length > 1 &&
this.current_line.is_empty()) {
this.__lines.pop();
this.current_line = this.__lines[this.__lines.length - 1];
this.current_line.trim();
}
this.previous_line = this.__lines.length > 1 ?
this.__lines[this.__lines.length - 2] : null;
};
Output.prototype.just_added_newline = function() {
return this.current_line.is_empty();
};
Output.prototype.just_added_blankline = function() {
return this.is_empty() ||
(this.current_line.is_empty() && this.previous_line.is_empty());
};
Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
var index = this.__lines.length - 2;
while (index >= 0) {
var potentialEmptyLine = this.__lines[index];
if (potentialEmptyLine.is_empty()) {
break;
} else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
potentialEmptyLine.item(-1) !== ends_with) {
this.__lines.splice(index + 1, 0, new OutputLine(this));
this.previous_line = this.__lines[this.__lines.length - 2];
break;
}
index--;
}
};
module.exports.Output = Output;
/***/ }),
/* 3 */
/***/ (function(module) {
/*jshint node:true */
/*
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
function Token(type, text, newlines, whitespace_before) {
this.type = type;
this.text = text;
// comments_before are
// comments that have a new line before them
// and may or may not have a newline after
// this is a set of comments before
this.comments_before = null; /* inline comment*/
// this.comments_after = new TokenStream(); // no new line before and newline after
this.newlines = newlines || 0;
this.whitespace_before = whitespace_before || '';
this.parent = null;
this.next = null;
this.previous = null;
this.opened = null;
this.closed = null;
this.directives = null;
}
module.exports.Token = Token;
/***/ }),
/* 4 */,
/* 5 */,
/* 6 */
/***/ (function(module) {
/*jshint node:true */
/*
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
function Options(options, merge_child_field) {
this.raw_options = _mergeOpts(options, merge_child_field);
// Support passing the source text back with no change
this.disabled = this._get_boolean('disabled');
this.eol = this._get_characters('eol', 'auto');
this.end_with_newline = this._get_boolean('end_with_newline');
this.indent_size = this._get_number('indent_size', 4);
this.indent_char = this._get_characters('indent_char', ' ');
this.indent_level = this._get_number('indent_level');
this.preserve_newlines = this._get_boolean('preserve_newlines', true);
this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
if (!this.preserve_newlines) {
this.max_preserve_newlines = 0;
}
this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
if (this.indent_with_tabs) {
this.indent_char = '\t';
// indent_size behavior changed after 1.8.6
// It used to be that indent_size would be
// set to 1 for indent_with_tabs. That is no longer needed and
// actually doesn't make sense - why not use spaces? Further,
// that might produce unexpected behavior - tabs being used
// for single-column alignment. So, when indent_with_tabs is true
// and indent_size is 1, reset indent_size to 4.
if (this.indent_size === 1) {
this.indent_size = 4;
}
}
// Backwards compat with 1.3.x
this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
this.indent_empty_lines = this._get_boolean('indent_empty_lines');
// valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty']
// For now, 'auto' = all off for javascript, all on for html (and inline javascript).
// other values ignored
this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
}
Options.prototype._get_array = function(name, default_value) {
var option_value = this.raw_options[name];
var result = default_value || [];
if (typeof option_value === 'object') {
if (option_value !== null && typeof option_value.concat === 'function') {
result = option_value.concat();
}
} else if (typeof option_value === 'string') {
result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
}
return result;
};
Options.prototype._get_boolean = function(name, default_value) {
var option_value = this.raw_options[name];
var result = option_value === undefined ? !!default_value : !!option_value;
return result;
};
Options.prototype._get_characters = function(name, default_value) {
var option_value = this.raw_options[name];
var result = default_value || '';
if (typeof option_value === 'string') {
result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
}
return result;
};
Options.prototype._get_number = function(name, default_value) {
var option_value = this.raw_options[name];
default_value = parseInt(default_value, 10);
if (isNaN(default_value)) {
default_value = 0;
}
var result = parseInt(option_value, 10);
if (isNaN(result)) {
result = default_value;
}
return result;
};
Options.prototype._get_selection = function(name, selection_list, default_value) {
var result = this._get_selection_list(name, selection_list, default_value);
if (result.length !== 1) {
throw new Error(
"Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
}
return result[0];
};
Options.prototype._get_selection_list = function(name, selection_list, default_value) {
if (!selection_list || selection_list.length === 0) {
throw new Error("Selection list cannot be empty.");
}
default_value = default_value || [selection_list[0]];
if (!this._is_valid_selection(default_value, selection_list)) {
throw new Error("Invalid Default Value!");
}
var result = this._get_array(name, default_value);
if (!this._is_valid_selection(result, selection_list)) {
throw new Error(
"Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
}
return result;
};
Options.prototype._is_valid_selection = function(result, selection_list) {
return result.length && selection_list.length &&
!result.some(function(item) { return selection_list.indexOf(item) === -1; });
};
// merges child options up with the parent options object
// Example: obj = {a: 1, b: {a: 2}}
// mergeOpts(obj, 'b')
//
// Returns: {a: 2}
function _mergeOpts(allOptions, childFieldName) {
var finalOpts = {};
allOptions = _normalizeOpts(allOptions);
var name;
for (name in allOptions) {
if (name !== childFieldName) {
finalOpts[name] = allOptions[name];
}
}
//merge in the per type settings for the childFieldName
if (childFieldName && allOptions[childFieldName]) {
for (name in allOptions[childFieldName]) {
finalOpts[name] = allOptions[childFieldName][name];
}
}
return finalOpts;
}
function _normalizeOpts(options) {
var convertedOpts = {};
var key;
for (key in options) {
var newKey = key.replace(/-/g, "_");
convertedOpts[newKey] = options[key];
}
return convertedOpts;
}
module.exports.Options = Options;
module.exports.normalizeOpts = _normalizeOpts;
module.exports.mergeOpts = _mergeOpts;
/***/ }),
/* 7 */,
/* 8 */
/***/ (function(module) {
/*jshint node:true */
/*
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
function InputScanner(input_string) {
this.__input = input_string || '';
this.__input_length = this.__input.length;
this.__position = 0;
}
InputScanner.prototype.restart = function() {
this.__position = 0;
};
InputScanner.prototype.back = function() {
if (this.__position > 0) {
this.__position -= 1;
}
};
InputScanner.prototype.hasNext = function() {
return this.__position < this.__input_length;
};
InputScanner.prototype.next = function() {
var val = null;
if (this.hasNext()) {
val = this.__input.charAt(this.__position);
this.__position += 1;
}
return val;
};
InputScanner.prototype.peek = function(index) {
var val = null;
index = index || 0;
index += this.__position;
if (index >= 0 && index < this.__input_length) {
val = this.__input.charAt(index);
}
return val;
};
// This is a JavaScript only helper function (not in python)
// Javascript doesn't have a match method
// and not all implementation support "sticky" flag.
// If they do not support sticky then both this.match() and this.test() method
// must get the match and check the index of the match.
// If sticky is supported and set, this method will use it.
// Otherwise it will check that global is set, and fall back to the slower method.
InputScanner.prototype.__match = function(pattern, index) {
pattern.lastIndex = index;
var pattern_match = pattern.exec(this.__input);
if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
if (pattern_match.index !== index) {
pattern_match = null;
}
}
return pattern_match;
};
InputScanner.prototype.test = function(pattern, index) {
index = index || 0;
index += this.__position;
if (index >= 0 && index < this.__input_length) {
return !!this.__match(pattern, index);
} else {
return false;
}
};
InputScanner.prototype.testChar = function(pattern, index) {
// test one character regex match
var val = this.peek(index);
pattern.lastIndex = 0;
return val !== null && pattern.test(val);
};
InputScanner.prototype.match = function(pattern) {
var pattern_match = this.__match(pattern, this.__position);
if (pattern_match) {
this.__position += pattern_match[0].length;
} else {
pattern_match = null;
}
return pattern_match;
};
InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
var val = '';
var match;
if (starting_pattern) {
match = this.match(starting_pattern);
if (match) {
val += match[0];
}
}
if (until_pattern && (match || !starting_pattern)) {
val += this.readUntil(until_pattern, until_after);
}
return val;
};
InputScanner.prototype.readUntil = function(pattern, until_after) {
var val = '';
var match_index = this.__position;
pattern.lastIndex = this.__position;
var pattern_match = pattern.exec(this.__input);
if (pattern_match) {
match_index = pattern_match.index;
if (until_after) {
match_index += pattern_match[0].length;
}
} else {
match_index = this.__input_length;
}
val = this.__input.substring(this.__position, match_index);
this.__position = match_index;
return val;
};
InputScanner.prototype.readUntilAfter = function(pattern) {
return this.readUntil(pattern, true);
};
InputScanner.prototype.get_regexp = function(pattern, match_from) {
var result = null;
var flags = 'g';
if (match_from && regexp_has_sticky) {
flags = 'y';
}
// strings are converted to regexp
if (typeof pattern === "string" && pattern !== '') {
// result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
result = new RegExp(pattern, flags);
} else if (pattern) {
result = new RegExp(pattern.source, flags);
}
return result;
};
InputScanner.prototype.get_literal_regexp = function(literal_string) {
return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
};
/* css beautifier legacy helpers */
InputScanner.prototype.peekUntilAfter = function(pattern) {
var start = this.__position;
var val = this.readUntilAfter(pattern);
this.__position = start;
return val;
};
InputScanner.prototype.lookBack = function(testVal) {
var start = this.__position - 1;
return start >= testVal.length && this.__input.substring(start - testVal.length, start)
.toLowerCase() === testVal;
};
module.exports.InputScanner = InputScanner;
/***/ }),
/* 9 */
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
/*jshint node:true */
/*
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/