Skip to content

Commit

Permalink
Merge branch 'MDL-75483-master' of https://github.com/davewoloszyn/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdef committed Oct 24, 2022
2 parents 83aa6c2 + 8f57991 commit 3b40231
Show file tree
Hide file tree
Showing 8 changed files with 496 additions and 268 deletions.
2 changes: 1 addition & 1 deletion lib/editor/atto/plugins/html/thirdpartylibs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<location>yui/src/beautify</location>
<name>jsbeautify</name>
<description>Beautify HTML code in Atto.</description>
<version>1.14.0</version>
<version>1.14.6</version>
<license>MIT</license>
<repository>https://github.com/beautify-web/js-beautify</repository>
<copyrights>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

83 changes: 66 additions & 17 deletions lib/editor/atto/plugins/html/yui/src/beautify/js/beautify-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,8 @@ module.exports.Directives = Directives;



var Beautifier = __webpack_require__(16).Beautifier,
Options = __webpack_require__(17).Options;
var Beautifier = (__webpack_require__(16).Beautifier),
Options = (__webpack_require__(17).Options);

function css_beautify(source_text, options) {
var beautifier = new Beautifier(source_text, options);
Expand Down Expand Up @@ -1051,10 +1051,10 @@ module.exports.defaultOptions = function() {



var Options = __webpack_require__(17).Options;
var Output = __webpack_require__(2).Output;
var InputScanner = __webpack_require__(8).InputScanner;
var Directives = __webpack_require__(13).Directives;
var Options = (__webpack_require__(17).Options);
var Output = (__webpack_require__(2).Output);
var InputScanner = (__webpack_require__(8).InputScanner);
var Directives = (__webpack_require__(13).Directives);

var directives_core = new Directives(/\/\*/, /\*\//);

Expand Down Expand Up @@ -1090,6 +1090,10 @@ function Beautifier(source_text, options) {
"@supports": true,
"@document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template-areas",
"grid-template"
];

}

Expand Down Expand Up @@ -1214,7 +1218,9 @@ Beautifier.prototype.beautify = function() {
var enteringConditionalGroup = false;
var insideAtExtend = false;
var insideAtImport = false;
var insideScssMap = false;
var topCharacter = this._ch;
var insideNonSemiColonValues = false;
var whitespace;
var isAfterSpace;
var previous_ch;
Expand Down Expand Up @@ -1266,7 +1272,7 @@ Beautifier.prototype.beautify = function() {

// Ensures any new lines following the comment are preserved
this.eatWhitespace(true);
} else if (this._ch === '@') {
} else if (this._ch === '@' || this._ch === '$') {
this.preserveSingleSpace(isAfterSpace);

// deal with less propery mixins @{...}
Expand Down Expand Up @@ -1337,7 +1343,12 @@ Beautifier.prototype.beautify = function() {
this.indent();
this._output.set_indent(this._indentLevel);
} else {
this.indent();
// inside mixin and first param is object
if (previous_ch === '(') {
this._output.space_before_token = false;
} else if (previous_ch !== ',') {
this.indent();
}
this.print_string(this._ch);
}

Expand Down Expand Up @@ -1369,7 +1380,21 @@ Beautifier.prototype.beautify = function() {
this._output.add_new_line(true);
}
}
if (this._input.peek() === ')') {
this._output.trim(true);
if (this._options.brace_style === "expand") {
this._output.add_new_line(true);
}
}
} else if (this._ch === ":") {

for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
insideNonSemiColonValues = true;
break;
}
}

if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
// 'property: value' delimiter
// which could be in a conditional group query
Expand Down Expand Up @@ -1398,10 +1423,12 @@ Beautifier.prototype.beautify = function() {
}
}
} else if (this._ch === '"' || this._ch === '\'') {
this.preserveSingleSpace(isAfterSpace);
var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
this.print_string(this._ch + this.eatString(this._ch));
this.eatWhitespace(true);
} else if (this._ch === ';') {
insideNonSemiColonValues = false;
if (parenLevel === 0) {
if (insidePropertyValue) {
this.outdent();
Expand Down Expand Up @@ -1441,22 +1468,39 @@ Beautifier.prototype.beautify = function() {
}
}
} else {
this.preserveSingleSpace(isAfterSpace);
var space_needed = false;
if (this._input.lookBack("with")) {
// look back is not an accurate solution, we need tokens to confirm without whitespaces
space_needed = true;
}
this.preserveSingleSpace(isAfterSpace || space_needed);
this.print_string(this._ch);
this.eatWhitespace();
parenLevel++;
this.indent();

// handle scss/sass map
if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
this._output.add_new_line();
insideScssMap = true;
} else {
this.eatWhitespace();
parenLevel++;
this.indent();
}
}
} else if (this._ch === ')') {
if (parenLevel) {
parenLevel--;
this.outdent();
}
if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
insideScssMap = false;
this.outdent();
this._output.add_new_line();
}
this.print_string(this._ch);
} else if (this._ch === ',') {
this.print_string(this._ch);
this.eatWhitespace(true);
if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
this._output.add_new_line();
} else {
this._output.space_before_token = true;
Expand Down Expand Up @@ -1487,11 +1531,16 @@ Beautifier.prototype.beautify = function() {
this._ch = '';
}
} else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
this.print_string(' ');
this._output.space_before_token = true;
this.print_string(this._ch);
} else {
this.preserveSingleSpace(isAfterSpace);
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
this.print_string(this._ch);

if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
this._output.add_new_line();
}
}
}

Expand Down Expand Up @@ -1537,7 +1586,7 @@ module.exports.Beautifier = Beautifier;



var BaseOptions = __webpack_require__(6).Options;
var BaseOptions = (__webpack_require__(6).Options);

function Options(options) {
BaseOptions.call(this, options, 'css');
Expand Down
59 changes: 36 additions & 23 deletions lib/editor/atto/plugins/html/yui/src/beautify/js/beautify-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,10 @@ module.exports.InputScanner = InputScanner;



var InputScanner = __webpack_require__(8).InputScanner;
var Token = __webpack_require__(3).Token;
var TokenStream = __webpack_require__(10).TokenStream;
var WhitespacePattern = __webpack_require__(11).WhitespacePattern;
var InputScanner = (__webpack_require__(8).InputScanner);
var Token = (__webpack_require__(3).Token);
var TokenStream = (__webpack_require__(10).TokenStream);
var WhitespacePattern = (__webpack_require__(11).WhitespacePattern);

var TOKEN = {
START: 'TK_START',
Expand Down Expand Up @@ -1229,7 +1229,7 @@ module.exports.TokenStream = TokenStream;



var Pattern = __webpack_require__(12).Pattern;
var Pattern = (__webpack_require__(12).Pattern);

function WhitespacePattern(input_scanner, parent) {
Pattern.call(this, input_scanner, parent);
Expand Down Expand Up @@ -1508,7 +1508,7 @@ module.exports.Directives = Directives;



var Pattern = __webpack_require__(12).Pattern;
var Pattern = (__webpack_require__(12).Pattern);


var template_names = {
Expand Down Expand Up @@ -1728,8 +1728,8 @@ module.exports.TemplatablePattern = TemplatablePattern;



var Beautifier = __webpack_require__(19).Beautifier,
Options = __webpack_require__(20).Options;
var Beautifier = (__webpack_require__(19).Beautifier),
Options = (__webpack_require__(20).Options);

function style_html(html_source, options, js_beautify, css_beautify) {
var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
Expand Down Expand Up @@ -1776,10 +1776,10 @@ module.exports.defaultOptions = function() {



var Options = __webpack_require__(20).Options;
var Output = __webpack_require__(2).Output;
var Tokenizer = __webpack_require__(21).Tokenizer;
var TOKEN = __webpack_require__(21).TOKEN;
var Options = (__webpack_require__(20).Options);
var Output = (__webpack_require__(2).Output);
var Tokenizer = (__webpack_require__(21).Tokenizer);
var TOKEN = (__webpack_require__(21).TOKEN);

var lineBreak = /\r\n|[\r\n]/;
var allLineBreaks = /\r\n|[\r\n]/g;
Expand Down Expand Up @@ -2355,14 +2355,19 @@ var TagOpenParserToken = function(parent, raw_token) {
tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';
} else {
tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';

// handle "{{#> myPartial}}
if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text;
// handle "{{#> myPartial}}" or "{{~#> myPartial}}"
if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
if (this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text.split(' ')[0];
} else {
this.tag_check = raw_token.text.split('>')[1];
}
}
}

this.tag_check = this.tag_check.toLowerCase();

if (raw_token.type === TOKEN.COMMENT) {
Expand All @@ -2374,9 +2379,17 @@ var TagOpenParserToken = function(parent, raw_token) {
this.is_end_tag = !this.is_start_tag ||
(raw_token.closed && raw_token.closed.text === '/>');

// if whitespace handler ~ included (i.e. {{~#if true}}), handlebars tags start at pos 3 not pos 2
var handlebar_starts = 2;
if (this.tag_start_char === '{' && this.text.length >= 3) {
if (this.text.charAt(2) === '~') {
handlebar_starts = 3;
}
}

// handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
this.is_end_tag = this.is_end_tag ||
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(2)))));
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
}
};

Expand Down Expand Up @@ -2647,7 +2660,7 @@ module.exports.Beautifier = Beautifier;



var BaseOptions = __webpack_require__(6).Options;
var BaseOptions = (__webpack_require__(6).Options);

function Options(options) {
BaseOptions.call(this, options, 'html');
Expand Down Expand Up @@ -2744,11 +2757,11 @@ module.exports.Options = Options;



var BaseTokenizer = __webpack_require__(9).Tokenizer;
var BASETOKEN = __webpack_require__(9).TOKEN;
var Directives = __webpack_require__(13).Directives;
var TemplatablePattern = __webpack_require__(14).TemplatablePattern;
var Pattern = __webpack_require__(12).Pattern;
var BaseTokenizer = (__webpack_require__(9).Tokenizer);
var BASETOKEN = (__webpack_require__(9).TOKEN);
var Directives = (__webpack_require__(13).Directives);
var TemplatablePattern = (__webpack_require__(14).TemplatablePattern);
var Pattern = (__webpack_require__(12).Pattern);

var TOKEN = {
TAG_OPEN: 'TK_TAG_OPEN',
Expand Down
Loading

0 comments on commit 3b40231

Please sign in to comment.