mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-23 12:49:40 +00:00
Cleaned commit history and added changes
This commit is contained in:
parent
97caa30849
commit
5ddfa5784b
@ -91,13 +91,12 @@ Beautifier.prototype.eatString = function(endChars) {
|
||||
// the first newline will be output
|
||||
Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) {
|
||||
var result = whitespaceChar.test(this._input.peek());
|
||||
var isFirstNewLine = true;
|
||||
|
||||
var newline_count = 0;
|
||||
while (whitespaceChar.test(this._input.peek())) {
|
||||
this._ch = this._input.next();
|
||||
if (allowAtLeastOneNewLine && this._ch === '\n') {
|
||||
if (this._options.preserve_newlines || isFirstNewLine) {
|
||||
isFirstNewLine = false;
|
||||
if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) {
|
||||
newline_count++;
|
||||
this._output.add_new_line(true);
|
||||
}
|
||||
}
|
||||
|
@ -11044,6 +11044,35 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
|
||||
'}');
|
||||
|
||||
|
||||
//============================================================
|
||||
// Preserve Newlines and max number of new lines
|
||||
reset_options();
|
||||
set_name('Preserve Newlines and max number of new lines');
|
||||
opts.preserve_newlines = true;
|
||||
opts.max_preserve_newlines = 2;
|
||||
t(
|
||||
'p {\n' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
' color: blue;\n' +
|
||||
'}',
|
||||
// -- output --
|
||||
'p {\n' +
|
||||
'\n' +
|
||||
' color: blue;\n' +
|
||||
'}');
|
||||
t(
|
||||
'p {\n' +
|
||||
'\n' +
|
||||
' color: blue;\n' +
|
||||
'}');
|
||||
t(
|
||||
'p {\n' +
|
||||
' color: blue;\n' +
|
||||
'}');
|
||||
|
||||
|
||||
//============================================================
|
||||
//
|
||||
reset_options();
|
||||
|
@ -139,13 +139,13 @@ class Beautifier:
|
||||
def eatWhitespace(self, allowAtLeastOneNewLine=False):
|
||||
result = whitespaceChar.search(self._input.peek() or "") is not None
|
||||
isFirstNewLine = True
|
||||
|
||||
newline_count = 0
|
||||
while whitespaceChar.search(self._input.peek() or "") is not None:
|
||||
self._ch = self._input.next()
|
||||
if allowAtLeastOneNewLine and self._ch == "\n":
|
||||
if self._options.preserve_newlines or isFirstNewLine:
|
||||
isFirstNewLine = False
|
||||
self._output.add_new_line(True)
|
||||
if newline_count == 0 or newline_count < self._options.max_preserve_newlines:
|
||||
newline_count += 1
|
||||
self._output.add_new_line(True)
|
||||
return result
|
||||
|
||||
# Nested pseudo-class if we are insideRule
|
||||
|
@ -10914,6 +10914,34 @@ class CSSBeautifierTest(unittest.TestCase):
|
||||
'}')
|
||||
|
||||
|
||||
#============================================================
|
||||
# Preserve Newlines and max number of new lines
|
||||
self.reset_options()
|
||||
self.options.preserve_newlines = true
|
||||
self.options.max_preserve_newlines = 2
|
||||
t(
|
||||
'p {\n' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
' color: blue;\n' +
|
||||
'}',
|
||||
# -- output --
|
||||
'p {\n' +
|
||||
'\n' +
|
||||
' color: blue;\n' +
|
||||
'}')
|
||||
t(
|
||||
'p {\n' +
|
||||
'\n' +
|
||||
' color: blue;\n' +
|
||||
'}')
|
||||
t(
|
||||
'p {\n' +
|
||||
' color: blue;\n' +
|
||||
'}')
|
||||
|
||||
|
||||
#============================================================
|
||||
#
|
||||
self.reset_options()
|
||||
|
@ -1800,6 +1800,21 @@ exports.test_data = {
|
||||
]
|
||||
}]
|
||||
}, {
|
||||
name: "Preserve Newlines and max number of new lines",
|
||||
options: [
|
||||
{ name: "preserve_newlines", value: "true" },
|
||||
{ name: "max_preserve_newlines", value: "2" }
|
||||
],
|
||||
description: "",
|
||||
tests: [{
|
||||
input: 'p {\n\n\n\n color: blue;\n}',
|
||||
output: 'p {\n\n color: blue;\n}'
|
||||
}, {
|
||||
unchanged: 'p {\n\n color: blue;\n}'
|
||||
}, {
|
||||
unchanged: 'p {\n color: blue;\n}'
|
||||
}]
|
||||
}, {
|
||||
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user