mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-17 03:38:08 +00:00
Merge branch 'main' into feat/2113-inline-custom-elements-behavior
This commit is contained in:
commit
495c8c32de
13
.github/workflows/main.yml
vendored
13
.github/workflows/main.yml
vendored
@ -17,19 +17,14 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ ubuntu, windows, macos ]
|
||||
python-version: [3.7, 3.8, 3.9, '3.10']
|
||||
python-version: [3.8, '3.10', 3.11]
|
||||
include:
|
||||
- python-version: 3.7
|
||||
node-version: 12
|
||||
- python-version: 3.8
|
||||
node-version: 14
|
||||
- python-version: 3.9
|
||||
node-version: 16
|
||||
- python-version: '3.10'
|
||||
node-version: 16
|
||||
exclude:
|
||||
- os: windows
|
||||
python-version: 2.7
|
||||
node-version: 18
|
||||
- python-version: 3.11
|
||||
node-version: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Node ${{ matrix.node-version }}
|
||||
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,5 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## v1.14.8
|
||||
* Require nodejs v12 or greater ([#2151](https://github.com/beautify-web/js-beautify/pull/2151))
|
||||
* CSS insideNonNestedAtRule generic variable ([#2147](https://github.com/beautify-web/js-beautify/pull/2147))
|
||||
* Update dependencies ([#2145](https://github.com/beautify-web/js-beautify/pull/2145))
|
||||
* Fix CI build ([#2144](https://github.com/beautify-web/js-beautify/pull/2144))
|
||||
* Fixed #2133 Theme Toggle on without\_codemirror Mode ([#2138](https://github.com/beautify-web/js-beautify/pull/2138))
|
||||
* use correct variable name ([#2135](https://github.com/beautify-web/js-beautify/pull/2135))
|
||||
* docs: Fix a few typos ([#2127](https://github.com/beautify-web/js-beautify/pull/2127))
|
||||
* Add support for new record types (cont.) ([#2118](https://github.com/beautify-web/js-beautify/pull/2118))
|
||||
* fix - semicolon followed by block statement doesnt have new line ([#2117](https://github.com/beautify-web/js-beautify/pull/2117))
|
||||
* Fix formatting related to the <menu> element ([#2114](https://github.com/beautify-web/js-beautify/pull/2114))
|
||||
* issue prettifying (function(){code();{code}})() ([#1852](https://github.com/beautify-web/js-beautify/issues/1852))
|
||||
|
||||
## v1.14.7
|
||||
* Doc: Updates web browser implementation examples ([#2107](https://github.com/beautify-web/js-beautify/pull/2107))
|
||||
* HTML formatter breaks layout by introducing newlines ([#1989](https://github.com/beautify-web/js-beautify/issues/1989))
|
||||
|
19
README.md
19
README.md
@ -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.8/beautify.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify-css.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/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.8/beautify.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify-css.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/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.8/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,6 +368,7 @@ 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]
|
||||
@ -433,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.8)
|
||||
|
@ -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,
|
||||
@ -164,6 +165,7 @@ 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"],
|
||||
@ -397,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]');
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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']);
|
||||
|
||||
|
3098
package-lock.json
generated
3098
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "js-beautify",
|
||||
"version": "1.14.7",
|
||||
"version": "1.14.8",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ def beautify(string, opts=None):
|
||||
|
||||
def beautify_file(file_name, opts=None):
|
||||
_main = __import__("cssbeautifier", globals(), locals(), ["_main"])._main
|
||||
return _main.beautify_file(file, opts)
|
||||
return _main.beautify_file(file_name, opts)
|
||||
|
||||
|
||||
def usage(stream=sys.stdout):
|
||||
|
@ -1 +1 @@
|
||||
__version__ = "1.14.7"
|
||||
__version__ = "1.14.8"
|
||||
|
@ -52,7 +52,6 @@ def beautify_file(file_name, opts=None):
|
||||
|
||||
|
||||
def usage(stream=sys.stdout):
|
||||
|
||||
print(
|
||||
"cssbeautifier.py@"
|
||||
+ __version__
|
||||
@ -102,7 +101,6 @@ Rarely needed options:
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
argv = sys.argv[1:]
|
||||
|
||||
try:
|
||||
|
@ -67,7 +67,6 @@ def beautify_file(file_name, opts=default_options()):
|
||||
|
||||
|
||||
def usage(stream=sys.stdout):
|
||||
|
||||
print(
|
||||
"cssbeautifier.py@"
|
||||
+ __version__
|
||||
@ -384,7 +383,6 @@ class Beautifier:
|
||||
if self._options.brace_style == "expand":
|
||||
self._output.add_new_line(True)
|
||||
elif self._ch == ":":
|
||||
|
||||
for i in range(0, len(self.NON_SEMICOLON_NEWLINE_PROPERTY)):
|
||||
if self._input.lookBack(self.NON_SEMICOLON_NEWLINE_PROPERTY[i]):
|
||||
insideNonSemiColonValues = True
|
||||
|
1
python/cssbeautifier/tests/__init__.py
Normal file
1
python/cssbeautifier/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# Empty file :)
|
@ -87,7 +87,6 @@ def beautify_file(file_name, opts=default_options()):
|
||||
|
||||
|
||||
def usage(stream=sys.stdout):
|
||||
|
||||
print(
|
||||
"jsbeautifier.py@"
|
||||
+ __version__
|
||||
@ -156,7 +155,6 @@ Rarely needed options:
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
argv = sys.argv[1:]
|
||||
|
||||
try:
|
||||
|
@ -1 +1 @@
|
||||
__version__ = "1.14.7"
|
||||
__version__ = "1.14.8"
|
||||
|
@ -27,7 +27,6 @@ import re
|
||||
|
||||
class Directives:
|
||||
def __init__(self, start_block_pattern, end_block_pattern):
|
||||
|
||||
self.__directives_block_pattern = re.compile(
|
||||
start_block_pattern + r" beautify( \w+[:]\w+)+ " + end_block_pattern
|
||||
)
|
||||
|
@ -204,7 +204,6 @@ class IndentStringCache:
|
||||
|
||||
class Output:
|
||||
def __init__(self, options, baseIndentString=""):
|
||||
|
||||
self.__indent_cache = IndentStringCache(options, baseIndentString)
|
||||
self.raw = False
|
||||
self._end_with_newline = options.end_with_newline
|
||||
|
@ -171,7 +171,6 @@ class TemplatablePattern(Pattern):
|
||||
resulting_string or self.__patterns.django_value.read()
|
||||
)
|
||||
if not self._excluded.django:
|
||||
|
||||
resulting_string = (
|
||||
resulting_string or self.__patterns.django_comment.read()
|
||||
)
|
||||
|
@ -1369,7 +1369,6 @@ class Beautifier:
|
||||
and self._options.preserve_newlines
|
||||
and current_token.text in Tokenizer.positionable_operators
|
||||
):
|
||||
|
||||
isColon = current_token.text == ":"
|
||||
isTernaryColon = isColon and in_ternary
|
||||
isOtherColon = isColon and not in_ternary
|
||||
|
@ -342,7 +342,6 @@ class Tokenizer(BaseTokenizer):
|
||||
return None
|
||||
|
||||
def _read_regexp(self, c, previous_token):
|
||||
|
||||
if c == "/" and self.allowRegExOrXML(previous_token):
|
||||
# handle regexp
|
||||
resulting_string = self._input.next()
|
||||
@ -425,7 +424,6 @@ class Tokenizer(BaseTokenizer):
|
||||
resulting_string = ""
|
||||
|
||||
if c == "#":
|
||||
|
||||
# she-bang
|
||||
if self._is_first_token():
|
||||
resulting_string = self._patterns.shebang.read()
|
||||
@ -471,7 +469,6 @@ class Tokenizer(BaseTokenizer):
|
||||
self._input.back()
|
||||
|
||||
elif c == "<" and self._is_first_token():
|
||||
|
||||
if self._patterns.html_comment_start.read():
|
||||
c = "<!--"
|
||||
while self._input.hasNext() and not self._input.testChar(
|
||||
|
1
python/jsbeautifier/tests/generated/__init__.py
Normal file
1
python/jsbeautifier/tests/generated/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# Empty file :)
|
@ -1995,6 +1995,23 @@ exports.test_data = {
|
||||
unchanged: 'p {\n color: blue;\n}'
|
||||
}]
|
||||
}, {
|
||||
name: "Issue #2012, #2147",
|
||||
description: "Avoid whitespace between first colon and next character in non nested at-rules",
|
||||
options: [],
|
||||
tests: [{
|
||||
unchanged: '@extend .btn-blue:hover;'
|
||||
}, {
|
||||
unchanged: '@import url("chrome://communicator/skin/");'
|
||||
}, {
|
||||
unchanged: '@apply w-4 lg:w-10 space-y-3 lg:space-x-12;'
|
||||
}, {
|
||||
unchanged: [
|
||||
'h3 {',
|
||||
' @apply flex flex-col lg:flex-row space-y-3 lg:space-x-12 items-start;',
|
||||
'}'
|
||||
]
|
||||
}]
|
||||
}, {
|
||||
|
||||
}
|
||||
]
|
||||
|
@ -1193,6 +1193,105 @@ exports.test_data = {
|
||||
'^^^indent_attr$$$(typeaheadOnSelect)="onSuggestionSelected($event)" />'
|
||||
]
|
||||
}]
|
||||
}, {
|
||||
name: "Test wrap_attributes_min_attrs with force/force-xx options",
|
||||
description: "",
|
||||
matrix: [{
|
||||
options: [
|
||||
{ name: "wrap_attributes", value: "'force'" },
|
||||
{ name: "wrap_attributes_min_attrs", value: "4" }
|
||||
],
|
||||
indent_attr: ' ',
|
||||
indent_attr_first: ' ',
|
||||
indent_end: ' ',
|
||||
newline_end: ''
|
||||
}, {
|
||||
options: [
|
||||
{ name: "wrap_attributes", value: "'force-aligned'" },
|
||||
{ name: "wrap_attributes_min_attrs", value: "4" }
|
||||
],
|
||||
indent_attr: ' ',
|
||||
indent_attr_first: ' ',
|
||||
indent_end: ' ',
|
||||
newline_end: ''
|
||||
}, {
|
||||
options: [
|
||||
{ name: "wrap_attributes", value: "'force-expand-multiline'" },
|
||||
{ name: "wrap_attributes_min_attrs", value: "4" }
|
||||
],
|
||||
indent_attr: ' ',
|
||||
indent_attr_first: '\n ',
|
||||
indent_end: '\n',
|
||||
newline_end: '\n'
|
||||
}],
|
||||
tests: [{
|
||||
input: [
|
||||
'<input type="four attributes should wrap" class="form-control" autocomplete="off"',
|
||||
'[(ngModel)]="myValue" />'
|
||||
],
|
||||
output: [
|
||||
'<input{{indent_attr_first}}type="four attributes should wrap"',
|
||||
'{{indent_attr}}class="form-control"',
|
||||
'{{indent_attr}}autocomplete="off"',
|
||||
'{{indent_attr}}[(ngModel)]="myValue"{{indent_end}}/>'
|
||||
]
|
||||
}, {
|
||||
input: [
|
||||
'<input type="three attributes should not wrap" autocomplete="off"',
|
||||
'[(ngModel)]="myValue" />'
|
||||
],
|
||||
output: '<input type="three attributes should not wrap" autocomplete="off" [(ngModel)]="myValue" />'
|
||||
}, {
|
||||
input: [
|
||||
'<cmpnt v-bind:xx="four attributes with valueless attribute should wrap" ' +
|
||||
'@someevent="dosomething" someprop',
|
||||
'class="xx-button">',
|
||||
'<div class="alert alert-info" style="margin-left: 1px;" role="alert">lorem ipsum</div>',
|
||||
'</cmpnt>'
|
||||
],
|
||||
output: [
|
||||
'<cmpnt{{indent_attr_first}}v-bind:xx="four attributes with valueless attribute should wrap"',
|
||||
'{{indent_attr}}@someevent="dosomething"',
|
||||
'{{indent_attr}}someprop',
|
||||
'{{indent_attr}}class="xx-button"{{newline_end}}>',
|
||||
' <div class="alert alert-info" style="margin-left: 1px;" role="alert">lorem ipsum</div>',
|
||||
'</cmpnt>'
|
||||
]
|
||||
}]
|
||||
}, {
|
||||
name: "Test wrap_attributes_min_attrs = 1 with force/force-xx options",
|
||||
description: "",
|
||||
matrix: [{
|
||||
// Should not wrap, by design
|
||||
options: [
|
||||
{ name: "wrap_attributes", value: "'force'" },
|
||||
{ name: "wrap_attributes_min_attrs", value: "1" }
|
||||
],
|
||||
indent_attr: ' ',
|
||||
newline_end: ' '
|
||||
}, {
|
||||
// Should not wrap, by design
|
||||
options: [
|
||||
{ name: "wrap_attributes", value: "'force-aligned'" },
|
||||
{ name: "wrap_attributes_min_attrs", value: "1" }
|
||||
],
|
||||
indent_attr: ' ',
|
||||
newline_end: ' '
|
||||
}, {
|
||||
// Should wrap
|
||||
options: [
|
||||
{ name: "wrap_attributes", value: "'force-expand-multiline'" },
|
||||
{ name: "wrap_attributes_min_attrs", value: "1" }
|
||||
],
|
||||
indent_attr: '\n ',
|
||||
newline_end: '\n'
|
||||
}],
|
||||
tests: [{
|
||||
input: [
|
||||
'<input type="one attribute"/>'
|
||||
],
|
||||
output: '<input{{indent_attr}}type="one attribute"{{newline_end}}/>'
|
||||
}]
|
||||
}, {
|
||||
name: "Handlebars Indenting Off",
|
||||
description: "Test handlebar behavior when indenting is off",
|
||||
|
@ -367,7 +367,7 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
test_fragment('foo {', 'foo {')
|
||||
test_fragment('return {', 'return {') # return needs the brace.
|
||||
test_fragment('return /* inline */ {', 'return /* inline */ {')
|
||||
test_fragment('return;\n{', 'return; {')
|
||||
test_fragment('return;\n{', 'return;\n{')
|
||||
bt("throw {}")
|
||||
bt("throw {\n foo;\n}")
|
||||
bt('var foo = {}')
|
||||
@ -458,7 +458,7 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
test_fragment('foo {', 'foo {')
|
||||
test_fragment('return {', 'return {') # return needs the brace.
|
||||
test_fragment('return /* inline */ {', 'return /* inline */ {')
|
||||
test_fragment('return;\n{', 'return; {')
|
||||
test_fragment('return;\n{', 'return;\n{')
|
||||
bt("throw {}")
|
||||
bt("throw {\n foo;\n}")
|
||||
bt('var foo = {}')
|
||||
|
@ -16,7 +16,7 @@ $(function() {
|
||||
the.editor = CodeMirror.fromTextArea(textArea, {
|
||||
lineNumbers: true
|
||||
});
|
||||
setPreferredColorScheme();
|
||||
|
||||
set_editor_mode();
|
||||
the.editor.focus();
|
||||
|
||||
@ -37,6 +37,7 @@ $(function() {
|
||||
});
|
||||
}
|
||||
|
||||
setPreferredColorScheme();
|
||||
|
||||
$(window).bind('keydown', function(e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.keyCode === 13) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user