@bmewburn/js-beautify 1.14.7 → 1.14.9-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -9
- package/js/src/cli.js +10 -3
- package/js/src/css/beautifier.js +51 -33
- package/js/src/html/beautifier.js +28 -30
- package/js/src/html/options.js +2 -0
- package/js/src/javascript/acorn.js +4 -3
- package/js/src/javascript/beautifier.js +9 -1
- package/js/src/javascript/tokenizer.js +6 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -58,13 +58,13 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
|
|
|
58
58
|
|
|
59
59
|
To pull the latest version from one of these services include one set of the script tags below in your document:
|
|
60
60
|
```html
|
|
61
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.
|
|
62
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.
|
|
63
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.
|
|
61
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.js"></script>
|
|
62
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-css.js"></script>
|
|
63
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-html.js"></script>
|
|
64
64
|
|
|
65
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.
|
|
66
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.
|
|
67
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.
|
|
65
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.min.js"></script>
|
|
66
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-css.min.js"></script>
|
|
67
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-html.min.js"></script>
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Example usage of a JS tag in html:
|
|
@@ -76,7 +76,7 @@ Example usage of a JS tag in html:
|
|
|
76
76
|
|
|
77
77
|
. . .
|
|
78
78
|
|
|
79
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.
|
|
79
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.min.js"></script>
|
|
80
80
|
<script src="script.js"></script>
|
|
81
81
|
</body>
|
|
82
82
|
</html>
|
|
@@ -141,7 +141,7 @@ To use `js-beautify` as a `node` library (after install locally), import and cal
|
|
|
141
141
|
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 }`.
|
|
142
142
|
|
|
143
143
|
```js
|
|
144
|
-
var beautify = require('js-beautify').js,
|
|
144
|
+
var beautify = require('js-beautify/js').js,
|
|
145
145
|
fs = require('fs');
|
|
146
146
|
|
|
147
147
|
fs.readFile('foo.js', 'utf8', function (err, data) {
|
|
@@ -368,8 +368,10 @@ HTML Beautifier Options:
|
|
|
368
368
|
-S, --indent-scripts [keep|separate|normal] ["normal"]
|
|
369
369
|
-w, --wrap-line-length Maximum characters per line (0 disables) [250]
|
|
370
370
|
-A, --wrap-attributes Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]
|
|
371
|
+
-M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]
|
|
371
372
|
-i, --wrap-attributes-indent-size Indent wrapped attributes to after N characters [indent-size] (ignored if wrap-attributes is "aligned")
|
|
372
373
|
-d, --inline List of tags to be considered inline tags
|
|
374
|
+
--inline_custom_elements Inline custom elements [true]
|
|
373
375
|
-U, --unformatted List of tags (defaults to inline) that should not be reformatted
|
|
374
376
|
-T, --content_unformatted List of tags (defaults to pre) whose content should not be reformatted
|
|
375
377
|
-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
|
|
|
432
434
|
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
|
|
433
435
|
Mathias Bynens, Vittorio Gambaletta and others.
|
|
434
436
|
|
|
435
|
-
(README.md: js-beautify@1.14.
|
|
437
|
+
(README.md: js-beautify@1.14.9)
|
package/js/src/cli.js
CHANGED
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
|
|
33
33
|
*/
|
|
34
34
|
/*jshint strict:false */
|
|
35
|
+
/*jshint esversion: 6 */
|
|
36
|
+
|
|
37
|
+
const { globSync } = require('glob');
|
|
35
38
|
|
|
36
39
|
var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
|
|
37
40
|
console.error.apply(console, arguments);
|
|
@@ -41,7 +44,7 @@ var fs = require('fs'),
|
|
|
41
44
|
cc = require('config-chain'),
|
|
42
45
|
beautify = require('../index'),
|
|
43
46
|
nopt = require('nopt'),
|
|
44
|
-
glob = require(
|
|
47
|
+
glob = require("glob");
|
|
45
48
|
|
|
46
49
|
nopt.invalidHandler = function(key, val) {
|
|
47
50
|
throw new Error(key + " was invalid with value \"" + val + "\"");
|
|
@@ -99,6 +102,7 @@ var path = require('path'),
|
|
|
99
102
|
"unescape_strings": Boolean,
|
|
100
103
|
"wrap_line_length": Number,
|
|
101
104
|
"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"],
|
|
105
|
+
"wrap_attributes_min_attrs": Number,
|
|
102
106
|
"wrap_attributes_indent_size": Number,
|
|
103
107
|
"e4x": Boolean,
|
|
104
108
|
"end_with_newline": Boolean,
|
|
@@ -115,6 +119,7 @@ var path = require('path'),
|
|
|
115
119
|
// HTML-only
|
|
116
120
|
"max_char": Number, // obsolete since 1.3.5
|
|
117
121
|
"inline": [String, Array],
|
|
122
|
+
"inline_custom_elements": [Boolean],
|
|
118
123
|
"unformatted": [String, Array],
|
|
119
124
|
"content_unformatted": [String, Array],
|
|
120
125
|
"indent_inner_html": [Boolean],
|
|
@@ -163,9 +168,11 @@ var path = require('path'),
|
|
|
163
168
|
"N": ["--newline_between_rules"],
|
|
164
169
|
// HTML-only
|
|
165
170
|
"A": ["--wrap_attributes"],
|
|
171
|
+
"M": ["--wrap_attributes_min_attrs"],
|
|
166
172
|
"i": ["--wrap_attributes_indent_size"],
|
|
167
173
|
"W": ["--max_char"], // obsolete since 1.3.5
|
|
168
174
|
"d": ["--inline"],
|
|
175
|
+
// no shorthand for "inline_custom_elements"
|
|
169
176
|
"U": ["--unformatted"],
|
|
170
177
|
"T": ["--content_unformatted"],
|
|
171
178
|
"I": ["--indent_inner_html"],
|
|
@@ -395,6 +402,7 @@ function usage(err) {
|
|
|
395
402
|
msg.push(' -S, --indent-scripts [keep|separate|normal] ["normal"]');
|
|
396
403
|
msg.push(' -w, --wrap-line-length Wrap lines that exceed N characters [0]');
|
|
397
404
|
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"]');
|
|
405
|
+
msg.push(' -M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]');
|
|
398
406
|
msg.push(' -i, --wrap-attributes-indent-size Indent wrapped tags to after N characters [indent-level]');
|
|
399
407
|
msg.push(' -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)');
|
|
400
408
|
msg.push(' -m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]');
|
|
@@ -629,8 +637,7 @@ function checkFiles(parsed) {
|
|
|
629
637
|
// Input was a glob
|
|
630
638
|
if (isGlob) {
|
|
631
639
|
hadGlob = true;
|
|
632
|
-
foundFiles =
|
|
633
|
-
sync: true,
|
|
640
|
+
foundFiles = globSync(f, {
|
|
634
641
|
absolute: true,
|
|
635
642
|
ignore: ['**/node_modules/**', '**/.git/**']
|
|
636
643
|
});
|
package/js/src/css/beautifier.js
CHANGED
|
@@ -54,18 +54,18 @@ function Beautifier(source_text, options) {
|
|
|
54
54
|
|
|
55
55
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
|
|
56
56
|
this.NESTED_AT_RULE = {
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
57
|
+
"page": true,
|
|
58
|
+
"font-face": true,
|
|
59
|
+
"keyframes": true,
|
|
60
60
|
// also in CONDITIONAL_GROUP_RULE below
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
61
|
+
"media": true,
|
|
62
|
+
"supports": true,
|
|
63
|
+
"document": true
|
|
64
64
|
};
|
|
65
65
|
this.CONDITIONAL_GROUP_RULE = {
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
66
|
+
"media": true,
|
|
67
|
+
"supports": true,
|
|
68
|
+
"document": true
|
|
69
69
|
};
|
|
70
70
|
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
|
|
71
71
|
"grid-template-areas",
|
|
@@ -193,8 +193,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
193
193
|
// label { content: blue }
|
|
194
194
|
var insidePropertyValue = false;
|
|
195
195
|
var enteringConditionalGroup = false;
|
|
196
|
-
var
|
|
197
|
-
var insideAtImport = false;
|
|
196
|
+
var insideNonNestedAtRule = false;
|
|
198
197
|
var insideScssMap = false;
|
|
199
198
|
var topCharacter = this._ch;
|
|
200
199
|
var insideNonSemiColonValues = false;
|
|
@@ -249,10 +248,30 @@ Beautifier.prototype.beautify = function() {
|
|
|
249
248
|
|
|
250
249
|
// Ensures any new lines following the comment are preserved
|
|
251
250
|
this.eatWhitespace(true);
|
|
252
|
-
} else if (this._ch === '
|
|
251
|
+
} else if (this._ch === '$') {
|
|
253
252
|
this.preserveSingleSpace(isAfterSpace);
|
|
254
253
|
|
|
255
|
-
|
|
254
|
+
this.print_string(this._ch);
|
|
255
|
+
|
|
256
|
+
// strip trailing space, if present, for hash property checks
|
|
257
|
+
var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
|
|
258
|
+
|
|
259
|
+
if (variable.match(/[ :]$/)) {
|
|
260
|
+
// we have a variable or pseudo-class, add it and insert one space before continuing
|
|
261
|
+
variable = this.eatString(": ").replace(/\s+$/, '');
|
|
262
|
+
this.print_string(variable);
|
|
263
|
+
this._output.space_before_token = true;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// might be sass variable
|
|
267
|
+
if (parenLevel === 0 && variable.indexOf(':') !== -1) {
|
|
268
|
+
insidePropertyValue = true;
|
|
269
|
+
this.indent();
|
|
270
|
+
}
|
|
271
|
+
} else if (this._ch === '@') {
|
|
272
|
+
this.preserveSingleSpace(isAfterSpace);
|
|
273
|
+
|
|
274
|
+
// deal with less property mixins @{...}
|
|
256
275
|
if (this._input.peek() === '{') {
|
|
257
276
|
this.print_string(this._ch + this.eatString('}'));
|
|
258
277
|
} else {
|
|
@@ -263,29 +282,26 @@ Beautifier.prototype.beautify = function() {
|
|
|
263
282
|
|
|
264
283
|
if (variableOrRule.match(/[ :]$/)) {
|
|
265
284
|
// we have a variable or pseudo-class, add it and insert one space before continuing
|
|
266
|
-
variableOrRule = this.eatString(": ").replace(/\s
|
|
285
|
+
variableOrRule = this.eatString(": ").replace(/\s+$/, '');
|
|
267
286
|
this.print_string(variableOrRule);
|
|
268
287
|
this._output.space_before_token = true;
|
|
269
288
|
}
|
|
270
289
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
} else if (variableOrRule === 'import') {
|
|
276
|
-
insideAtImport = true;
|
|
277
|
-
}
|
|
290
|
+
// might be less variable
|
|
291
|
+
if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
|
|
292
|
+
insidePropertyValue = true;
|
|
293
|
+
this.indent();
|
|
278
294
|
|
|
279
|
-
|
|
280
|
-
if (variableOrRule in this.NESTED_AT_RULE) {
|
|
295
|
+
// might be a nesting at-rule
|
|
296
|
+
} else if (variableOrRule in this.NESTED_AT_RULE) {
|
|
281
297
|
this._nestedLevel += 1;
|
|
282
298
|
if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
|
|
283
299
|
enteringConditionalGroup = true;
|
|
284
300
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
301
|
+
|
|
302
|
+
// might be a non-nested at-rule
|
|
303
|
+
} else if (parenLevel === 0 && !insidePropertyValue) {
|
|
304
|
+
insideNonNestedAtRule = true;
|
|
289
305
|
}
|
|
290
306
|
}
|
|
291
307
|
} else if (this._ch === '#' && this._input.peek() === '{') {
|
|
@@ -297,6 +313,9 @@ Beautifier.prototype.beautify = function() {
|
|
|
297
313
|
this.outdent();
|
|
298
314
|
}
|
|
299
315
|
|
|
316
|
+
// non nested at rule becomes nested
|
|
317
|
+
insideNonNestedAtRule = false;
|
|
318
|
+
|
|
300
319
|
// when entering conditional groups, only rulesets are allowed
|
|
301
320
|
if (enteringConditionalGroup) {
|
|
302
321
|
enteringConditionalGroup = false;
|
|
@@ -337,8 +356,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
337
356
|
if (previous_ch === '{') {
|
|
338
357
|
this._output.trim(true);
|
|
339
358
|
}
|
|
340
|
-
|
|
341
|
-
insideAtExtend = false;
|
|
359
|
+
|
|
342
360
|
if (insidePropertyValue) {
|
|
343
361
|
this.outdent();
|
|
344
362
|
insidePropertyValue = false;
|
|
@@ -372,9 +390,10 @@ Beautifier.prototype.beautify = function() {
|
|
|
372
390
|
}
|
|
373
391
|
}
|
|
374
392
|
|
|
375
|
-
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !
|
|
393
|
+
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
|
|
376
394
|
// 'property: value' delimiter
|
|
377
395
|
// which could be in a conditional group query
|
|
396
|
+
|
|
378
397
|
this.print_string(':');
|
|
379
398
|
if (!insidePropertyValue) {
|
|
380
399
|
insidePropertyValue = true;
|
|
@@ -411,8 +430,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
411
430
|
this.outdent();
|
|
412
431
|
insidePropertyValue = false;
|
|
413
432
|
}
|
|
414
|
-
|
|
415
|
-
insideAtImport = false;
|
|
433
|
+
insideNonNestedAtRule = false;
|
|
416
434
|
this.print_string(this._ch);
|
|
417
435
|
this.eatWhitespace(true);
|
|
418
436
|
|
|
@@ -477,7 +495,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
477
495
|
} else if (this._ch === ',') {
|
|
478
496
|
this.print_string(this._ch);
|
|
479
497
|
this.eatWhitespace(true);
|
|
480
|
-
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !
|
|
498
|
+
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
|
|
481
499
|
this._output.add_new_line();
|
|
482
500
|
} else {
|
|
483
501
|
this._output.space_before_token = true;
|
|
@@ -297,11 +297,11 @@ Beautifier.prototype.beautify = function() {
|
|
|
297
297
|
while (raw_token.type !== TOKEN.EOF) {
|
|
298
298
|
|
|
299
299
|
if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
|
|
300
|
-
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token);
|
|
300
|
+
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
|
|
301
301
|
last_tag_token = parser_token;
|
|
302
302
|
} else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
|
|
303
303
|
(raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
|
|
304
|
-
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token,
|
|
304
|
+
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
|
|
305
305
|
} else if (raw_token.type === TOKEN.TAG_CLOSE) {
|
|
306
306
|
parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
|
|
307
307
|
} else if (raw_token.type === TOKEN.TEXT) {
|
|
@@ -358,7 +358,7 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
|
|
|
358
358
|
return parser_token;
|
|
359
359
|
};
|
|
360
360
|
|
|
361
|
-
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token,
|
|
361
|
+
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
|
|
362
362
|
var wrapped = last_tag_token.has_wrapped_attrs;
|
|
363
363
|
var parser_token = {
|
|
364
364
|
text: raw_token.text,
|
|
@@ -379,7 +379,6 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
|
|
|
379
379
|
} else {
|
|
380
380
|
if (raw_token.type === TOKEN.ATTRIBUTE) {
|
|
381
381
|
printer.set_space_before_token(true);
|
|
382
|
-
last_tag_token.attr_count += 1;
|
|
383
382
|
} else if (raw_token.type === TOKEN.EQUALS) { //no space before =
|
|
384
383
|
printer.set_space_before_token(false);
|
|
385
384
|
} else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
|
|
@@ -392,29 +391,15 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
|
|
|
392
391
|
wrapped = wrapped || raw_token.newlines !== 0;
|
|
393
392
|
}
|
|
394
393
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
if (peek_token.type === TOKEN.ATTRIBUTE) {
|
|
405
|
-
is_only_attribute = false;
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
peek_index += 1;
|
|
409
|
-
} while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
|
|
410
|
-
|
|
411
|
-
force_attr_wrap = !is_only_attribute;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (force_attr_wrap) {
|
|
415
|
-
printer.print_newline(false);
|
|
416
|
-
wrapped = true;
|
|
417
|
-
}
|
|
394
|
+
// Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
|
|
395
|
+
// 1. always wrap the second and beyond attributes
|
|
396
|
+
// 2. wrap the first attribute only if 'force-expand-multiline' is specified
|
|
397
|
+
if (this._is_wrap_attributes_force &&
|
|
398
|
+
last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
|
|
399
|
+
(last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
|
|
400
|
+
this._is_wrap_attributes_force_expand_multiline)) {
|
|
401
|
+
printer.print_newline(false);
|
|
402
|
+
wrapped = true;
|
|
418
403
|
}
|
|
419
404
|
}
|
|
420
405
|
printer.print_token(raw_token);
|
|
@@ -550,12 +535,12 @@ Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token,
|
|
|
550
535
|
}
|
|
551
536
|
};
|
|
552
537
|
|
|
553
|
-
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
|
|
538
|
+
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
|
|
554
539
|
var parser_token = this._get_tag_open_token(raw_token);
|
|
555
540
|
|
|
556
541
|
if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
|
|
557
542
|
!last_tag_token.is_empty_element &&
|
|
558
|
-
raw_token.type === TOKEN.TAG_OPEN &&
|
|
543
|
+
raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
|
|
559
544
|
// End element tags for unformatted or content_unformatted elements
|
|
560
545
|
// are printed raw to keep any newlines inside them exactly the same.
|
|
561
546
|
printer.add_raw_token(raw_token);
|
|
@@ -569,6 +554,19 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
|
|
|
569
554
|
printer.print_token(raw_token);
|
|
570
555
|
}
|
|
571
556
|
|
|
557
|
+
// count the number of attributes
|
|
558
|
+
if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
|
|
559
|
+
var peek_index = 0;
|
|
560
|
+
var peek_token;
|
|
561
|
+
do {
|
|
562
|
+
peek_token = tokens.peek(peek_index);
|
|
563
|
+
if (peek_token.type === TOKEN.ATTRIBUTE) {
|
|
564
|
+
parser_token.attr_count += 1;
|
|
565
|
+
}
|
|
566
|
+
peek_index += 1;
|
|
567
|
+
} while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
|
|
568
|
+
}
|
|
569
|
+
|
|
572
570
|
//indent attributes an auto, forced, aligned or forced-align line-wrap
|
|
573
571
|
if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
|
|
574
572
|
parser_token.alignment_size = raw_token.text.length + 1;
|
|
@@ -666,7 +664,7 @@ Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to g
|
|
|
666
664
|
|
|
667
665
|
parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
|
|
668
666
|
parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
|
|
669
|
-
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_name.includes("-") || parser_token.tag_start_char === '{';
|
|
667
|
+
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 === '{';
|
|
670
668
|
|
|
671
669
|
return parser_token;
|
|
672
670
|
};
|
package/js/src/html/options.js
CHANGED
|
@@ -43,6 +43,7 @@ function Options(options) {
|
|
|
43
43
|
this.indent_handlebars = this._get_boolean('indent_handlebars', true);
|
|
44
44
|
this.wrap_attributes = this._get_selection('wrap_attributes',
|
|
45
45
|
['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
|
|
46
|
+
this.wrap_attributes_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
|
|
46
47
|
this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
|
|
47
48
|
this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
|
|
48
49
|
|
|
@@ -60,6 +61,7 @@ function Options(options) {
|
|
|
60
61
|
// obsolete inline tags
|
|
61
62
|
'acronym', 'big', 'strike', 'tt'
|
|
62
63
|
]);
|
|
64
|
+
this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
|
|
63
65
|
this.void_elements = this._get_array('void_elements', [
|
|
64
66
|
// HTLM void elements - aka self-closing tags - aka singletons
|
|
65
67
|
// https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
|
|
@@ -35,12 +35,13 @@ var nonASCIIidentifierChars = "\\u0300-\\u036f\\u0483-\\u0487\\u0591-\\u05bd\\u0
|
|
|
35
35
|
//var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
|
36
36
|
//var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
|
37
37
|
|
|
38
|
-
var
|
|
39
|
-
var
|
|
38
|
+
var unicodeEscapeOrCodePoint = "\\\\u[0-9a-fA-F]{4}|\\\\u\\{[0-9a-fA-F]+\\}";
|
|
39
|
+
var identifierStart = "(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
|
|
40
|
+
var identifierChars = "(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
|
|
40
41
|
|
|
41
42
|
exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
|
|
42
43
|
exports.identifierStart = new RegExp(identifierStart);
|
|
43
|
-
exports.identifierMatch = new RegExp("(
|
|
44
|
+
exports.identifierMatch = new RegExp("(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
|
|
44
45
|
|
|
45
46
|
var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line
|
|
46
47
|
|
|
@@ -892,7 +892,9 @@ Beautifier.prototype.handle_word = function(current_token) {
|
|
|
892
892
|
}
|
|
893
893
|
|
|
894
894
|
if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
|
|
895
|
-
if (!this.start_of_object_property()
|
|
895
|
+
if (!this.start_of_object_property() && !(
|
|
896
|
+
// start of object property is different for numeric values with +/- prefix operators
|
|
897
|
+
in_array(this._flags.last_token.text, ['+', '-']) && this._last_last_text === ':' && this._flags.parent.mode === MODE.ObjectLiteral)) {
|
|
896
898
|
this.allow_wrap_or_preserved_newline(current_token);
|
|
897
899
|
}
|
|
898
900
|
}
|
|
@@ -1184,6 +1186,12 @@ Beautifier.prototype.handle_operator = function(current_token) {
|
|
|
1184
1186
|
return;
|
|
1185
1187
|
}
|
|
1186
1188
|
|
|
1189
|
+
if (in_array(current_token.text, ['-', '+']) && this.start_of_object_property()) {
|
|
1190
|
+
// numeric value with +/- symbol in front as a property
|
|
1191
|
+
this.print_token(current_token);
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1187
1195
|
// Allow line wrapping between operators when operator_position is
|
|
1188
1196
|
// set to before or preserve
|
|
1189
1197
|
if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
|
|
@@ -484,6 +484,9 @@ function unescape_string(s) {
|
|
|
484
484
|
matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
|
|
485
485
|
} else if (input_scan.peek() === 'u') {
|
|
486
486
|
matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
|
|
487
|
+
if (!matched) {
|
|
488
|
+
matched = input_scan.match(/u\{([0-9A-Fa-f]+)\}/g);
|
|
489
|
+
}
|
|
487
490
|
} else {
|
|
488
491
|
out += '\\';
|
|
489
492
|
if (input_scan.hasNext()) {
|
|
@@ -507,7 +510,9 @@ function unescape_string(s) {
|
|
|
507
510
|
} else if (escaped >= 0x00 && escaped < 0x20) {
|
|
508
511
|
// leave 0x00...0x1f escaped
|
|
509
512
|
out += '\\' + matched[0];
|
|
510
|
-
|
|
513
|
+
} else if (escaped > 0x10FFFF) {
|
|
514
|
+
// If the escape sequence is out of bounds, keep the original sequence and continue conversion
|
|
515
|
+
out += '\\' + matched[0];
|
|
511
516
|
} else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
|
|
512
517
|
// single-quote, apostrophe, backslash - escape these
|
|
513
518
|
out += '\\' + String.fromCharCode(escaped);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bmewburn/js-beautify",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.9-beta.1",
|
|
4
4
|
"description": "beautifier.io for node",
|
|
5
5
|
"main": "js/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -45,28 +45,28 @@
|
|
|
45
45
|
],
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=14"
|
|
49
49
|
},
|
|
50
50
|
"browserslist": "ie 11",
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"config-chain": "^1.1.13",
|
|
53
|
-
"editorconfig": "^0.
|
|
54
|
-
"glob": "^
|
|
55
|
-
"nopt": "^
|
|
53
|
+
"editorconfig": "^1.0.3",
|
|
54
|
+
"glob": "^10.3.3",
|
|
55
|
+
"nopt": "^7.2.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"ansi-regex": "^6.0.1",
|
|
59
59
|
"benchmark": "^2.1.4",
|
|
60
|
-
"codemirror": "^5.65.
|
|
61
|
-
"jquery": "^3.6.
|
|
62
|
-
"jshint": "^2.13.
|
|
63
|
-
"minimist": "^1.2.
|
|
64
|
-
"mocha": "^10.
|
|
60
|
+
"codemirror": "^5.65.13",
|
|
61
|
+
"jquery": "^3.6.4",
|
|
62
|
+
"jshint": "^2.13.6",
|
|
63
|
+
"minimist": "^1.2.8",
|
|
64
|
+
"mocha": "^10.2.0",
|
|
65
65
|
"mustache": "^4.2.0",
|
|
66
66
|
"requirejs": "^2.3.6",
|
|
67
|
-
"serve": "^14.0
|
|
67
|
+
"serve": "^14.2.0",
|
|
68
68
|
"strip-ansi": "^7.0.1",
|
|
69
|
-
"webpack": "^5.
|
|
70
|
-
"webpack-cli": "^
|
|
69
|
+
"webpack": "^5.81.0",
|
|
70
|
+
"webpack-cli": "^5.1.4"
|
|
71
71
|
}
|
|
72
72
|
}
|