chore: update dependencies

This commit is contained in:
grandeljay 2023-08-17 11:47:40 +02:00
parent 0f47bca189
commit 6d20c0b45a
3066 changed files with 359185 additions and 427821 deletions

20
node_modules/js-beautify/README.md generated vendored
View file

@ -58,13 +58,13 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
To pull the latest version from one of these services include one set of the script tags below in your document:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-html.min.js"></script>
```
Example usage of a JS tag in html:
@ -76,7 +76,7 @@ Example usage of a JS tag in html:
. . .
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.min.js"></script>
<script src="script.js"></script>
</body>
</html>
@ -141,7 +141,7 @@ To use `js-beautify` as a `node` library (after install locally), import and cal
The configuration option names are the same as the CLI names but with underscores instead of dashes. For example, `--indent-size 2 --space-in-empty-paren` would be `{ indent_size: 2, space_in_empty_paren: true }`.
```js
var beautify = require('js-beautify').js,
var beautify = require('js-beautify/js').js,
fs = require('fs');
fs.readFile('foo.js', 'utf8', function (err, data) {
@ -368,8 +368,10 @@ HTML Beautifier Options:
-S, --indent-scripts [keep|separate|normal] ["normal"]
-w, --wrap-line-length Maximum characters per line (0 disables) [250]
-A, --wrap-attributes Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]
-M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]
-i, --wrap-attributes-indent-size Indent wrapped attributes to after N characters [indent-size] (ignored if wrap-attributes is "aligned")
-d, --inline List of tags to be considered inline tags
--inline_custom_elements Inline custom elements [true]
-U, --unformatted List of tags (defaults to inline) that should not be reformatted
-T, --content_unformatted List of tags (defaults to pre) whose content should not be reformatted
-E, --extra_liners List of tags (defaults to [head,body,/html] that should have an extra newline before them.
@ -432,4 +434,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
Mathias Bynens, Vittorio Gambaletta and others.
(README.md: js-beautify@1.14.7)
(README.md: js-beautify@1.14.9)

View file

@ -879,7 +879,7 @@ Beautifier.prototype.handle_start_block = function(current_token) {
}
}
if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
if (this._flags.last_token.type === TOKEN.START_BLOCK && !this._flags.inline_frame) {
if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
this.print_newline();
} else {
this._output.space_before_token = true;
@ -2605,6 +2605,7 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
token = token || this._read_non_javascript(c);
token = token || this._read_string(c);
token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
token = token || this._read_word(previous_token);
token = token || this._read_singles(c);
token = token || this._read_comment(c);
@ -2663,6 +2664,19 @@ Tokenizer.prototype._read_singles = function(c) {
return token;
};
Tokenizer.prototype._read_pair = function(c, d) {
var token = null;
if (c === '#' && d === '{') {
token = this._create_token(TOKEN.START_BLOCK, c + d);
}
if (token) {
this._input.next();
this._input.next();
}
return token;
};
Tokenizer.prototype._read_punctuation = function() {
var resulting_string = this.__patterns.punct.read();
@ -4037,18 +4051,18 @@ function Beautifier(source_text, options) {
// https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
this.NESTED_AT_RULE = {
"@page": true,
"@font-face": true,
"@keyframes": true,
"page": true,
"font-face": true,
"keyframes": true,
// also in CONDITIONAL_GROUP_RULE below
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.CONDITIONAL_GROUP_RULE = {
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template-areas",
@ -4176,8 +4190,7 @@ Beautifier.prototype.beautify = function() {
// label { content: blue }
var insidePropertyValue = false;
var enteringConditionalGroup = false;
var insideAtExtend = false;
var insideAtImport = false;
var insideNonNestedAtRule = false;
var insideScssMap = false;
var topCharacter = this._ch;
var insideNonSemiColonValues = false;
@ -4232,10 +4245,32 @@ Beautifier.prototype.beautify = function() {
// Ensures any new lines following the comment are preserved
this.eatWhitespace(true);
} else if (this._ch === '@' || this._ch === '$') {
} else if (this._ch === '$') {
this.preserveSingleSpace(isAfterSpace);
// deal with less propery mixins @{...}
this.print_string(this._ch);
// strip trailing space, if present, for hash property checks
var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
if (variable.match(/[ :]$/)) {
// we have a variable or pseudo-class, add it and insert one space before continuing
variable = this.eatString(": ").replace(/\s$/, '');
this.print_string(variable);
this._output.space_before_token = true;
}
variable = variable.replace(/\s$/, '');
// might be sass variable
if (parenLevel === 0 && variable.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
}
} else if (this._ch === '@') {
this.preserveSingleSpace(isAfterSpace);
// deal with less property mixins @{...}
if (this._input.peek() === '{') {
this.print_string(this._ch + this.eatString('}'));
} else {
@ -4253,22 +4288,21 @@ Beautifier.prototype.beautify = function() {
variableOrRule = variableOrRule.replace(/\s$/, '');
if (variableOrRule === 'extend') {
insideAtExtend = true;
} else if (variableOrRule === 'import') {
insideAtImport = true;
}
// might be less variable
if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a nesting at-rule
if (variableOrRule in this.NESTED_AT_RULE) {
// might be a nesting at-rule
} else if (variableOrRule in this.NESTED_AT_RULE) {
this._nestedLevel += 1;
if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
enteringConditionalGroup = true;
}
// might be less variable
} else if (!insideRule && parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a non-nested at-rule
} else if (parenLevel === 0 && !insidePropertyValue) {
insideNonNestedAtRule = true;
}
}
} else if (this._ch === '#' && this._input.peek() === '{') {
@ -4280,6 +4314,9 @@ Beautifier.prototype.beautify = function() {
this.outdent();
}
// non nested at rule becomes nested
insideNonNestedAtRule = false;
// when entering conditional groups, only rulesets are allowed
if (enteringConditionalGroup) {
enteringConditionalGroup = false;
@ -4320,8 +4357,7 @@ Beautifier.prototype.beautify = function() {
if (previous_ch === '{') {
this._output.trim(true);
}
insideAtImport = false;
insideAtExtend = false;
if (insidePropertyValue) {
this.outdent();
insidePropertyValue = false;
@ -4355,9 +4391,10 @@ Beautifier.prototype.beautify = function() {
}
}
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
// 'property: value' delimiter
// which could be in a conditional group query
this.print_string(':');
if (!insidePropertyValue) {
insidePropertyValue = true;
@ -4394,8 +4431,7 @@ Beautifier.prototype.beautify = function() {
this.outdent();
insidePropertyValue = false;
}
insideAtExtend = false;
insideAtImport = false;
insideNonNestedAtRule = false;
this.print_string(this._ch);
this.eatWhitespace(true);
@ -4460,7 +4496,7 @@ Beautifier.prototype.beautify = function() {
} else if (this._ch === ',') {
this.print_string(this._ch);
this.eatWhitespace(true);
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
this._output.add_new_line();
} else {
this._output.space_before_token = true;
@ -4924,11 +4960,11 @@ Beautifier.prototype.beautify = function() {
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);
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
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);
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
} 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) {
@ -4985,7 +5021,7 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
return parser_token;
};
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
var wrapped = last_tag_token.has_wrapped_attrs;
var parser_token = {
text: raw_token.text,
@ -5006,7 +5042,6 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
} 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
@ -5019,29 +5054,15 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
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;
}
// Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
// 1. always wrap the second and beyond attributes
// 2. wrap the first attribute only if 'force-expand-multiline' is specified
if (this._is_wrap_attributes_force &&
last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
(last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
this._is_wrap_attributes_force_expand_multiline)) {
printer.print_newline(false);
wrapped = true;
}
}
printer.print_token(raw_token);
@ -5170,12 +5191,12 @@ Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token,
}
};
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
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) {
raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
// 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);
@ -5189,6 +5210,19 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
printer.print_token(raw_token);
}
// count the number of attributes
if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
var peek_index = 0;
var peek_token;
do {
peek_token = tokens.peek(peek_index);
if (peek_token.type === TOKEN.ATTRIBUTE) {
parser_token.attr_count += 1;
}
peek_index += 1;
} while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
}
//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;
@ -5286,7 +5320,7 @@ Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to g
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_name.includes("-") || parser_token.tag_start_char === '{';
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
return parser_token;
};
@ -5393,7 +5427,7 @@ Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_toke
};
//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_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
Beautifier.prototype._do_optional_end_element = function(parser_token) {
@ -5416,7 +5450,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
} else if (parser_token.tag_name === 'li') {
// An li elements 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']);
result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
} else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
// A dd elements 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.
@ -5555,6 +5589,7 @@ function Options(options) {
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_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
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']);
@ -5572,6 +5607,7 @@ function Options(options) {
// obsolete inline tags
'acronym', 'big', 'strike', 'tt'
]);
this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
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

File diff suppressed because one or more lines are too long

View file

@ -1077,18 +1077,18 @@ function Beautifier(source_text, options) {
// https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
this.NESTED_AT_RULE = {
"@page": true,
"@font-face": true,
"@keyframes": true,
"page": true,
"font-face": true,
"keyframes": true,
// also in CONDITIONAL_GROUP_RULE below
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.CONDITIONAL_GROUP_RULE = {
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template-areas",
@ -1216,8 +1216,7 @@ Beautifier.prototype.beautify = function() {
// label { content: blue }
var insidePropertyValue = false;
var enteringConditionalGroup = false;
var insideAtExtend = false;
var insideAtImport = false;
var insideNonNestedAtRule = false;
var insideScssMap = false;
var topCharacter = this._ch;
var insideNonSemiColonValues = false;
@ -1272,10 +1271,32 @@ Beautifier.prototype.beautify = function() {
// Ensures any new lines following the comment are preserved
this.eatWhitespace(true);
} else if (this._ch === '@' || this._ch === '$') {
} else if (this._ch === '$') {
this.preserveSingleSpace(isAfterSpace);
// deal with less propery mixins @{...}
this.print_string(this._ch);
// strip trailing space, if present, for hash property checks
var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
if (variable.match(/[ :]$/)) {
// we have a variable or pseudo-class, add it and insert one space before continuing
variable = this.eatString(": ").replace(/\s$/, '');
this.print_string(variable);
this._output.space_before_token = true;
}
variable = variable.replace(/\s$/, '');
// might be sass variable
if (parenLevel === 0 && variable.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
}
} else if (this._ch === '@') {
this.preserveSingleSpace(isAfterSpace);
// deal with less property mixins @{...}
if (this._input.peek() === '{') {
this.print_string(this._ch + this.eatString('}'));
} else {
@ -1293,22 +1314,21 @@ Beautifier.prototype.beautify = function() {
variableOrRule = variableOrRule.replace(/\s$/, '');
if (variableOrRule === 'extend') {
insideAtExtend = true;
} else if (variableOrRule === 'import') {
insideAtImport = true;
}
// might be less variable
if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a nesting at-rule
if (variableOrRule in this.NESTED_AT_RULE) {
// might be a nesting at-rule
} else if (variableOrRule in this.NESTED_AT_RULE) {
this._nestedLevel += 1;
if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
enteringConditionalGroup = true;
}
// might be less variable
} else if (!insideRule && parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a non-nested at-rule
} else if (parenLevel === 0 && !insidePropertyValue) {
insideNonNestedAtRule = true;
}
}
} else if (this._ch === '#' && this._input.peek() === '{') {
@ -1320,6 +1340,9 @@ Beautifier.prototype.beautify = function() {
this.outdent();
}
// non nested at rule becomes nested
insideNonNestedAtRule = false;
// when entering conditional groups, only rulesets are allowed
if (enteringConditionalGroup) {
enteringConditionalGroup = false;
@ -1360,8 +1383,7 @@ Beautifier.prototype.beautify = function() {
if (previous_ch === '{') {
this._output.trim(true);
}
insideAtImport = false;
insideAtExtend = false;
if (insidePropertyValue) {
this.outdent();
insidePropertyValue = false;
@ -1395,9 +1417,10 @@ Beautifier.prototype.beautify = function() {
}
}
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
// 'property: value' delimiter
// which could be in a conditional group query
this.print_string(':');
if (!insidePropertyValue) {
insidePropertyValue = true;
@ -1434,8 +1457,7 @@ Beautifier.prototype.beautify = function() {
this.outdent();
insidePropertyValue = false;
}
insideAtExtend = false;
insideAtImport = false;
insideNonNestedAtRule = false;
this.print_string(this._ch);
this.eatWhitespace(true);
@ -1500,7 +1522,7 @@ Beautifier.prototype.beautify = function() {
} else if (this._ch === ',') {
this.print_string(this._ch);
this.eatWhitespace(true);
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
this._output.add_new_line();
} else {
this._output.space_before_token = true;

View file

@ -2044,11 +2044,11 @@ Beautifier.prototype.beautify = function() {
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);
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
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);
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
} 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) {
@ -2105,7 +2105,7 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
return parser_token;
};
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
var wrapped = last_tag_token.has_wrapped_attrs;
var parser_token = {
text: raw_token.text,
@ -2126,7 +2126,6 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
} 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
@ -2139,29 +2138,15 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
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;
}
// Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
// 1. always wrap the second and beyond attributes
// 2. wrap the first attribute only if 'force-expand-multiline' is specified
if (this._is_wrap_attributes_force &&
last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
(last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
this._is_wrap_attributes_force_expand_multiline)) {
printer.print_newline(false);
wrapped = true;
}
}
printer.print_token(raw_token);
@ -2290,12 +2275,12 @@ Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token,
}
};
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
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) {
raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
// 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);
@ -2309,6 +2294,19 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
printer.print_token(raw_token);
}
// count the number of attributes
if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
var peek_index = 0;
var peek_token;
do {
peek_token = tokens.peek(peek_index);
if (peek_token.type === TOKEN.ATTRIBUTE) {
parser_token.attr_count += 1;
}
peek_index += 1;
} while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
}
//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;
@ -2406,7 +2404,7 @@ Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to g
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_name.includes("-") || parser_token.tag_start_char === '{';
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
return parser_token;
};
@ -2513,7 +2511,7 @@ Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_toke
};
//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_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
Beautifier.prototype._do_optional_end_element = function(parser_token) {
@ -2536,7 +2534,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
} else if (parser_token.tag_name === 'li') {
// An li elements 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']);
result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
} else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
// A dd elements 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.
@ -2675,6 +2673,7 @@ function Options(options) {
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_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
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']);
@ -2692,6 +2691,7 @@ function Options(options) {
// obsolete inline tags
'acronym', 'big', 'strike', 'tt'
]);
this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
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

View file

@ -59,7 +59,7 @@
} }
space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()",
NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
NOTE: This option is overridden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none" | any of the former + ",preserve-inline"
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.
@ -910,7 +910,7 @@ Beautifier.prototype.handle_start_block = function(current_token) {
}
}
if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
if (this._flags.last_token.type === TOKEN.START_BLOCK && !this._flags.inline_frame) {
if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
this.print_newline();
} else {
this._output.space_before_token = true;
@ -2636,6 +2636,7 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
token = token || this._read_non_javascript(c);
token = token || this._read_string(c);
token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
token = token || this._read_word(previous_token);
token = token || this._read_singles(c);
token = token || this._read_comment(c);
@ -2694,6 +2695,19 @@ Tokenizer.prototype._read_singles = function(c) {
return token;
};
Tokenizer.prototype._read_pair = function(c, d) {
var token = null;
if (c === '#' && d === '{') {
token = this._create_token(TOKEN.START_BLOCK, c + d);
}
if (token) {
this._input.next();
this._input.next();
}
return token;
};
Tokenizer.prototype._read_punctuation = function() {
var resulting_string = this.__patterns.punct.read();

View file

@ -99,6 +99,7 @@ var path = require('path'),
"unescape_strings": Boolean,
"wrap_line_length": Number,
"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"],
"wrap_attributes_min_attrs": Number,
"wrap_attributes_indent_size": Number,
"e4x": Boolean,
"end_with_newline": Boolean,
@ -115,6 +116,7 @@ var path = require('path'),
// HTML-only
"max_char": Number, // obsolete since 1.3.5
"inline": [String, Array],
"inline_custom_elements": [Boolean],
"unformatted": [String, Array],
"content_unformatted": [String, Array],
"indent_inner_html": [Boolean],
@ -163,9 +165,11 @@ var path = require('path'),
"N": ["--newline_between_rules"],
// HTML-only
"A": ["--wrap_attributes"],
"M": ["--wrap_attributes_min_attrs"],
"i": ["--wrap_attributes_indent_size"],
"W": ["--max_char"], // obsolete since 1.3.5
"d": ["--inline"],
// no shorthand for "inline_custom_elements"
"U": ["--unformatted"],
"T": ["--content_unformatted"],
"I": ["--indent_inner_html"],
@ -395,6 +399,7 @@ function usage(err) {
msg.push(' -S, --indent-scripts [keep|separate|normal] ["normal"]');
msg.push(' -w, --wrap-line-length Wrap lines that exceed N characters [0]');
msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]');
msg.push(' -M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]');
msg.push(' -i, --wrap-attributes-indent-size Indent wrapped tags to after N characters [indent-level]');
msg.push(' -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)');
msg.push(' -m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]');

View file

@ -99,6 +99,7 @@ var path = require('path'),
"unescape_strings": Boolean,
"wrap_line_length": Number,
"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"],
"wrap_attributes_min_attrs": Number,
"wrap_attributes_indent_size": Number,
"e4x": Boolean,
"end_with_newline": Boolean,
@ -115,6 +116,7 @@ var path = require('path'),
// HTML-only
"max_char": Number, // obsolete since 1.3.5
"inline": [String, Array],
"inline_custom_elements": [Boolean],
"unformatted": [String, Array],
"content_unformatted": [String, Array],
"indent_inner_html": [Boolean],
@ -163,9 +165,11 @@ var path = require('path'),
"N": ["--newline_between_rules"],
// HTML-only
"A": ["--wrap_attributes"],
"M": ["--wrap_attributes_min_attrs"],
"i": ["--wrap_attributes_indent_size"],
"W": ["--max_char"], // obsolete since 1.3.5
"d": ["--inline"],
// no shorthand for "inline_custom_elements"
"U": ["--unformatted"],
"T": ["--content_unformatted"],
"I": ["--indent_inner_html"],
@ -395,6 +399,7 @@ function usage(err) {
msg.push(' -S, --indent-scripts [keep|separate|normal] ["normal"]');
msg.push(' -w, --wrap-line-length Wrap lines that exceed N characters [0]');
msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]');
msg.push(' -M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]');
msg.push(' -i, --wrap-attributes-indent-size Indent wrapped tags to after N characters [indent-level]');
msg.push(' -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)');
msg.push(' -m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]');

View file

@ -54,18 +54,18 @@ function Beautifier(source_text, options) {
// https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
this.NESTED_AT_RULE = {
"@page": true,
"@font-face": true,
"@keyframes": true,
"page": true,
"font-face": true,
"keyframes": true,
// also in CONDITIONAL_GROUP_RULE below
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.CONDITIONAL_GROUP_RULE = {
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template-areas",
@ -193,8 +193,7 @@ Beautifier.prototype.beautify = function() {
// label { content: blue }
var insidePropertyValue = false;
var enteringConditionalGroup = false;
var insideAtExtend = false;
var insideAtImport = false;
var insideNonNestedAtRule = false;
var insideScssMap = false;
var topCharacter = this._ch;
var insideNonSemiColonValues = false;
@ -249,10 +248,32 @@ Beautifier.prototype.beautify = function() {
// Ensures any new lines following the comment are preserved
this.eatWhitespace(true);
} else if (this._ch === '@' || this._ch === '$') {
} else if (this._ch === '$') {
this.preserveSingleSpace(isAfterSpace);
// deal with less propery mixins @{...}
this.print_string(this._ch);
// strip trailing space, if present, for hash property checks
var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
if (variable.match(/[ :]$/)) {
// we have a variable or pseudo-class, add it and insert one space before continuing
variable = this.eatString(": ").replace(/\s$/, '');
this.print_string(variable);
this._output.space_before_token = true;
}
variable = variable.replace(/\s$/, '');
// might be sass variable
if (parenLevel === 0 && variable.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
}
} else if (this._ch === '@') {
this.preserveSingleSpace(isAfterSpace);
// deal with less property mixins @{...}
if (this._input.peek() === '{') {
this.print_string(this._ch + this.eatString('}'));
} else {
@ -270,22 +291,21 @@ Beautifier.prototype.beautify = function() {
variableOrRule = variableOrRule.replace(/\s$/, '');
if (variableOrRule === 'extend') {
insideAtExtend = true;
} else if (variableOrRule === 'import') {
insideAtImport = true;
}
// might be less variable
if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a nesting at-rule
if (variableOrRule in this.NESTED_AT_RULE) {
// might be a nesting at-rule
} else if (variableOrRule in this.NESTED_AT_RULE) {
this._nestedLevel += 1;
if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
enteringConditionalGroup = true;
}
// might be less variable
} else if (!insideRule && parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a non-nested at-rule
} else if (parenLevel === 0 && !insidePropertyValue) {
insideNonNestedAtRule = true;
}
}
} else if (this._ch === '#' && this._input.peek() === '{') {
@ -297,6 +317,9 @@ Beautifier.prototype.beautify = function() {
this.outdent();
}
// non nested at rule becomes nested
insideNonNestedAtRule = false;
// when entering conditional groups, only rulesets are allowed
if (enteringConditionalGroup) {
enteringConditionalGroup = false;
@ -337,8 +360,7 @@ Beautifier.prototype.beautify = function() {
if (previous_ch === '{') {
this._output.trim(true);
}
insideAtImport = false;
insideAtExtend = false;
if (insidePropertyValue) {
this.outdent();
insidePropertyValue = false;
@ -372,9 +394,10 @@ Beautifier.prototype.beautify = function() {
}
}
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
// 'property: value' delimiter
// which could be in a conditional group query
this.print_string(':');
if (!insidePropertyValue) {
insidePropertyValue = true;
@ -411,8 +434,7 @@ Beautifier.prototype.beautify = function() {
this.outdent();
insidePropertyValue = false;
}
insideAtExtend = false;
insideAtImport = false;
insideNonNestedAtRule = false;
this.print_string(this._ch);
this.eatWhitespace(true);
@ -477,7 +499,7 @@ Beautifier.prototype.beautify = function() {
} else if (this._ch === ',') {
this.print_string(this._ch);
this.eatWhitespace(true);
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
this._output.add_new_line();
} else {
this._output.space_before_token = true;

View file

@ -296,11 +296,11 @@ Beautifier.prototype.beautify = function() {
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);
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
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);
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
} 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) {
@ -357,7 +357,7 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
return parser_token;
};
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
var wrapped = last_tag_token.has_wrapped_attrs;
var parser_token = {
text: raw_token.text,
@ -378,7 +378,6 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
} 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
@ -391,29 +390,15 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
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;
}
// Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
// 1. always wrap the second and beyond attributes
// 2. wrap the first attribute only if 'force-expand-multiline' is specified
if (this._is_wrap_attributes_force &&
last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
(last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
this._is_wrap_attributes_force_expand_multiline)) {
printer.print_newline(false);
wrapped = true;
}
}
printer.print_token(raw_token);
@ -542,12 +527,12 @@ Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token,
}
};
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
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) {
raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
// 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);
@ -561,6 +546,19 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
printer.print_token(raw_token);
}
// count the number of attributes
if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
var peek_index = 0;
var peek_token;
do {
peek_token = tokens.peek(peek_index);
if (peek_token.type === TOKEN.ATTRIBUTE) {
parser_token.attr_count += 1;
}
peek_index += 1;
} while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
}
//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;
@ -658,7 +656,7 @@ Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to g
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_name.includes("-") || parser_token.tag_start_char === '{';
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
return parser_token;
};
@ -765,7 +763,7 @@ Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_toke
};
//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_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
Beautifier.prototype._do_optional_end_element = function(parser_token) {
@ -788,7 +786,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
} else if (parser_token.tag_name === 'li') {
// An li elements 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']);
result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
} else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
// A dd elements 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.

View file

@ -43,6 +43,7 @@ function Options(options) {
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_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
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']);
@ -60,6 +61,7 @@ function Options(options) {
// obsolete inline tags
'acronym', 'big', 'strike', 'tt'
]);
this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
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

View file

@ -765,7 +765,7 @@ Beautifier.prototype.handle_start_block = function(current_token) {
}
}
if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
if (this._flags.last_token.type === TOKEN.START_BLOCK && !this._flags.inline_frame) {
if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
this.print_newline();
} else {
this._output.space_before_token = true;

View file

@ -167,6 +167,7 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
token = token || this._read_non_javascript(c);
token = token || this._read_string(c);
token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
token = token || this._read_word(previous_token);
token = token || this._read_singles(c);
token = token || this._read_comment(c);
@ -225,6 +226,19 @@ Tokenizer.prototype._read_singles = function(c) {
return token;
};
Tokenizer.prototype._read_pair = function(c, d) {
var token = null;
if (c === '#' && d === '{') {
token = this._create_token(TOKEN.START_BLOCK, c + d);
}
if (token) {
this._input.next();
this._input.next();
}
return token;
};
Tokenizer.prototype._read_punctuation = function() {
var resulting_string = this.__patterns.punct.read();

View file

@ -1,2 +0,0 @@
tidelift: "npm/brace-expansion"
patreon: juliangruber

View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
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.

View file

@ -1,135 +0,0 @@
# brace-expansion
[Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
as known from sh/bash, in JavaScript.
[![build status](https://secure.travis-ci.org/juliangruber/brace-expansion.svg)](http://travis-ci.org/juliangruber/brace-expansion)
[![downloads](https://img.shields.io/npm/dm/brace-expansion.svg)](https://www.npmjs.org/package/brace-expansion)
[![Greenkeeper badge](https://badges.greenkeeper.io/juliangruber/brace-expansion.svg)](https://greenkeeper.io/)
[![testling badge](https://ci.testling.com/juliangruber/brace-expansion.png)](https://ci.testling.com/juliangruber/brace-expansion)
## Example
```js
var expand = require('brace-expansion');
expand('file-{a,b,c}.jpg')
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
expand('-v{,,}')
// => ['-v', '-v', '-v']
expand('file{0..2}.jpg')
// => ['file0.jpg', 'file1.jpg', 'file2.jpg']
expand('file-{a..c}.jpg')
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
expand('file{2..0}.jpg')
// => ['file2.jpg', 'file1.jpg', 'file0.jpg']
expand('file{0..4..2}.jpg')
// => ['file0.jpg', 'file2.jpg', 'file4.jpg']
expand('file-{a..e..2}.jpg')
// => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']
expand('file{00..10..5}.jpg')
// => ['file00.jpg', 'file05.jpg', 'file10.jpg']
expand('{{A..C},{a..c}}')
// => ['A', 'B', 'C', 'a', 'b', 'c']
expand('ppp{,config,oe{,conf}}')
// => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']
```
## API
```js
var expand = require('brace-expansion');
```
### var expanded = expand(str)
Return an array of all possible and valid expansions of `str`. If none are
found, `[str]` is returned.
Valid expansions are:
```js
/^(.*,)+(.+)?$/
// {a,b,...}
```
A comma separated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.
```js
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
// {x..y[..incr]}
```
A numeric sequence from `x` to `y` inclusive, with optional increment.
If `x` or `y` start with a leading `0`, all the numbers will be padded
to have equal length. Negative numbers and backwards iteration work too.
```js
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
// {x..y[..incr]}
```
An alphabetic sequence from `x` to `y` inclusive, with optional increment.
`x` and `y` must be exactly one character, and if given, `incr` must be a
number.
For compatibility reasons, the string `${` is not eligible for brace expansion.
## Installation
With [npm](https://npmjs.org) do:
```bash
npm install brace-expansion
```
## Contributors
- [Julian Gruber](https://github.com/juliangruber)
- [Isaac Z. Schlueter](https://github.com/isaacs)
## Sponsors
This module is proudly supported by my [Sponsors](https://github.com/juliangruber/sponsors)!
Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my [Patreon](https://www.patreon.com/juliangruber). Not sure how much of my modules you're using? Try [feross/thanks](https://github.com/feross/thanks)!
## Security contact information
To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.
## License
(MIT)
Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
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.

View file

@ -1,203 +0,0 @@
var balanced = require('balanced-match');
module.exports = expandTop;
var escSlash = '\0SLASH'+Math.random()+'\0';
var escOpen = '\0OPEN'+Math.random()+'\0';
var escClose = '\0CLOSE'+Math.random()+'\0';
var escComma = '\0COMMA'+Math.random()+'\0';
var escPeriod = '\0PERIOD'+Math.random()+'\0';
function numeric(str) {
return parseInt(str, 10) == str
? parseInt(str, 10)
: str.charCodeAt(0);
}
function escapeBraces(str) {
return str.split('\\\\').join(escSlash)
.split('\\{').join(escOpen)
.split('\\}').join(escClose)
.split('\\,').join(escComma)
.split('\\.').join(escPeriod);
}
function unescapeBraces(str) {
return str.split(escSlash).join('\\')
.split(escOpen).join('{')
.split(escClose).join('}')
.split(escComma).join(',')
.split(escPeriod).join('.');
}
// Basically just str.split(","), but handling cases
// where we have nested braced sections, which should be
// treated as individual members, like {a,{b,c},d}
function parseCommaParts(str) {
if (!str)
return [''];
var parts = [];
var m = balanced('{', '}', str);
if (!m)
return str.split(',');
var pre = m.pre;
var body = m.body;
var post = m.post;
var p = pre.split(',');
p[p.length-1] += '{' + body + '}';
var postParts = parseCommaParts(post);
if (post.length) {
p[p.length-1] += postParts.shift();
p.push.apply(p, postParts);
}
parts.push.apply(parts, p);
return parts;
}
function expandTop(str) {
if (!str)
return [];
// I don't know why Bash 4.3 does this, but it does.
// Anything starting with {} will have the first two bytes preserved
// but *only* at the top level, so {},a}b will not expand to anything,
// but a{},b}c will be expanded to [a}c,abc].
// One could argue that this is a bug in Bash, but since the goal of
// this module is to match Bash's rules, we escape a leading {}
if (str.substr(0, 2) === '{}') {
str = '\\{\\}' + str.substr(2);
}
return expand(escapeBraces(str), true).map(unescapeBraces);
}
function embrace(str) {
return '{' + str + '}';
}
function isPadded(el) {
return /^-?0\d/.test(el);
}
function lte(i, y) {
return i <= y;
}
function gte(i, y) {
return i >= y;
}
function expand(str, isTop) {
var expansions = [];
var m = balanced('{', '}', str);
if (!m) return [str];
// no need to expand pre, since it is guaranteed to be free of brace-sets
var pre = m.pre;
var post = m.post.length
? expand(m.post, false)
: [''];
if (/\$$/.test(m.pre)) {
for (var k = 0; k < post.length; k++) {
var expansion = pre+ '{' + m.body + '}' + post[k];
expansions.push(expansion);
}
} else {
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
var isSequence = isNumericSequence || isAlphaSequence;
var isOptions = m.body.indexOf(',') >= 0;
if (!isSequence && !isOptions) {
// {a},b}
if (m.post.match(/,.*\}/)) {
str = m.pre + '{' + m.body + escClose + m.post;
return expand(str);
}
return [str];
}
var n;
if (isSequence) {
n = m.body.split(/\.\./);
} else {
n = parseCommaParts(m.body);
if (n.length === 1) {
// x{{a,b}}y ==> x{a}y x{b}y
n = expand(n[0], false).map(embrace);
if (n.length === 1) {
return post.map(function(p) {
return m.pre + n[0] + p;
});
}
}
}
// at this point, n is the parts, and we know it's not a comma set
// with a single entry.
var N;
if (isSequence) {
var x = numeric(n[0]);
var y = numeric(n[1]);
var width = Math.max(n[0].length, n[1].length)
var incr = n.length == 3
? Math.abs(numeric(n[2]))
: 1;
var test = lte;
var reverse = y < x;
if (reverse) {
incr *= -1;
test = gte;
}
var pad = n.some(isPadded);
N = [];
for (var i = x; test(i, y); i += incr) {
var c;
if (isAlphaSequence) {
c = String.fromCharCode(i);
if (c === '\\')
c = '';
} else {
c = String(i);
if (pad) {
var need = width - c.length;
if (need > 0) {
var z = new Array(need + 1).join('0');
if (i < 0)
c = '-' + z + c.slice(1);
else
c = z + c;
}
}
}
N.push(c);
}
} else {
N = [];
for (var j = 0; j < n.length; j++) {
N.push.apply(N, expand(n[j], false));
}
}
for (var j = 0; j < N.length; j++) {
for (var k = 0; k < post.length; k++) {
var expansion = pre + N[j] + post[k];
if (!isTop || isSequence || expansion)
expansions.push(expansion);
}
}
}
return expansions;
}

View file

@ -1,46 +0,0 @@
{
"name": "brace-expansion",
"description": "Brace expansion as known from sh/bash",
"version": "2.0.1",
"repository": {
"type": "git",
"url": "git://github.com/juliangruber/brace-expansion.git"
},
"homepage": "https://github.com/juliangruber/brace-expansion",
"main": "index.js",
"scripts": {
"test": "tape test/*.js",
"gentest": "bash test/generate.sh",
"bench": "matcha test/perf/bench.js"
},
"dependencies": {
"balanced-match": "^1.0.0"
},
"devDependencies": {
"@c4312/matcha": "^1.3.1",
"tape": "^4.6.0"
},
"keywords": [],
"author": {
"name": "Julian Gruber",
"email": "mail@juliangruber.com",
"url": "http://juliangruber.com"
},
"license": "MIT",
"testling": {
"files": "test/*.js",
"browsers": [
"ie/8..latest",
"firefox/20..latest",
"firefox/nightly",
"chrome/25..latest",
"chrome/canary",
"opera/12..latest",
"opera/next",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
}
}

View file

@ -1,6 +1,6 @@
{
"name": "js-beautify",
"version": "1.14.7",
"version": "1.14.9",
"description": "beautifier.io for node",
"main": "js/index.js",
"bin": {
@ -45,28 +45,28 @@
],
"license": "MIT",
"engines": {
"node": ">=10"
"node": ">=12"
},
"browserslist": "ie 11",
"dependencies": {
"config-chain": "^1.1.13",
"editorconfig": "^0.15.3",
"glob": "^8.0.3",
"editorconfig": "^1.0.3",
"glob": "^8.1.0",
"nopt": "^6.0.0"
},
"devDependencies": {
"ansi-regex": "^6.0.1",
"benchmark": "^2.1.4",
"codemirror": "^5.65.2",
"jquery": "^3.6.0",
"jshint": "^2.13.4",
"minimist": "^1.2.6",
"mocha": "^10.0.0",
"codemirror": "^5.65.13",
"jquery": "^3.6.4",
"jshint": "^2.13.6",
"minimist": "^1.2.8",
"mocha": "^10.2.0",
"mustache": "^4.2.0",
"requirejs": "^2.3.6",
"serve": "^14.0.1",
"serve": "^14.2.0",
"strip-ansi": "^7.0.1",
"webpack": "^5.74.0",
"webpack": "^5.81.0",
"webpack-cli": "^4.10.0"
}
}