3124 lines
107 KiB
JavaScript
3124 lines
107 KiB
JavaScript
/* 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, (nsossonko@hotmail.com)
|
||
|
||
Based on code initially developed by: Einar Lielmanis, <einar@beautifier.io>
|
||
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.
|
||
*/
|
||
|
||
|
||
|
||
var InputScanner = __webpack_require__(8).InputScanner;
|
||
var Token = __webpack_require__(3).Token;
|
||
var TokenStream = __webpack_require__(10).TokenStream;
|
||
var WhitespacePattern = __webpack_require__(11).WhitespacePattern;
|
||
|
||
var TOKEN = {
|
||
START: 'TK_START',
|
||
RAW: 'TK_RAW',
|
||
EOF: 'TK_EOF'
|
||
};
|
||
|
||
var Tokenizer = function(input_string, options) {
|
||
this._input = new InputScanner(input_string);
|
||
this._options = options || {};
|
||
this.__tokens = null;
|
||
|
||
this._patterns = {};
|
||
this._patterns.whitespace = new WhitespacePattern(this._input);
|
||
};
|
||
|
||
Tokenizer.prototype.tokenize = function() {
|
||
this._input.restart();
|
||
this.__tokens = new TokenStream();
|
||
|
||
this._reset();
|
||
|
||
var current;
|
||
var previous = new Token(TOKEN.START, '');
|
||
var open_token = null;
|
||
var open_stack = [];
|
||
var comments = new TokenStream();
|
||
|
||
while (previous.type !== TOKEN.EOF) {
|
||
current = this._get_next_token(previous, open_token);
|
||
while (this._is_comment(current)) {
|
||
comments.add(current);
|
||
current = this._get_next_token(previous, open_token);
|
||
}
|
||
|
||
if (!comments.isEmpty()) {
|
||
current.comments_before = comments;
|
||
comments = new TokenStream();
|
||
}
|
||
|
||
current.parent = open_token;
|
||
|
||
if (this._is_opening(current)) {
|
||
open_stack.push(open_token);
|
||
open_token = current;
|
||
} else if (open_token && this._is_closing(current, open_token)) {
|
||
current.opened = open_token;
|
||
open_token.closed = current;
|
||
open_token = open_stack.pop();
|
||
current.parent = open_token;
|
||
}
|
||
|
||
current.previous = previous;
|
||
previous.next = current;
|
||
|
||
this.__tokens.add(current);
|
||
previous = current;
|
||
}
|
||
|
||
return this.__tokens;
|
||
};
|
||
|
||
|
||
Tokenizer.prototype._is_first_token = function() {
|
||
return this.__tokens.isEmpty();
|
||
};
|
||
|
||
Tokenizer.prototype._reset = function() {};
|
||
|
||
Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
|
||
this._readWhitespace();
|
||
var resulting_string = this._input.read(/.+/g);
|
||
if (resulting_string) {
|
||
return this._create_token(TOKEN.RAW, resulting_string);
|
||
} else {
|
||
return this._create_token(TOKEN.EOF, '');
|
||
}
|
||
};
|
||
|
||
Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
|
||
return false;
|
||
};
|
||
|
||
Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
|
||
return false;
|
||
};
|
||
|
||
Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
|
||
return false;
|
||
};
|
||
|
||
Tokenizer.prototype._create_token = function(type, text) {
|
||
var token = new Token(type, text,
|
||
this._patterns.whitespace.newline_count,
|
||
this._patterns.whitespace.whitespace_before_token);
|
||
return token;
|
||
};
|
||
|
||
Tokenizer.prototype._readWhitespace = function() {
|
||
return this._patterns.whitespace.read();
|
||
};
|
||
|
||
|
||
|
||
module.exports.Tokenizer = Tokenizer;
|
||
module.exports.TOKEN = TOKEN;
|
||
|
||
|
||
/***/ }),
|
||
/* 10 */
|
||
/***/ (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 TokenStream(parent_token) {
|
||
// private
|
||
this.__tokens = [];
|
||
this.__tokens_length = this.__tokens.length;
|
||
this.__position = 0;
|
||
this.__parent_token = parent_token;
|
||
}
|
||
|
||
TokenStream.prototype.restart = function() {
|
||
this.__position = 0;
|
||
};
|
||
|
||
TokenStream.prototype.isEmpty = function() {
|
||
return this.__tokens_length === 0;
|
||
};
|
||
|
||
TokenStream.prototype.hasNext = function() {
|
||
return this.__position < this.__tokens_length;
|
||
};
|
||
|
||
TokenStream.prototype.next = function() {
|
||
var val = null;
|
||
if (this.hasNext()) {
|
||
val = this.__tokens[this.__position];
|
||
this.__position += 1;
|
||
}
|
||
return val;
|
||
};
|
||
|
||
TokenStream.prototype.peek = function(index) {
|
||
var val = null;
|
||
index = index || 0;
|
||
index += this.__position;
|
||
if (index >= 0 && index < this.__tokens_length) {
|
||
val = this.__tokens[index];
|
||
}
|
||
return val;
|
||
};
|
||
|
||
TokenStream.prototype.add = function(token) {
|
||
if (this.__parent_token) {
|
||
token.parent = this.__parent_token;
|
||
}
|
||
this.__tokens.push(token);
|
||
this.__tokens_length += 1;
|
||
};
|
||
|
||
module.exports.TokenStream = TokenStream;
|
||
|
||
|
||
/***/ }),
|
||
/* 11 */
|
||
/***/ (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.
|
||
*/
|
||
|
||
|
||
|
||
var Pattern = __webpack_require__(12).Pattern;
|
||
|
||
function WhitespacePattern(input_scanner, parent) {
|
||
Pattern.call(this, input_scanner, parent);
|
||
if (parent) {
|
||
this._line_regexp = this._input.get_regexp(parent._line_regexp);
|
||
} else {
|
||
this.__set_whitespace_patterns('', '');
|
||
}
|
||
|
||
this.newline_count = 0;
|
||
this.whitespace_before_token = '';
|
||
}
|
||
WhitespacePattern.prototype = new Pattern();
|
||
|
||
WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
|
||
whitespace_chars += '\\t ';
|
||
newline_chars += '\\n\\r';
|
||
|
||
this._match_pattern = this._input.get_regexp(
|
||
'[' + whitespace_chars + newline_chars + ']+', true);
|
||
this._newline_regexp = this._input.get_regexp(
|
||
'\\r\\n|[' + newline_chars + ']');
|
||
};
|
||
|
||
WhitespacePattern.prototype.read = function() {
|
||
this.newline_count = 0;
|
||
this.whitespace_before_token = '';
|
||
|
||
var resulting_string = this._input.read(this._match_pattern);
|
||
if (resulting_string === ' ') {
|
||
this.whitespace_before_token = ' ';
|
||
} else if (resulting_string) {
|
||
var matches = this.__split(this._newline_regexp, resulting_string);
|
||
this.newline_count = matches.length - 1;
|
||
this.whitespace_before_token = matches[this.newline_count];
|
||
}
|
||
|
||
return resulting_string;
|
||
};
|
||
|
||
WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
|
||
var result = this._create();
|
||
result.__set_whitespace_patterns(whitespace_chars, newline_chars);
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
WhitespacePattern.prototype._create = function() {
|
||
return new WhitespacePattern(this._input, this);
|
||
};
|
||
|
||
WhitespacePattern.prototype.__split = function(regexp, input_string) {
|
||
regexp.lastIndex = 0;
|
||
var start_index = 0;
|
||
var result = [];
|
||
var next_match = regexp.exec(input_string);
|
||
while (next_match) {
|
||
result.push(input_string.substring(start_index, next_match.index));
|
||
start_index = next_match.index + next_match[0].length;
|
||
next_match = regexp.exec(input_string);
|
||
}
|
||
|
||
if (start_index < input_string.length) {
|
||
result.push(input_string.substring(start_index, input_string.length));
|
||
} else {
|
||
result.push('');
|
||
}
|
||
|
||
return result;
|
||
};
|
||
|
||
|
||
|
||
module.exports.WhitespacePattern = WhitespacePattern;
|
||
|
||
|
||
/***/ }),
|
||
/* 12 */
|
||
/***/ (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 Pattern(input_scanner, parent) {
|
||
this._input = input_scanner;
|
||
this._starting_pattern = null;
|
||
this._match_pattern = null;
|
||
this._until_pattern = null;
|
||
this._until_after = false;
|
||
|
||
if (parent) {
|
||
this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
|
||
this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
|
||
this._until_pattern = this._input.get_regexp(parent._until_pattern);
|
||
this._until_after = parent._until_after;
|
||
}
|
||
}
|
||
|
||
Pattern.prototype.read = function() {
|
||
var result = this._input.read(this._starting_pattern);
|
||
if (!this._starting_pattern || result) {
|
||
result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
|
||
}
|
||
return result;
|
||
};
|
||
|
||
Pattern.prototype.read_match = function() {
|
||
return this._input.match(this._match_pattern);
|
||
};
|
||
|
||
Pattern.prototype.until_after = function(pattern) {
|
||
var result = this._create();
|
||
result._until_after = true;
|
||
result._until_pattern = this._input.get_regexp(pattern);
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
Pattern.prototype.until = function(pattern) {
|
||
var result = this._create();
|
||
result._until_after = false;
|
||
result._until_pattern = this._input.get_regexp(pattern);
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
Pattern.prototype.starting_with = function(pattern) {
|
||
var result = this._create();
|
||
result._starting_pattern = this._input.get_regexp(pattern, true);
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
Pattern.prototype.matching = function(pattern) {
|
||
var result = this._create();
|
||
result._match_pattern = this._input.get_regexp(pattern, true);
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
Pattern.prototype._create = function() {
|
||
return new Pattern(this._input, this);
|
||
};
|
||
|
||
Pattern.prototype._update = function() {};
|
||
|
||
module.exports.Pattern = Pattern;
|
||
|
||
|
||
/***/ }),
|
||
/* 13 */
|
||
/***/ (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 Directives(start_block_pattern, end_block_pattern) {
|
||
start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
|
||
end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
|
||
this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
|
||
this.__directive_pattern = / (\w+)[:](\w+)/g;
|
||
|
||
this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
|
||
}
|
||
|
||
Directives.prototype.get_directives = function(text) {
|
||
if (!text.match(this.__directives_block_pattern)) {
|
||
return null;
|
||
}
|
||
|
||
var directives = {};
|
||
this.__directive_pattern.lastIndex = 0;
|
||
var directive_match = this.__directive_pattern.exec(text);
|
||
|
||
while (directive_match) {
|
||
directives[directive_match[1]] = directive_match[2];
|
||
directive_match = this.__directive_pattern.exec(text);
|
||
}
|
||
|
||
return directives;
|
||
};
|
||
|
||
Directives.prototype.readIgnored = function(input) {
|
||
return input.readUntilAfter(this.__directives_end_ignore_pattern);
|
||
};
|
||
|
||
|
||
module.exports.Directives = Directives;
|
||
|
||
|
||
/***/ }),
|
||
/* 14 */
|
||
/***/ (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.
|
||
*/
|
||
|
||
|
||
|
||
var Pattern = __webpack_require__(12).Pattern;
|
||
|
||
|
||
var template_names = {
|
||
django: false,
|
||
erb: false,
|
||
handlebars: false,
|
||
php: false,
|
||
smarty: false
|
||
};
|
||
|
||
// This lets templates appear anywhere we would do a readUntil
|
||
// The cost is higher but it is pay to play.
|
||
function TemplatablePattern(input_scanner, parent) {
|
||
Pattern.call(this, input_scanner, parent);
|
||
this.__template_pattern = null;
|
||
this._disabled = Object.assign({}, template_names);
|
||
this._excluded = Object.assign({}, template_names);
|
||
|
||
if (parent) {
|
||
this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
|
||
this._excluded = Object.assign(this._excluded, parent._excluded);
|
||
this._disabled = Object.assign(this._disabled, parent._disabled);
|
||
}
|
||
var pattern = new Pattern(input_scanner);
|
||
this.__patterns = {
|
||
handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
|
||
handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
|
||
handlebars: pattern.starting_with(/{{/).until_after(/}}/),
|
||
php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
|
||
erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
|
||
// django coflicts with handlebars a bit.
|
||
django: pattern.starting_with(/{%/).until_after(/%}/),
|
||
django_value: pattern.starting_with(/{{/).until_after(/}}/),
|
||
django_comment: pattern.starting_with(/{#/).until_after(/#}/),
|
||
smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
|
||
smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
|
||
smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
|
||
};
|
||
}
|
||
TemplatablePattern.prototype = new Pattern();
|
||
|
||
TemplatablePattern.prototype._create = function() {
|
||
return new TemplatablePattern(this._input, this);
|
||
};
|
||
|
||
TemplatablePattern.prototype._update = function() {
|
||
this.__set_templated_pattern();
|
||
};
|
||
|
||
TemplatablePattern.prototype.disable = function(language) {
|
||
var result = this._create();
|
||
result._disabled[language] = true;
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
TemplatablePattern.prototype.read_options = function(options) {
|
||
var result = this._create();
|
||
for (var language in template_names) {
|
||
result._disabled[language] = options.templating.indexOf(language) === -1;
|
||
}
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
TemplatablePattern.prototype.exclude = function(language) {
|
||
var result = this._create();
|
||
result._excluded[language] = true;
|
||
result._update();
|
||
return result;
|
||
};
|
||
|
||
TemplatablePattern.prototype.read = function() {
|
||
var result = '';
|
||
if (this._match_pattern) {
|
||
result = this._input.read(this._starting_pattern);
|
||
} else {
|
||
result = this._input.read(this._starting_pattern, this.__template_pattern);
|
||
}
|
||
var next = this._read_template();
|
||
while (next) {
|
||
if (this._match_pattern) {
|
||
next += this._input.read(this._match_pattern);
|
||
} else {
|
||
next += this._input.readUntil(this.__template_pattern);
|
||
}
|
||
result += next;
|
||
next = this._read_template();
|
||
}
|
||
|
||
if (this._until_after) {
|
||
result += this._input.readUntilAfter(this._until_pattern);
|
||
}
|
||
return result;
|
||
};
|
||
|
||
TemplatablePattern.prototype.__set_templated_pattern = function() {
|
||
var items = [];
|
||
|
||
if (!this._disabled.php) {
|
||
items.push(this.__patterns.php._starting_pattern.source);
|
||
}
|
||
if (!this._disabled.handlebars) {
|
||
items.push(this.__patterns.handlebars._starting_pattern.source);
|
||
}
|
||
if (!this._disabled.erb) {
|
||
items.push(this.__patterns.erb._starting_pattern.source);
|
||
}
|
||
if (!this._disabled.django) {
|
||
items.push(this.__patterns.django._starting_pattern.source);
|
||
// The starting pattern for django is more complex because it has different
|
||
// patterns for value, comment, and other sections
|
||
items.push(this.__patterns.django_value._starting_pattern.source);
|
||
items.push(this.__patterns.django_comment._starting_pattern.source);
|
||
}
|
||
if (!this._disabled.smarty) {
|
||
items.push(this.__patterns.smarty._starting_pattern.source);
|
||
}
|
||
|
||
if (this._until_pattern) {
|
||
items.push(this._until_pattern.source);
|
||
}
|
||
this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
|
||
};
|
||
|
||
TemplatablePattern.prototype._read_template = function() {
|
||
var resulting_string = '';
|
||
var c = this._input.peek();
|
||
if (c === '<') {
|
||
var peek1 = this._input.peek(1);
|
||
//if we're in a comment, do something special
|
||
// We treat all comments as literals, even more than preformatted tags
|
||
// we just look for the appropriate close tag
|
||
if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.php.read();
|
||
}
|
||
if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.erb.read();
|
||
}
|
||
} else if (c === '{') {
|
||
if (!this._disabled.handlebars && !this._excluded.handlebars) {
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.handlebars_comment.read();
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.handlebars_unescaped.read();
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.handlebars.read();
|
||
}
|
||
if (!this._disabled.django) {
|
||
// django coflicts with handlebars a bit.
|
||
if (!this._excluded.django && !this._excluded.handlebars) {
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.django_value.read();
|
||
}
|
||
if (!this._excluded.django) {
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.django_comment.read();
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.django.read();
|
||
}
|
||
}
|
||
if (!this._disabled.smarty) {
|
||
// smarty cannot be enabled with django or handlebars enabled
|
||
if (this._disabled.django && this._disabled.handlebars) {
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.smarty_comment.read();
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.smarty_literal.read();
|
||
resulting_string = resulting_string ||
|
||
this.__patterns.smarty.read();
|
||
}
|
||
}
|
||
}
|
||
return resulting_string;
|
||
};
|
||
|
||
|
||
module.exports.TemplatablePattern = TemplatablePattern;
|
||
|
||
|
||
/***/ }),
|
||
/* 15 */,
|
||
/* 16 */,
|
||
/* 17 */,
|
||
/* 18 */
|
||
/***/ (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.
|
||
*/
|
||
|
||
|
||
|
||
var Beautifier = __webpack_require__(19).Beautifier,
|
||
Options = __webpack_require__(20).Options;
|
||
|
||
function style_html(html_source, options, js_beautify, css_beautify) {
|
||
var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
|
||
return beautifier.beautify();
|
||
}
|
||
|
||
module.exports = style_html;
|
||
module.exports.defaultOptions = function() {
|
||
return new Options();
|
||
};
|
||
|
||
|
||
/***/ }),
|
||
/* 19 */
|
||
/***/ (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.
|
||
*/
|
||
|
||
|
||
|
||
var Options = __webpack_require__(20).Options;
|
||
var Output = __webpack_require__(2).Output;
|
||
var Tokenizer = __webpack_require__(21).Tokenizer;
|
||
var TOKEN = __webpack_require__(21).TOKEN;
|
||
|
||
var lineBreak = /\r\n|[\r\n]/;
|
||
var allLineBreaks = /\r\n|[\r\n]/g;
|
||
|
||
var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions
|
||
|
||
this.indent_level = 0;
|
||
this.alignment_size = 0;
|
||
this.max_preserve_newlines = options.max_preserve_newlines;
|
||
this.preserve_newlines = options.preserve_newlines;
|
||
|
||
this._output = new Output(options, base_indent_string);
|
||
|
||
};
|
||
|
||
Printer.prototype.current_line_has_match = function(pattern) {
|
||
return this._output.current_line.has_match(pattern);
|
||
};
|
||
|
||
Printer.prototype.set_space_before_token = function(value, non_breaking) {
|
||
this._output.space_before_token = value;
|
||
this._output.non_breaking_space = non_breaking;
|
||
};
|
||
|
||
Printer.prototype.set_wrap_point = function() {
|
||
this._output.set_indent(this.indent_level, this.alignment_size);
|
||
this._output.set_wrap_point();
|
||
};
|
||
|
||
|
||
Printer.prototype.add_raw_token = function(token) {
|
||
this._output.add_raw_token(token);
|
||
};
|
||
|
||
Printer.prototype.print_preserved_newlines = function(raw_token) {
|
||
var newlines = 0;
|
||
if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
|
||
newlines = raw_token.newlines ? 1 : 0;
|
||
}
|
||
|
||
if (this.preserve_newlines) {
|
||
newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
|
||
}
|
||
for (var n = 0; n < newlines; n++) {
|
||
this.print_newline(n > 0);
|
||
}
|
||
|
||
return newlines !== 0;
|
||
};
|
||
|
||
Printer.prototype.traverse_whitespace = function(raw_token) {
|
||
if (raw_token.whitespace_before || raw_token.newlines) {
|
||
if (!this.print_preserved_newlines(raw_token)) {
|
||
this._output.space_before_token = true;
|
||
}
|
||
return true;
|
||
}
|
||
return false;
|
||
};
|
||
|
||
Printer.prototype.previous_token_wrapped = function() {
|
||
return this._output.previous_token_wrapped;
|
||
};
|
||
|
||
Printer.prototype.print_newline = function(force) {
|
||
this._output.add_new_line(force);
|
||
};
|
||
|
||
Printer.prototype.print_token = function(token) {
|
||
if (token.text) {
|
||
this._output.set_indent(this.indent_level, this.alignment_size);
|
||
this._output.add_token(token.text);
|
||
}
|
||
};
|
||
|
||
Printer.prototype.indent = function() {
|
||
this.indent_level++;
|
||
};
|
||
|
||
Printer.prototype.get_full_indent = function(level) {
|
||
level = this.indent_level + (level || 0);
|
||
if (level < 1) {
|
||
return '';
|
||
}
|
||
|
||
return this._output.get_indent_string(level);
|
||
};
|
||
|
||
var get_type_attribute = function(start_token) {
|
||
var result = null;
|
||
var raw_token = start_token.next;
|
||
|
||
// Search attributes for a type attribute
|
||
while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
|
||
if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
|
||
if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
|
||
raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
|
||
result = raw_token.next.next.text;
|
||
}
|
||
break;
|
||
}
|
||
raw_token = raw_token.next;
|
||
}
|
||
|
||
return result;
|
||
};
|
||
|
||
var get_custom_beautifier_name = function(tag_check, raw_token) {
|
||
var typeAttribute = null;
|
||
var result = null;
|
||
|
||
if (!raw_token.closed) {
|
||
return null;
|
||
}
|
||
|
||
if (tag_check === 'script') {
|
||
typeAttribute = 'text/javascript';
|
||
} else if (tag_check === 'style') {
|
||
typeAttribute = 'text/css';
|
||
}
|
||
|
||
typeAttribute = get_type_attribute(raw_token) || typeAttribute;
|
||
|
||
// For script and style tags that have a type attribute, only enable custom beautifiers for matching values
|
||
// For those without a type attribute use default;
|
||
if (typeAttribute.search('text/css') > -1) {
|
||
result = 'css';
|
||
} else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
|
||
result = 'javascript';
|
||
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
|
||
result = 'html';
|
||
} else if (typeAttribute.search(/test\/null/) > -1) {
|
||
// Test only mime-type for testing the beautifier when null is passed as beautifing function
|
||
result = 'null';
|
||
}
|
||
|
||
return result;
|
||
};
|
||
|
||
function in_array(what, arr) {
|
||
return arr.indexOf(what) !== -1;
|
||
}
|
||
|
||
function TagFrame(parent, parser_token, indent_level) {
|
||
this.parent = parent || null;
|
||
this.tag = parser_token ? parser_token.tag_name : '';
|
||
this.indent_level = indent_level || 0;
|
||
this.parser_token = parser_token || null;
|
||
}
|
||
|
||
function TagStack(printer) {
|
||
this._printer = printer;
|
||
this._current_frame = null;
|
||
}
|
||
|
||
TagStack.prototype.get_parser_token = function() {
|
||
return this._current_frame ? this._current_frame.parser_token : null;
|
||
};
|
||
|
||
TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object
|
||
var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
|
||
this._current_frame = new_frame;
|
||
};
|
||
|
||
TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer
|
||
var parser_token = null;
|
||
|
||
if (frame) {
|
||
parser_token = frame.parser_token;
|
||
this._printer.indent_level = frame.indent_level;
|
||
this._current_frame = frame.parent;
|
||
}
|
||
|
||
return parser_token;
|
||
};
|
||
|
||
TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer
|
||
var frame = this._current_frame;
|
||
|
||
while (frame) { //till we reach '' (the initial value);
|
||
if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it
|
||
break;
|
||
} else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
|
||
frame = null;
|
||
break;
|
||
}
|
||
frame = frame.parent;
|
||
}
|
||
|
||
return frame;
|
||
};
|
||
|
||
TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer
|
||
var frame = this._get_frame([tag], stop_list);
|
||
return this._try_pop_frame(frame);
|
||
};
|
||
|
||
TagStack.prototype.indent_to_tag = function(tag_list) {
|
||
var frame = this._get_frame(tag_list);
|
||
if (frame) {
|
||
this._printer.indent_level = frame.indent_level;
|
||
}
|
||
};
|
||
|
||
function Beautifier(source_text, options, js_beautify, css_beautify) {
|
||
//Wrapper function to invoke all the necessary constructors and deal with the output.
|
||
this._source_text = source_text || '';
|
||
options = options || {};
|
||
this._js_beautify = js_beautify;
|
||
this._css_beautify = css_beautify;
|
||
this._tag_stack = null;
|
||
|
||
// Allow the setting of language/file-type specific options
|
||
// with inheritance of overall settings
|
||
var optionHtml = new Options(options, 'html');
|
||
|
||
this._options = optionHtml;
|
||
|
||
this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
|
||
this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
|
||
this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
|
||
this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
|
||
this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
|
||
this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
|
||
}
|
||
|
||
Beautifier.prototype.beautify = function() {
|
||
|
||
// if disabled, return the input unchanged.
|
||
if (this._options.disabled) {
|
||
return this._source_text;
|
||
}
|
||
|
||
var source_text = this._source_text;
|
||
var eol = this._options.eol;
|
||
if (this._options.eol === 'auto') {
|
||
eol = '\n';
|
||
if (source_text && lineBreak.test(source_text)) {
|
||
eol = source_text.match(lineBreak)[0];
|
||
}
|
||
}
|
||
|
||
// HACK: newline parsing inconsistent. This brute force normalizes the input.
|
||
source_text = source_text.replace(allLineBreaks, '\n');
|
||
|
||
var baseIndentString = source_text.match(/^[\t ]*/)[0];
|
||
|
||
var last_token = {
|
||
text: '',
|
||
type: ''
|
||
};
|
||
|
||
var last_tag_token = new TagOpenParserToken();
|
||
|
||
var printer = new Printer(this._options, baseIndentString);
|
||
var tokens = new Tokenizer(source_text, this._options).tokenize();
|
||
|
||
this._tag_stack = new TagStack(printer);
|
||
|
||
var parser_token = null;
|
||
var raw_token = tokens.next();
|
||
while (raw_token.type !== TOKEN.EOF) {
|
||
|
||
if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
|
||
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token);
|
||
last_tag_token = parser_token;
|
||
} else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
|
||
(raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
|
||
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, tokens);
|
||
} else if (raw_token.type === TOKEN.TAG_CLOSE) {
|
||
parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
|
||
} else if (raw_token.type === TOKEN.TEXT) {
|
||
parser_token = this._handle_text(printer, raw_token, last_tag_token);
|
||
} else {
|
||
// This should never happen, but if it does. Print the raw token
|
||
printer.add_raw_token(raw_token);
|
||
}
|
||
|
||
last_token = parser_token;
|
||
|
||
raw_token = tokens.next();
|
||
}
|
||
var sweet_code = printer._output.get_code(eol);
|
||
|
||
return sweet_code;
|
||
};
|
||
|
||
Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
|
||
var parser_token = {
|
||
text: raw_token.text,
|
||
type: raw_token.type
|
||
};
|
||
printer.alignment_size = 0;
|
||
last_tag_token.tag_complete = true;
|
||
|
||
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
|
||
if (last_tag_token.is_unformatted) {
|
||
printer.add_raw_token(raw_token);
|
||
} else {
|
||
if (last_tag_token.tag_start_char === '<') {
|
||
printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
|
||
if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
|
||
printer.print_newline(false);
|
||
}
|
||
}
|
||
printer.print_token(raw_token);
|
||
|
||
}
|
||
|
||
if (last_tag_token.indent_content &&
|
||
!(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
|
||
printer.indent();
|
||
|
||
// only indent once per opened tag
|
||
last_tag_token.indent_content = false;
|
||
}
|
||
|
||
if (!last_tag_token.is_inline_element &&
|
||
!(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
|
||
printer.set_wrap_point();
|
||
}
|
||
|
||
return parser_token;
|
||
};
|
||
|
||
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
|
||
var wrapped = last_tag_token.has_wrapped_attrs;
|
||
var parser_token = {
|
||
text: raw_token.text,
|
||
type: raw_token.type
|
||
};
|
||
|
||
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
|
||
if (last_tag_token.is_unformatted) {
|
||
printer.add_raw_token(raw_token);
|
||
} else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
|
||
// For the insides of handlebars allow newlines or a single space between open and contents
|
||
if (printer.print_preserved_newlines(raw_token)) {
|
||
raw_token.newlines = 0;
|
||
printer.add_raw_token(raw_token);
|
||
} else {
|
||
printer.print_token(raw_token);
|
||
}
|
||
} else {
|
||
if (raw_token.type === TOKEN.ATTRIBUTE) {
|
||
printer.set_space_before_token(true);
|
||
last_tag_token.attr_count += 1;
|
||
} else if (raw_token.type === TOKEN.EQUALS) { //no space before =
|
||
printer.set_space_before_token(false);
|
||
} else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
|
||
printer.set_space_before_token(false);
|
||
}
|
||
|
||
if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
|
||
if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
|
||
printer.traverse_whitespace(raw_token);
|
||
wrapped = wrapped || raw_token.newlines !== 0;
|
||
}
|
||
|
||
|
||
if (this._is_wrap_attributes_force) {
|
||
var force_attr_wrap = last_tag_token.attr_count > 1;
|
||
if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
|
||
var is_only_attribute = true;
|
||
var peek_index = 0;
|
||
var peek_token;
|
||
do {
|
||
peek_token = tokens.peek(peek_index);
|
||
if (peek_token.type === TOKEN.ATTRIBUTE) {
|
||
is_only_attribute = false;
|
||
break;
|
||
}
|
||
peek_index += 1;
|
||
} while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
|
||
|
||
force_attr_wrap = !is_only_attribute;
|
||
}
|
||
|
||
if (force_attr_wrap) {
|
||
printer.print_newline(false);
|
||
wrapped = true;
|
||
}
|
||
}
|
||
}
|
||
printer.print_token(raw_token);
|
||
wrapped = wrapped || printer.previous_token_wrapped();
|
||
last_tag_token.has_wrapped_attrs = wrapped;
|
||
}
|
||
return parser_token;
|
||
};
|
||
|
||
Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
|
||
var parser_token = {
|
||
text: raw_token.text,
|
||
type: 'TK_CONTENT'
|
||
};
|
||
if (last_tag_token.custom_beautifier_name) { //check if we need to format javascript
|
||
this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
|
||
} else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
|
||
printer.add_raw_token(raw_token);
|
||
} else {
|
||
printer.traverse_whitespace(raw_token);
|
||
printer.print_token(raw_token);
|
||
}
|
||
return parser_token;
|
||
};
|
||
|
||
Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
|
||
var local = this;
|
||
if (raw_token.text !== '') {
|
||
|
||
var text = raw_token.text,
|
||
_beautifier,
|
||
script_indent_level = 1,
|
||
pre = '',
|
||
post = '';
|
||
if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
|
||
_beautifier = this._js_beautify;
|
||
} else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
|
||
_beautifier = this._css_beautify;
|
||
} else if (last_tag_token.custom_beautifier_name === 'html') {
|
||
_beautifier = function(html_source, options) {
|
||
var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
|
||
return beautifier.beautify();
|
||
};
|
||
}
|
||
|
||
if (this._options.indent_scripts === "keep") {
|
||
script_indent_level = 0;
|
||
} else if (this._options.indent_scripts === "separate") {
|
||
script_indent_level = -printer.indent_level;
|
||
}
|
||
|
||
var indentation = printer.get_full_indent(script_indent_level);
|
||
|
||
// if there is at least one empty line at the end of this text, strip it
|
||
// we'll be adding one back after the text but before the containing tag.
|
||
text = text.replace(/\n[ \t]*$/, '');
|
||
|
||
// Handle the case where content is wrapped in a comment or cdata.
|
||
if (last_tag_token.custom_beautifier_name !== 'html' &&
|
||
text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
|
||
var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
|
||
|
||
// if we start to wrap but don't finish, print raw
|
||
if (!matched) {
|
||
printer.add_raw_token(raw_token);
|
||
return;
|
||
}
|
||
|
||
pre = indentation + matched[1] + '\n';
|
||
text = matched[4];
|
||
if (matched[5]) {
|
||
post = indentation + matched[5];
|
||
}
|
||
|
||
// if there is at least one empty line at the end of this text, strip it
|
||
// we'll be adding one back after the text but before the containing tag.
|
||
text = text.replace(/\n[ \t]*$/, '');
|
||
|
||
if (matched[2] || matched[3].indexOf('\n') !== -1) {
|
||
// if the first line of the non-comment text has spaces
|
||
// use that as the basis for indenting in null case.
|
||
matched = matched[3].match(/[ \t]+$/);
|
||
if (matched) {
|
||
raw_token.whitespace_before = matched[0];
|
||
}
|
||
}
|
||
}
|
||
|
||
if (text) {
|
||
if (_beautifier) {
|
||
|
||
// call the Beautifier if avaliable
|
||
var Child_options = function() {
|
||
this.eol = '\n';
|
||
};
|
||
Child_options.prototype = this._options.raw_options;
|
||
var child_options = new Child_options();
|
||
text = _beautifier(indentation + text, child_options);
|
||
} else {
|
||
// simply indent the string otherwise
|
||
var white = raw_token.whitespace_before;
|
||
if (white) {
|
||
text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
|
||
}
|
||
|
||
text = indentation + text.replace(/\n/g, '\n' + indentation);
|
||
}
|
||
}
|
||
|
||
if (pre) {
|
||
if (!text) {
|
||
text = pre + post;
|
||
} else {
|
||
text = pre + text + '\n' + post;
|
||
}
|
||
}
|
||
|
||
printer.print_newline(false);
|
||
if (text) {
|
||
raw_token.text = text;
|
||
raw_token.whitespace_before = '';
|
||
raw_token.newlines = 0;
|
||
printer.add_raw_token(raw_token);
|
||
printer.print_newline(true);
|
||
}
|
||
}
|
||
};
|
||
|
||
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
|
||
var parser_token = this._get_tag_open_token(raw_token);
|
||
|
||
if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
|
||
!last_tag_token.is_empty_element &&
|
||
raw_token.type === TOKEN.TAG_OPEN && raw_token.text.indexOf('</') === 0) {
|
||
// End element tags for unformatted or content_unformatted elements
|
||
// are printed raw to keep any newlines inside them exactly the same.
|
||
printer.add_raw_token(raw_token);
|
||
parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
|
||
} else {
|
||
printer.traverse_whitespace(raw_token);
|
||
this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
|
||
if (!parser_token.is_inline_element) {
|
||
printer.set_wrap_point();
|
||
}
|
||
printer.print_token(raw_token);
|
||
}
|
||
|
||
//indent attributes an auto, forced, aligned or forced-align line-wrap
|
||
if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
|
||
parser_token.alignment_size = raw_token.text.length + 1;
|
||
}
|
||
|
||
if (!parser_token.tag_complete && !parser_token.is_unformatted) {
|
||
printer.alignment_size = parser_token.alignment_size;
|
||
}
|
||
|
||
return parser_token;
|
||
};
|
||
|
||
var TagOpenParserToken = function(parent, raw_token) {
|
||
this.parent = parent || null;
|
||
this.text = '';
|
||
this.type = 'TK_TAG_OPEN';
|
||
this.tag_name = '';
|
||
this.is_inline_element = false;
|
||
this.is_unformatted = false;
|
||
this.is_content_unformatted = false;
|
||
this.is_empty_element = false;
|
||
this.is_start_tag = false;
|
||
this.is_end_tag = false;
|
||
this.indent_content = false;
|
||
this.multiline_content = false;
|
||
this.custom_beautifier_name = null;
|
||
this.start_tag_token = null;
|
||
this.attr_count = 0;
|
||
this.has_wrapped_attrs = false;
|
||
this.alignment_size = 0;
|
||
this.tag_complete = false;
|
||
this.tag_start_char = '';
|
||
this.tag_check = '';
|
||
|
||
if (!raw_token) {
|
||
this.tag_complete = true;
|
||
} else {
|
||
var tag_check_match;
|
||
|
||
this.tag_start_char = raw_token.text[0];
|
||
this.text = raw_token.text;
|
||
|
||
if (this.tag_start_char === '<') {
|
||
tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
|
||
this.tag_check = tag_check_match ? tag_check_match[1] : '';
|
||
} else {
|
||
tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
|
||
this.tag_check = tag_check_match ? tag_check_match[1] : '';
|
||
|
||
// handle "{{#> myPartial}}
|
||
if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
|
||
this.tag_check = raw_token.next.text;
|
||
}
|
||
}
|
||
this.tag_check = this.tag_check.toLowerCase();
|
||
|
||
if (raw_token.type === TOKEN.COMMENT) {
|
||
this.tag_complete = true;
|
||
}
|
||
|
||
this.is_start_tag = this.tag_check.charAt(0) !== '/';
|
||
this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
|
||
this.is_end_tag = !this.is_start_tag ||
|
||
(raw_token.closed && raw_token.closed.text === '/>');
|
||
|
||
// handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
|
||
this.is_end_tag = this.is_end_tag ||
|
||
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(2)))));
|
||
}
|
||
};
|
||
|
||
Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
|
||
var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
|
||
|
||
parser_token.alignment_size = this._options.wrap_attributes_indent_size;
|
||
|
||
parser_token.is_end_tag = parser_token.is_end_tag ||
|
||
in_array(parser_token.tag_check, this._options.void_elements);
|
||
|
||
parser_token.is_empty_element = parser_token.tag_complete ||
|
||
(parser_token.is_start_tag && parser_token.is_end_tag);
|
||
|
||
parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
|
||
parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
|
||
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_start_char === '{';
|
||
|
||
return parser_token;
|
||
};
|
||
|
||
Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
|
||
|
||
if (!parser_token.is_empty_element) {
|
||
if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
|
||
parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors
|
||
} else { // it's a start-tag
|
||
// check if this tag is starting an element that has optional end element
|
||
// and do an ending needed
|
||
if (this._do_optional_end_element(parser_token)) {
|
||
if (!parser_token.is_inline_element) {
|
||
printer.print_newline(false);
|
||
}
|
||
}
|
||
|
||
this._tag_stack.record_tag(parser_token); //push it on the tag stack
|
||
|
||
if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
|
||
!(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
|
||
parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line
|
||
printer.print_newline(false);
|
||
if (!printer._output.just_added_blankline()) {
|
||
printer.print_newline(true);
|
||
}
|
||
}
|
||
|
||
if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /)
|
||
|
||
// if you hit an else case, reset the indent level if you are inside an:
|
||
// 'if', 'unless', or 'each' block.
|
||
if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
|
||
this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
|
||
parser_token.indent_content = true;
|
||
// Don't add a newline if opening {{#if}} tag is on the current line
|
||
var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
|
||
if (!foundIfOnCurrentLine) {
|
||
printer.print_newline(false);
|
||
}
|
||
}
|
||
|
||
// Don't add a newline before elements that should remain where they are.
|
||
if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
|
||
last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) {
|
||
//Do nothing. Leave comments on same line.
|
||
} else {
|
||
if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
|
||
printer.print_newline(false);
|
||
}
|
||
this._calcluate_parent_multiline(printer, parser_token);
|
||
}
|
||
} else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
|
||
var do_end_expand = false;
|
||
|
||
// deciding whether a block is multiline should not be this hard
|
||
do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
|
||
do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
|
||
!(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
|
||
!(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
|
||
last_token.type !== 'TK_CONTENT'
|
||
);
|
||
|
||
if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
|
||
do_end_expand = false;
|
||
}
|
||
|
||
if (do_end_expand) {
|
||
printer.print_newline(false);
|
||
}
|
||
} else { // it's a start-tag
|
||
parser_token.indent_content = !parser_token.custom_beautifier_name;
|
||
|
||
if (parser_token.tag_start_char === '<') {
|
||
if (parser_token.tag_name === 'html') {
|
||
parser_token.indent_content = this._options.indent_inner_html;
|
||
} else if (parser_token.tag_name === 'head') {
|
||
parser_token.indent_content = this._options.indent_head_inner_html;
|
||
} else if (parser_token.tag_name === 'body') {
|
||
parser_token.indent_content = this._options.indent_body_inner_html;
|
||
}
|
||
}
|
||
|
||
if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
|
||
(last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
|
||
printer.print_newline(false);
|
||
}
|
||
|
||
this._calcluate_parent_multiline(printer, parser_token);
|
||
}
|
||
};
|
||
|
||
Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
|
||
if (parser_token.parent && printer._output.just_added_newline() &&
|
||
!((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
|
||
parser_token.parent.multiline_content = true;
|
||
}
|
||
};
|
||
|
||
//To be used for <p> tag special case:
|
||
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
|
||
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
|
||
|
||
Beautifier.prototype._do_optional_end_element = function(parser_token) {
|
||
var result = null;
|
||
// NOTE: cases of "if there is no more content in the parent element"
|
||
// are handled automatically by the beautifier.
|
||
// It assumes parent or ancestor close tag closes all children.
|
||
// https://www.w3.org/TR/html5/syntax.html#optional-tags
|
||
if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
|
||
return;
|
||
|
||
}
|
||
|
||
if (parser_token.tag_name === 'body') {
|
||
// A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
|
||
result = result || this._tag_stack.try_pop('head');
|
||
|
||
//} else if (parser_token.tag_name === 'body') {
|
||
// DONE: A body element’s end tag may be omitted if the body element is not immediately followed by a comment.
|
||
|
||
} else if (parser_token.tag_name === 'li') {
|
||
// 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.
|
||
result = result || this._tag_stack.try_pop('li', ['ol', 'ul']);
|
||
|
||
} else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
|
||
// 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.
|
||
// A dt element’s end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.
|
||
result = result || this._tag_stack.try_pop('dt', ['dl']);
|
||
result = result || this._tag_stack.try_pop('dd', ['dl']);
|
||
|
||
|
||
} else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
|
||
// IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
|
||
// 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.
|
||
// To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
|
||
// But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
|
||
var p_parent = parser_token.parent.parent;
|
||
if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
|
||
result = result || this._tag_stack.try_pop('p');
|
||
}
|
||
} else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
|
||
// 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.
|
||
// 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.
|
||
result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
|
||
result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
|
||
|
||
} else if (parser_token.tag_name === 'optgroup') {
|
||
// 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.
|
||
// 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.
|
||
result = result || this._tag_stack.try_pop('optgroup', ['select']);
|
||
//result = result || this._tag_stack.try_pop('option', ['select']);
|
||
|
||
} else if (parser_token.tag_name === 'option') {
|
||
// 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.
|
||
result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
|
||
|
||
} else if (parser_token.tag_name === 'colgroup') {
|
||
// 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.
|
||
// A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
|
||
result = result || this._tag_stack.try_pop('caption', ['table']);
|
||
|
||
} else if (parser_token.tag_name === 'thead') {
|
||
// A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
|
||
// A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
|
||
result = result || this._tag_stack.try_pop('caption', ['table']);
|
||
result = result || this._tag_stack.try_pop('colgroup', ['table']);
|
||
|
||
//} else if (parser_token.tag_name === 'caption') {
|
||
// 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.
|
||
|
||
} else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
|
||
// A thead element’s end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.
|
||
// 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.
|
||
// A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
|
||
// A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
|
||
result = result || this._tag_stack.try_pop('caption', ['table']);
|
||
result = result || this._tag_stack.try_pop('colgroup', ['table']);
|
||
result = result || this._tag_stack.try_pop('thead', ['table']);
|
||
result = result || this._tag_stack.try_pop('tbody', ['table']);
|
||
|
||
//} else if (parser_token.tag_name === 'tfoot') {
|
||
// DONE: A tfoot element’s end tag may be omitted if there is no more content in the parent element.
|
||
|
||
} else if (parser_token.tag_name === 'tr') {
|
||
// 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.
|
||
// A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
|
||
// A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
|
||
result = result || this._tag_stack.try_pop('caption', ['table']);
|
||
result = result || this._tag_stack.try_pop('colgroup', ['table']);
|
||
result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
|
||
|
||
} else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
|
||
// 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.
|
||
// 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.
|
||
result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
|
||
result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
|
||
}
|
||
|
||
// Start element omission not handled currently
|
||
// 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.
|
||
// 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.)
|
||
// 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.)
|
||
|
||
// Fix up the parent of the parser token
|
||
parser_token.parent = this._tag_stack.get_parser_token();
|
||
|
||
return result;
|
||
};
|
||
|
||
module.exports.Beautifier = Beautifier;
|
||
|
||
|
||
/***/ }),
|
||
/* 20 */
|
||
/***/ (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.
|
||
*/
|
||
|
||
|
||
|
||
var BaseOptions = __webpack_require__(6).Options;
|
||
|
||
function Options(options) {
|
||
BaseOptions.call(this, options, 'html');
|
||
if (this.templating.length === 1 && this.templating[0] === 'auto') {
|
||
this.templating = ['django', 'erb', 'handlebars', 'php'];
|
||
}
|
||
|
||
this.indent_inner_html = this._get_boolean('indent_inner_html');
|
||
this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
|
||
this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
|
||
|
||
this.indent_handlebars = this._get_boolean('indent_handlebars', true);
|
||
this.wrap_attributes = this._get_selection('wrap_attributes',
|
||
['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
|
||
this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
|
||
this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
|
||
|
||
// Block vs inline elements
|
||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
||
// https://www.w3.org/TR/html5/dom.html#phrasing-content
|
||
this.inline = this._get_array('inline', [
|
||
'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
|
||
'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
|
||
'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
|
||
'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
|
||
'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
|
||
'video', 'wbr', 'text',
|
||
// obsolete inline tags
|
||
'acronym', 'big', 'strike', 'tt'
|
||
]);
|
||
this.void_elements = this._get_array('void_elements', [
|
||
// HTLM void elements - aka self-closing tags - aka singletons
|
||
// https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
|
||
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
|
||
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
|
||
// NOTE: Optional tags are too complex for a simple list
|
||
// they are hard coded in _do_optional_end_element
|
||
|
||
// Doctype and xml elements
|
||
'!doctype', '?xml',
|
||
|
||
// obsolete tags
|
||
// basefont: https://www.computerhope.com/jargon/h/html-basefont-tag.htm
|
||
// isndex: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex
|
||
'basefont', 'isindex'
|
||
]);
|
||
this.unformatted = this._get_array('unformatted', []);
|
||
this.content_unformatted = this._get_array('content_unformatted', [
|
||
'pre', 'textarea'
|
||
]);
|
||
this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
|
||
this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
|
||
|
||
}
|
||
Options.prototype = new BaseOptions();
|
||
|
||
|
||
|
||
module.exports.Options = Options;
|
||
|
||
|
||
/***/ }),
|
||
/* 21 */
|
||
/***/ (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.
|
||
*/
|
||
|
||
|
||
|
||
var BaseTokenizer = __webpack_require__(9).Tokenizer;
|
||
var BASETOKEN = __webpack_require__(9).TOKEN;
|
||
var Directives = __webpack_require__(13).Directives;
|
||
var TemplatablePattern = __webpack_require__(14).TemplatablePattern;
|
||
var Pattern = __webpack_require__(12).Pattern;
|
||
|
||
var TOKEN = {
|
||
TAG_OPEN: 'TK_TAG_OPEN',
|
||
TAG_CLOSE: 'TK_TAG_CLOSE',
|
||
ATTRIBUTE: 'TK_ATTRIBUTE',
|
||
EQUALS: 'TK_EQUALS',
|
||
VALUE: 'TK_VALUE',
|
||
COMMENT: 'TK_COMMENT',
|
||
TEXT: 'TK_TEXT',
|
||
UNKNOWN: 'TK_UNKNOWN',
|
||
START: BASETOKEN.START,
|
||
RAW: BASETOKEN.RAW,
|
||
EOF: BASETOKEN.EOF
|
||
};
|
||
|
||
var directives_core = new Directives(/<\!--/, /-->/);
|
||
|
||
var Tokenizer = function(input_string, options) {
|
||
BaseTokenizer.call(this, input_string, options);
|
||
this._current_tag_name = '';
|
||
|
||
// Words end at whitespace or when a tag starts
|
||
// if we are indenting handlebars, they are considered tags
|
||
var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
|
||
var pattern_reader = new Pattern(this._input);
|
||
|
||
this.__patterns = {
|
||
word: templatable_reader.until(/[\n\r\t <]/),
|
||
single_quote: templatable_reader.until_after(/'/),
|
||
double_quote: templatable_reader.until_after(/"/),
|
||
attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
|
||
element_name: templatable_reader.until(/[\n\r\t >\/]/),
|
||
|
||
handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
|
||
handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
|
||
handlebars_open: pattern_reader.until(/[\n\r\t }]/),
|
||
handlebars_raw_close: pattern_reader.until(/}}/),
|
||
comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
|
||
cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
|
||
// https://en.wikipedia.org/wiki/Conditional_comment
|
||
conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
|
||
processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
|
||
};
|
||
|
||
if (this._options.indent_handlebars) {
|
||
this.__patterns.word = this.__patterns.word.exclude('handlebars');
|
||
}
|
||
|
||
this._unformatted_content_delimiter = null;
|
||
|
||
if (this._options.unformatted_content_delimiter) {
|
||
var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
|
||
this.__patterns.unformatted_content_delimiter =
|
||
pattern_reader.matching(literal_regexp)
|
||
.until_after(literal_regexp);
|
||
}
|
||
};
|
||
Tokenizer.prototype = new BaseTokenizer();
|
||
|
||
Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
|
||
return false; //current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.UNKNOWN;
|
||
};
|
||
|
||
Tokenizer.prototype._is_opening = function(current_token) {
|
||
return current_token.type === TOKEN.TAG_OPEN;
|
||
};
|
||
|
||
Tokenizer.prototype._is_closing = function(current_token, open_token) {
|
||
return current_token.type === TOKEN.TAG_CLOSE &&
|
||
(open_token && (
|
||
((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
|
||
(current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
|
||
};
|
||
|
||
Tokenizer.prototype._reset = function() {
|
||
this._current_tag_name = '';
|
||
};
|
||
|
||
Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
|
||
var token = null;
|
||
this._readWhitespace();
|
||
var c = this._input.peek();
|
||
|
||
if (c === null) {
|
||
return this._create_token(TOKEN.EOF, '');
|
||
}
|
||
|
||
token = token || this._read_open_handlebars(c, open_token);
|
||
token = token || this._read_attribute(c, previous_token, open_token);
|
||
token = token || this._read_close(c, open_token);
|
||
token = token || this._read_raw_content(c, previous_token, open_token);
|
||
token = token || this._read_content_word(c);
|
||
token = token || this._read_comment_or_cdata(c);
|
||
token = token || this._read_processing(c);
|
||
token = token || this._read_open(c, open_token);
|
||
token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
|
||
|
||
return token;
|
||
};
|
||
|
||
Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
|
||
var token = null;
|
||
var resulting_string = null;
|
||
var directives = null;
|
||
|
||
if (c === '<') {
|
||
var peek1 = this._input.peek(1);
|
||
// We treat all comments as literals, even more than preformatted tags
|
||
// we only look for the appropriate closing marker
|
||
if (peek1 === '!') {
|
||
resulting_string = this.__patterns.comment.read();
|
||
|
||
// only process directive on html comments
|
||
if (resulting_string) {
|
||
directives = directives_core.get_directives(resulting_string);
|
||
if (directives && directives.ignore === 'start') {
|
||
resulting_string += directives_core.readIgnored(this._input);
|
||
}
|
||
} else {
|
||
resulting_string = this.__patterns.cdata.read();
|
||
}
|
||
}
|
||
|
||
if (resulting_string) {
|
||
token = this._create_token(TOKEN.COMMENT, resulting_string);
|
||
token.directives = directives;
|
||
}
|
||
}
|
||
|
||
return token;
|
||
};
|
||
|
||
Tokenizer.prototype._read_processing = function(c) { // jshint unused:false
|
||
var token = null;
|
||
var resulting_string = null;
|
||
var directives = null;
|
||
|
||
if (c === '<') {
|
||
var peek1 = this._input.peek(1);
|
||
if (peek1 === '!' || peek1 === '?') {
|
||
resulting_string = this.__patterns.conditional_comment.read();
|
||
resulting_string = resulting_string || this.__patterns.processing.read();
|
||
}
|
||
|
||
if (resulting_string) {
|
||
token = this._create_token(TOKEN.COMMENT, resulting_string);
|
||
token.directives = directives;
|
||
}
|
||
}
|
||
|
||
return token;
|
||
};
|
||
|
||
Tokenizer.prototype._read_open = function(c, open_token) {
|
||
var resulting_string = null;
|
||
var token = null;
|
||
if (!open_token) {
|
||
if (c === '<') {
|
||
|
||
resulting_string = this._input.next();
|
||
if (this._input.peek() === '/') {
|
||
resulting_string += this._input.next();
|
||
}
|
||
resulting_string += this.__patterns.element_name.read();
|
||
token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
|
||
}
|
||
}
|
||
return token;
|
||
};
|
||
|
||
Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
|
||
var resulting_string = null;
|
||
var token = null;
|
||
if (!open_token) {
|
||
if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
|
||
if (this._input.peek(2) === '!') {
|
||
resulting_string = this.__patterns.handlebars_comment.read();
|
||
resulting_string = resulting_string || this.__patterns.handlebars.read();
|
||
token = this._create_token(TOKEN.COMMENT, resulting_string);
|
||
} else {
|
||
resulting_string = this.__patterns.handlebars_open.read();
|
||
token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
|
||
}
|
||
}
|
||
}
|
||
return token;
|
||
};
|
||
|
||
|
||
Tokenizer.prototype._read_close = function(c, open_token) {
|
||
var resulting_string = null;
|
||
var token = null;
|
||
if (open_token) {
|
||
if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
|
||
resulting_string = this._input.next();
|
||
if (c === '/') { // for close tag "/>"
|
||
resulting_string += this._input.next();
|
||
}
|
||
token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
|
||
} else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
|
||
this._input.next();
|
||
this._input.next();
|
||
token = this._create_token(TOKEN.TAG_CLOSE, '}}');
|
||
}
|
||
}
|
||
|
||
return token;
|
||
};
|
||
|
||
Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
|
||
var token = null;
|
||
var resulting_string = '';
|
||
if (open_token && open_token.text[0] === '<') {
|
||
|
||
if (c === '=') {
|
||
token = this._create_token(TOKEN.EQUALS, this._input.next());
|
||
} else if (c === '"' || c === "'") {
|
||
var content = this._input.next();
|
||
if (c === '"') {
|
||
content += this.__patterns.double_quote.read();
|
||
} else {
|
||
content += this.__patterns.single_quote.read();
|
||
}
|
||
token = this._create_token(TOKEN.VALUE, content);
|
||
} else {
|
||
resulting_string = this.__patterns.attribute.read();
|
||
|
||
if (resulting_string) {
|
||
if (previous_token.type === TOKEN.EQUALS) {
|
||
token = this._create_token(TOKEN.VALUE, resulting_string);
|
||
} else {
|
||
token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return token;
|
||
};
|
||
|
||
Tokenizer.prototype._is_content_unformatted = function(tag_name) {
|
||
// void_elements have no content and so cannot have unformatted content
|
||
// script and style tags should always be read as unformatted content
|
||
// finally content_unformatted and unformatted element contents are unformatted
|
||
return this._options.void_elements.indexOf(tag_name) === -1 &&
|
||
(this._options.content_unformatted.indexOf(tag_name) !== -1 ||
|
||
this._options.unformatted.indexOf(tag_name) !== -1);
|
||
};
|
||
|
||
|
||
Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
|
||
var resulting_string = '';
|
||
if (open_token && open_token.text[0] === '{') {
|
||
resulting_string = this.__patterns.handlebars_raw_close.read();
|
||
} else if (previous_token.type === TOKEN.TAG_CLOSE &&
|
||
previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
|
||
// ^^ empty tag has no content
|
||
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
|
||
if (tag_name === 'script' || tag_name === 'style') {
|
||
// Script and style tags are allowed to have comments wrapping their content
|
||
// or just have regular content.
|
||
var token = this._read_comment_or_cdata(c);
|
||
if (token) {
|
||
token.type = TOKEN.TEXT;
|
||
return token;
|
||
}
|
||
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
|
||
} else if (this._is_content_unformatted(tag_name)) {
|
||
|
||
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
|
||
}
|
||
}
|
||
|
||
if (resulting_string) {
|
||
return this._create_token(TOKEN.TEXT, resulting_string);
|
||
}
|
||
|
||
return null;
|
||
};
|
||
|
||
Tokenizer.prototype._read_content_word = function(c) {
|
||
var resulting_string = '';
|
||
if (this._options.unformatted_content_delimiter) {
|
||
if (c === this._options.unformatted_content_delimiter[0]) {
|
||
resulting_string = this.__patterns.unformatted_content_delimiter.read();
|
||
}
|
||
}
|
||
|
||
if (!resulting_string) {
|
||
resulting_string = this.__patterns.word.read();
|
||
}
|
||
if (resulting_string) {
|
||
return this._create_token(TOKEN.TEXT, resulting_string);
|
||
}
|
||
};
|
||
|
||
module.exports.Tokenizer = Tokenizer;
|
||
module.exports.TOKEN = TOKEN;
|
||
|
||
|
||
/***/ })
|
||
/******/ ]);
|
||
/************************************************************************/
|
||
/******/ // The module cache
|
||
/******/ var __webpack_module_cache__ = {};
|
||
/******/
|
||
/******/ // The require function
|
||
/******/ function __webpack_require__(moduleId) {
|
||
/******/ // Check if module is in cache
|
||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||
/******/ if (cachedModule !== undefined) {
|
||
/******/ return cachedModule.exports;
|
||
/******/ }
|
||
/******/ // Create a new module (and put it into the cache)
|
||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||
/******/ // no module.id needed
|
||
/******/ // no module.loaded needed
|
||
/******/ exports: {}
|
||
/******/ };
|
||
/******/
|
||
/******/ // Execute the module function
|
||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||
/******/
|
||
/******/ // Return the exports of the module
|
||
/******/ return module.exports;
|
||
/******/ }
|
||
/******/
|
||
/************************************************************************/
|
||
/******/
|
||
/******/ // startup
|
||
/******/ // Load entry module and return exports
|
||
/******/ // This entry module is referenced by other modules so it can't be inlined
|
||
/******/ var __webpack_exports__ = __webpack_require__(18);
|
||
/******/ legacy_beautify_html = __webpack_exports__;
|
||
/******/
|
||
/******/ })()
|
||
;
|
||
var style_html = legacy_beautify_html;
|
||
/* Footer */
|
||
if (typeof define === "function" && define.amd) {
|
||
// Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
|
||
define(["require", "./beautify", "./beautify-css"], function(requireamd) {
|
||
var js_beautify = requireamd("./beautify");
|
||
var css_beautify = requireamd("./beautify-css");
|
||
|
||
return {
|
||
html_beautify: function(html_source, options) {
|
||
return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
|
||
}
|
||
};
|
||
});
|
||
} else if (typeof exports !== "undefined") {
|
||
// Add support for CommonJS. Just put this file somewhere on your require.paths
|
||
// and you will be able to `var html_beautify = require("beautify").html_beautify`.
|
||
var js_beautify = require('./beautify.js');
|
||
var css_beautify = require('./beautify-css.js');
|
||
|
||
exports.html_beautify = function(html_source, options) {
|
||
return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
|
||
};
|
||
} else if (typeof window !== "undefined") {
|
||
// If we're running a web page and don't have either of the above, add our one global
|
||
window.html_beautify = function(html_source, options) {
|
||
return style_html(html_source, options, window.js_beautify, window.css_beautify);
|
||
};
|
||
} else if (typeof global !== "undefined") {
|
||
// If we don't even have window, try global.
|
||
global.html_beautify = function(html_source, options) {
|
||
return style_html(html_source, options, global.js_beautify, global.css_beautify);
|
||
};
|
||
}
|
||
|
||
}());
|