diff --git a/.vscode/launch.json b/.vscode/launch.json index 3243007..7eca463 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,7 +7,7 @@ "request": "attach", "port": 6004, "sourceMaps": true, - "outFiles": ["${workspaceRoot}/lib/umd/**"] + "outFiles": ["${workspaceRoot}/lib/esm/**"] }, { "name": "Unit Tests", @@ -18,11 +18,11 @@ "--test" ], "args": [ - "./lib/umd/test/*.js" + "./lib/esm/test/*.js" ], "cwd": "${workspaceRoot}", "sourceMaps": true, - "outFiles": ["${workspaceRoot}/lib/umd/**"], + "outFiles": ["${workspaceRoot}/lib/esm/**"], "preLaunchTask": "npm: compile" } ] diff --git a/README.md b/README.md index 398754d..0725628 100644 --- a/README.md +++ b/README.md @@ -72,5 +72,5 @@ License Copyright 2016-2023, Microsoft -`src/languageFacts/data/webCustomData.ts` (shipped as `lib/esm/languageFacts/data/webCustomData.ts` and `lib/umd/languageFacts/data/webCustomData.ts`) +`src/languageFacts/data/webCustomData.ts` (shipped as `lib/esm/languageFacts/data/webCustomData.ts`) are built upon content from [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web) and distributed under CC BY-SA 2.5. diff --git a/build/copy-jsbeautify.js b/build/copy-jsbeautify.js deleted file mode 100644 index 233fb6e..0000000 --- a/build/copy-jsbeautify.js +++ /dev/null @@ -1,23 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -function copy(from, to) { - if (!fs.existsSync(to)) { - fs.mkdirSync(to, { recursive: true }); - } - const files = fs.readdirSync(from); - for (let file of files) { - if (path.extname(file) === '.js') { - const fromPath = path.join(from, file); - const toPath = path.join(to, file); - console.log(`copy ${fromPath} to ${toPath}`); - fs.copyFileSync(fromPath, toPath); - } - } -} - -const umdDir = path.join(__dirname, '..', 'lib', 'umd', 'beautify'); -copy(path.join(__dirname, '..', 'src', 'beautify'), umdDir); - -const esmDir = path.join(__dirname, '..', 'lib', 'esm', 'beautify'); -copy(path.join(__dirname, '..', 'src', 'beautify', 'esm'), esmDir); diff --git a/build/generateData.js b/build/generateData.js index 91ab081..3e742e2 100644 --- a/build/generateData.js +++ b/build/generateData.js @@ -3,11 +3,15 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -const fs = require('fs') -const path = require('path') -const os = require('os') +import fs from 'node:fs'; +import path from 'node:path'; +import os from 'node:os'; +import { createRequire } from 'node:module'; +import { fileURLToPath } from 'node:url'; +const require = createRequire(import.meta.url); const customData = require('@vscode/web-custom-data/data/browsers.html-data.json'); +const __dirname = path.dirname(fileURLToPath(import.meta.url)); function toJavaScript(obj) { return JSON.stringify(obj, null, '\t'); @@ -21,13 +25,13 @@ const output = [ ' *--------------------------------------------------------------------------------------------*/', '// file generated from @vscode/web-custom-data NPM package', '', - `import { ${DATA_TYPE} } from '../../htmlLanguageTypes';`, + `import { ${DATA_TYPE} } from '../../htmlLanguageTypes.js';`, '', `export const htmlData : ${DATA_TYPE} = ` + toJavaScript(customData) + ';' ]; -var outputPath = path.resolve(__dirname, '../src/languageFacts/data/webCustomData.ts'); +const outputPath = path.resolve(__dirname, '../src/languageFacts/data/webCustomData.ts'); console.log('Writing to: ' + outputPath); -var content = output.join(os.EOL); +const content = output.join(os.EOL); fs.writeFileSync(outputPath, content); console.log('Done'); diff --git a/build/remove-sourcemap-refs.js b/build/remove-sourcemap-refs.js index 89a0997..767af70 100644 --- a/build/remove-sourcemap-refs.js +++ b/build/remove-sourcemap-refs.js @@ -3,8 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -const fs = require('fs'); -const path = require('path'); +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); function deleteRefs(dir) { const files = fs.readdirSync(dir); diff --git a/build/update-jsbeautify.js b/build/update-jsbeautify.js index 5192638..6e25336 100644 --- a/build/update-jsbeautify.js +++ b/build/update-jsbeautify.js @@ -3,25 +3,26 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -'use strict'; +import path from 'node:path'; +import fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; -var path = require('path'); -var fs = require('fs'); +const __dirname = path.dirname(fileURLToPath(import.meta.url)); function getVersion(moduleName) { - var packageJSONPath = path.join(__dirname, '..', 'node_modules', moduleName, 'package.json'); + const packageJSONPath = path.join(__dirname, '..', 'node_modules', moduleName, 'package.json'); return readFile(packageJSONPath).then(function (content) { try { return JSON.parse(content).version; } catch (e) { - return Promise.resolve(null); + return null; } }); } -function readFile(path) { +function readFile(filePath) { return new Promise((s, e) => { - fs.readFile(path, (err, res) => { + fs.readFile(filePath, (err, res) => { if (err) { e(err); } else { @@ -33,7 +34,7 @@ function readFile(path) { } function update(moduleName, repoPath, dest, addHeader, patch) { - var contentPath = path.join(__dirname, '..', 'node_modules', moduleName, repoPath); + const contentPath = path.join(__dirname, '..', 'node_modules', moduleName, repoPath); console.log('Reading from ' + contentPath); return readFile(contentPath).then(function (content) { return getVersion(moduleName).then(function (version) { @@ -62,12 +63,10 @@ function update(moduleName, repoPath, dest, addHeader, patch) { }, console.error); } -update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/beautify-html.js', true); -update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/beautify-css.js', true); update('js-beautify', 'LICENSE', './src/beautify/beautify-license'); // ESM version -update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/esm/beautify-html.js', true, function (contents) { +update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/beautify-html.js', true, function (contents) { let topLevelFunction = '(function() {'; let outputVar = 'var legacy_beautify_html'; let footer = 'var style_html = legacy_beautify_html;'; @@ -84,14 +83,14 @@ update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/esm/beautify-ht throw new Error(`Problem patching beautify.html for ESM: '${footer}' not found after '${outputVar}'.`); } return contents.substring(0, index1) + -`import { js_beautify } from "./beautify";\nimport { css_beautify } from "./beautify-css";\n\n` +`import { js_beautify } from "./beautify.js";\nimport { css_beautify } from "./beautify-css.js";\n\n` + contents.substring(index2, index3) + ` export function html_beautify(html_source, options) { return legacy_beautify_html(html_source, options, js_beautify, css_beautify); }`; }); -update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/esm/beautify-css.js', true, function (contents) { +update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/beautify-css.js', true, function (contents) { let topLevelFunction = '(function() {'; let outputVar = 'var legacy_beautify_css'; let footer = 'var css_beautify = legacy_beautify_css;'; diff --git a/package-lock.json b/package-lock.json index 55a1a5e..e936653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-html-languageservice", - "version": "5.6.2", + "version": "6.0.0-next.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vscode-html-languageservice", - "version": "5.6.2", + "version": "6.0.0-next.1", "license": "MIT", "dependencies": { "@vscode/l10n": "^0.0.18", diff --git a/package.json b/package.json index e267694..90aeb7c 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "vscode-html-languageservice", - "version": "5.6.2", + "version": "6.0.0-next.1", "description": "Language service for HTML", - "main": "./lib/umd/htmlLanguageService.js", - "typings": "./lib/umd/htmlLanguageService", + "type": "module", + "main": "./lib/esm/htmlLanguageService.js", + "typings": "./lib/esm/htmlLanguageService", "module": "./lib/esm/htmlLanguageService.js", "author": "Microsoft Corporation", "repository": { @@ -31,16 +32,14 @@ "vscode-uri": "^3.1.0" }, "scripts": { - "prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs", - "compile": "tsc -p ./src && npm run copy-jsbeautify", - "compile-esm": "tsc -p ./src/tsconfig.esm.json", - "watch": "tsc -w -p ./src && npm run copy-jsbeautify", + "prepack": "npm run clean && npm run compile && npm run test && npm run remove-sourcemap-refs", + "compile": "tsc -p ./src", + "watch": "tsc -w -p ./src", "clean": "rimraf lib", "remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js", - "test": "npm run compile && node --enable-source-maps --test ./lib/umd/test/*.js && npm run lint", + "test": "npm run compile && node --enable-source-maps --test ./lib/esm/test/*.js && npm run lint", "lint": "eslint src/**/*.ts", "install-types-next": "npm i vscode-languageserver-types@next -f -S && npm i vscode-languageserver-textdocument@next -f -S", - "copy-jsbeautify": "node ./build/copy-jsbeautify.js", "update-jsbeautify": "npm i js-beautify && node ./build/update-jsbeautify.js", "update-jsbeautify-next": "npm i js-beautify@next && node ./build/update-jsbeautify.js", "update-data": "npm i @vscode/web-custom-data -D && node ./build/generateData.js" diff --git a/src/beautify/beautify-css.js b/src/beautify/beautify-css.js index 278240e..9127d65 100644 --- a/src/beautify/beautify-css.js +++ b/src/beautify/beautify-css.js @@ -64,9 +64,6 @@ // http://www.w3.org/TR/CSS21/syndata.html#tokenization // http://www.w3.org/TR/css3-syntax/ -(function() { - -/* GENERATED_BUILD_OUTPUT */ var legacy_beautify_css; /******/ (function() { // webpackBootstrap /******/ "use strict"; @@ -1671,25 +1668,5 @@ module.exports.Options = Options; /******/ /******/ })() ; -var css_beautify = legacy_beautify_css; -/* Footer */ -if (typeof define === "function" && define.amd) { - // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- ) - define([], function() { - return { - css_beautify: css_beautify - }; - }); -} else if (typeof exports !== "undefined") { - // Add support for CommonJS. Just put this file somewhere on your require.paths - // and you will be able to `var html_beautify = require("beautify").html_beautify`. - exports.css_beautify = css_beautify; -} else if (typeof window !== "undefined") { - // If we're running a web page and don't have either of the above, add our one global - window.css_beautify = css_beautify; -} else if (typeof global !== "undefined") { - // If we don't even have window, try global. - global.css_beautify = css_beautify; -} -}()); +export var css_beautify = legacy_beautify_css; \ No newline at end of file diff --git a/src/beautify/beautify-html.js b/src/beautify/beautify-html.js index c96b8ca..cc452ea 100644 --- a/src/beautify/beautify-html.js +++ b/src/beautify/beautify-html.js @@ -74,9 +74,9 @@ }); */ -(function() { +import { js_beautify } from "./beautify.js"; +import { css_beautify } from "./beautify-css.js"; -/* GENERATED_BUILD_OUTPUT */ var legacy_beautify_html; /******/ (function() { // webpackBootstrap /******/ "use strict"; @@ -3206,39 +3206,7 @@ module.exports.TOKEN = TOKEN; /******/ /******/ })() ; -var style_html = legacy_beautify_html; -/* Footer */ -if (typeof define === "function" && define.amd) { - // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- ) - define(["require", "./beautify", "./beautify-css"], function(requireamd) { - var js_beautify = requireamd("./beautify"); - var css_beautify = requireamd("./beautify-css"); - - return { - html_beautify: function(html_source, options) { - return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify); - } - }; - }); -} else if (typeof exports !== "undefined") { - // Add support for CommonJS. Just put this file somewhere on your require.paths - // and you will be able to `var html_beautify = require("beautify").html_beautify`. - var js_beautify = require('./beautify.js'); - var css_beautify = require('./beautify-css.js'); - - exports.html_beautify = function(html_source, options) { - return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify); - }; -} else if (typeof window !== "undefined") { - // If we're running a web page and don't have either of the above, add our one global - window.html_beautify = function(html_source, options) { - return style_html(html_source, options, window.js_beautify, window.css_beautify); - }; -} else if (typeof global !== "undefined") { - // If we don't even have window, try global. - global.html_beautify = function(html_source, options) { - return style_html(html_source, options, global.js_beautify, global.css_beautify); - }; -} -}()); +export function html_beautify(html_source, options) { + return legacy_beautify_html(html_source, options, js_beautify, css_beautify); +} \ No newline at end of file diff --git a/src/beautify/esm/beautify-css.js b/src/beautify/esm/beautify-css.js deleted file mode 100644 index 9127d65..0000000 --- a/src/beautify/esm/beautify-css.js +++ /dev/null @@ -1,1672 +0,0 @@ -// copied from js-beautify/js/lib/beautify-css.js -// version: 1.15.4 -/* AUTO-GENERATED. DO NOT MODIFY. */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. - - - CSS Beautifier ---------------- - - Written by Harutyun Amirjanyan, (amirjanyan@gmail.com) - - Based on code initially developed by: Einar Lielmanis, - https://beautifier.io/ - - Usage: - css_beautify(source_text); - css_beautify(source_text, options); - - The options are (default in brackets): - indent_size (4) — indentation size, - indent_char (space) — character to indent with, - selector_separator_newline (true) - separate selectors with newline or - not (e.g. "a,\nbr" or "a, br") - end_with_newline (false) - end with a newline - newline_between_rules (true) - add a new line after every css rule - space_around_selector_separator (false) - ensure space around selector separators: - '>', '+', '~' (e.g. "a>b" -> "a > b") - e.g - - css_beautify(css_source_text, { - 'indent_size': 1, - 'indent_char': '\t', - 'selector_separator': ' ', - 'end_with_newline': false, - 'newline_between_rules': true, - 'space_around_selector_separator': true - }); -*/ - -// http://www.w3.org/TR/CSS21/syndata.html#tokenization -// http://www.w3.org/TR/css3-syntax/ - -var legacy_beautify_css; -/******/ (function() { // webpackBootstrap -/******/ "use strict"; -/******/ var __webpack_modules__ = ([ -/* 0 */, -/* 1 */, -/* 2 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function OutputLine(parent) { - this.__parent = parent; - this.__character_count = 0; - // use indent_count as a marker for this.__lines that have preserved indentation - this.__indent_count = -1; - this.__alignment_count = 0; - this.__wrap_point_index = 0; - this.__wrap_point_character_count = 0; - this.__wrap_point_indent_count = -1; - this.__wrap_point_alignment_count = 0; - - this.__items = []; -} - -OutputLine.prototype.clone_empty = function() { - var line = new OutputLine(this.__parent); - line.set_indent(this.__indent_count, this.__alignment_count); - return line; -}; - -OutputLine.prototype.item = function(index) { - if (index < 0) { - return this.__items[this.__items.length + index]; - } else { - return this.__items[index]; - } -}; - -OutputLine.prototype.has_match = function(pattern) { - for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) { - if (this.__items[lastCheckedOutput].match(pattern)) { - return true; - } - } - return false; -}; - -OutputLine.prototype.set_indent = function(indent, alignment) { - if (this.is_empty()) { - this.__indent_count = indent || 0; - this.__alignment_count = alignment || 0; - this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count); - } -}; - -OutputLine.prototype._set_wrap_point = function() { - if (this.__parent.wrap_line_length) { - this.__wrap_point_index = this.__items.length; - this.__wrap_point_character_count = this.__character_count; - this.__wrap_point_indent_count = this.__parent.next_line.__indent_count; - this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count; - } -}; - -OutputLine.prototype._should_wrap = function() { - return this.__wrap_point_index && - this.__character_count > this.__parent.wrap_line_length && - this.__wrap_point_character_count > this.__parent.next_line.__character_count; -}; - -OutputLine.prototype._allow_wrap = function() { - if (this._should_wrap()) { - this.__parent.add_new_line(); - var next = this.__parent.current_line; - next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count); - next.__items = this.__items.slice(this.__wrap_point_index); - this.__items = this.__items.slice(0, this.__wrap_point_index); - - next.__character_count += this.__character_count - this.__wrap_point_character_count; - this.__character_count = this.__wrap_point_character_count; - - if (next.__items[0] === " ") { - next.__items.splice(0, 1); - next.__character_count -= 1; - } - return true; - } - return false; -}; - -OutputLine.prototype.is_empty = function() { - return this.__items.length === 0; -}; - -OutputLine.prototype.last = function() { - if (!this.is_empty()) { - return this.__items[this.__items.length - 1]; - } else { - return null; - } -}; - -OutputLine.prototype.push = function(item) { - this.__items.push(item); - var last_newline_index = item.lastIndexOf('\n'); - if (last_newline_index !== -1) { - this.__character_count = item.length - last_newline_index; - } else { - this.__character_count += item.length; - } -}; - -OutputLine.prototype.pop = function() { - var item = null; - if (!this.is_empty()) { - item = this.__items.pop(); - this.__character_count -= item.length; - } - return item; -}; - - -OutputLine.prototype._remove_indent = function() { - if (this.__indent_count > 0) { - this.__indent_count -= 1; - this.__character_count -= this.__parent.indent_size; - } -}; - -OutputLine.prototype._remove_wrap_indent = function() { - if (this.__wrap_point_indent_count > 0) { - this.__wrap_point_indent_count -= 1; - } -}; -OutputLine.prototype.trim = function() { - while (this.last() === ' ') { - this.__items.pop(); - this.__character_count -= 1; - } -}; - -OutputLine.prototype.toString = function() { - var result = ''; - if (this.is_empty()) { - if (this.__parent.indent_empty_lines) { - result = this.__parent.get_indent_string(this.__indent_count); - } - } else { - result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count); - result += this.__items.join(''); - } - return result; -}; - -function IndentStringCache(options, baseIndentString) { - this.__cache = ['']; - this.__indent_size = options.indent_size; - this.__indent_string = options.indent_char; - if (!options.indent_with_tabs) { - this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char); - } - - // Set to null to continue support for auto detection of base indent - baseIndentString = baseIndentString || ''; - if (options.indent_level > 0) { - baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string); - } - - this.__base_string = baseIndentString; - this.__base_string_length = baseIndentString.length; -} - -IndentStringCache.prototype.get_indent_size = function(indent, column) { - var result = this.__base_string_length; - column = column || 0; - if (indent < 0) { - result = 0; - } - result += indent * this.__indent_size; - result += column; - return result; -}; - -IndentStringCache.prototype.get_indent_string = function(indent_level, column) { - var result = this.__base_string; - column = column || 0; - if (indent_level < 0) { - indent_level = 0; - result = ''; - } - column += indent_level * this.__indent_size; - this.__ensure_cache(column); - result += this.__cache[column]; - return result; -}; - -IndentStringCache.prototype.__ensure_cache = function(column) { - while (column >= this.__cache.length) { - this.__add_column(); - } -}; - -IndentStringCache.prototype.__add_column = function() { - var column = this.__cache.length; - var indent = 0; - var result = ''; - if (this.__indent_size && column >= this.__indent_size) { - indent = Math.floor(column / this.__indent_size); - column -= indent * this.__indent_size; - result = new Array(indent + 1).join(this.__indent_string); - } - if (column) { - result += new Array(column + 1).join(' '); - } - - this.__cache.push(result); -}; - -function Output(options, baseIndentString) { - this.__indent_cache = new IndentStringCache(options, baseIndentString); - this.raw = false; - this._end_with_newline = options.end_with_newline; - this.indent_size = options.indent_size; - this.wrap_line_length = options.wrap_line_length; - this.indent_empty_lines = options.indent_empty_lines; - this.__lines = []; - this.previous_line = null; - this.current_line = null; - this.next_line = new OutputLine(this); - this.space_before_token = false; - this.non_breaking_space = false; - this.previous_token_wrapped = false; - // initialize - this.__add_outputline(); -} - -Output.prototype.__add_outputline = function() { - this.previous_line = this.current_line; - this.current_line = this.next_line.clone_empty(); - this.__lines.push(this.current_line); -}; - -Output.prototype.get_line_number = function() { - return this.__lines.length; -}; - -Output.prototype.get_indent_string = function(indent, column) { - return this.__indent_cache.get_indent_string(indent, column); -}; - -Output.prototype.get_indent_size = function(indent, column) { - return this.__indent_cache.get_indent_size(indent, column); -}; - -Output.prototype.is_empty = function() { - return !this.previous_line && this.current_line.is_empty(); -}; - -Output.prototype.add_new_line = function(force_newline) { - // never newline at the start of file - // otherwise, newline only if we didn't just add one or we're forced - if (this.is_empty() || - (!force_newline && this.just_added_newline())) { - return false; - } - - // if raw output is enabled, don't print additional newlines, - // but still return True as though you had - if (!this.raw) { - this.__add_outputline(); - } - return true; -}; - -Output.prototype.get_code = function(eol) { - this.trim(true); - - // handle some edge cases where the last tokens - // has text that ends with newline(s) - var last_item = this.current_line.pop(); - if (last_item) { - if (last_item[last_item.length - 1] === '\n') { - last_item = last_item.replace(/\n+$/g, ''); - } - this.current_line.push(last_item); - } - - if (this._end_with_newline) { - this.__add_outputline(); - } - - var sweet_code = this.__lines.join('\n'); - - if (eol !== '\n') { - sweet_code = sweet_code.replace(/[\n]/g, eol); - } - return sweet_code; -}; - -Output.prototype.set_wrap_point = function() { - this.current_line._set_wrap_point(); -}; - -Output.prototype.set_indent = function(indent, alignment) { - indent = indent || 0; - alignment = alignment || 0; - - // Next line stores alignment values - this.next_line.set_indent(indent, alignment); - - // Never indent your first output indent at the start of the file - if (this.__lines.length > 1) { - this.current_line.set_indent(indent, alignment); - return true; - } - - this.current_line.set_indent(); - return false; -}; - -Output.prototype.add_raw_token = function(token) { - for (var x = 0; x < token.newlines; x++) { - this.__add_outputline(); - } - this.current_line.set_indent(-1); - this.current_line.push(token.whitespace_before); - this.current_line.push(token.text); - this.space_before_token = false; - this.non_breaking_space = false; - this.previous_token_wrapped = false; -}; - -Output.prototype.add_token = function(printable_token) { - this.__add_space_before_token(); - this.current_line.push(printable_token); - this.space_before_token = false; - this.non_breaking_space = false; - this.previous_token_wrapped = this.current_line._allow_wrap(); -}; - -Output.prototype.__add_space_before_token = function() { - if (this.space_before_token && !this.just_added_newline()) { - if (!this.non_breaking_space) { - this.set_wrap_point(); - } - this.current_line.push(' '); - } -}; - -Output.prototype.remove_indent = function(index) { - var output_length = this.__lines.length; - while (index < output_length) { - this.__lines[index]._remove_indent(); - index++; - } - this.current_line._remove_wrap_indent(); -}; - -Output.prototype.trim = function(eat_newlines) { - eat_newlines = (eat_newlines === undefined) ? false : eat_newlines; - - this.current_line.trim(); - - while (eat_newlines && this.__lines.length > 1 && - this.current_line.is_empty()) { - this.__lines.pop(); - this.current_line = this.__lines[this.__lines.length - 1]; - this.current_line.trim(); - } - - this.previous_line = this.__lines.length > 1 ? - this.__lines[this.__lines.length - 2] : null; -}; - -Output.prototype.just_added_newline = function() { - return this.current_line.is_empty(); -}; - -Output.prototype.just_added_blankline = function() { - return this.is_empty() || - (this.current_line.is_empty() && this.previous_line.is_empty()); -}; - -Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) { - var index = this.__lines.length - 2; - while (index >= 0) { - var potentialEmptyLine = this.__lines[index]; - if (potentialEmptyLine.is_empty()) { - break; - } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 && - potentialEmptyLine.item(-1) !== ends_with) { - this.__lines.splice(index + 1, 0, new OutputLine(this)); - this.previous_line = this.__lines[this.__lines.length - 2]; - break; - } - index--; - } -}; - -module.exports.Output = Output; - - -/***/ }), -/* 3 */, -/* 4 */, -/* 5 */, -/* 6 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function Options(options, merge_child_field) { - this.raw_options = _mergeOpts(options, merge_child_field); - - // Support passing the source text back with no change - this.disabled = this._get_boolean('disabled'); - - this.eol = this._get_characters('eol', 'auto'); - this.end_with_newline = this._get_boolean('end_with_newline'); - this.indent_size = this._get_number('indent_size', 4); - this.indent_char = this._get_characters('indent_char', ' '); - this.indent_level = this._get_number('indent_level'); - - this.preserve_newlines = this._get_boolean('preserve_newlines', true); - this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786); - if (!this.preserve_newlines) { - this.max_preserve_newlines = 0; - } - - this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t'); - if (this.indent_with_tabs) { - this.indent_char = '\t'; - - // indent_size behavior changed after 1.8.6 - // It used to be that indent_size would be - // set to 1 for indent_with_tabs. That is no longer needed and - // actually doesn't make sense - why not use spaces? Further, - // that might produce unexpected behavior - tabs being used - // for single-column alignment. So, when indent_with_tabs is true - // and indent_size is 1, reset indent_size to 4. - if (this.indent_size === 1) { - this.indent_size = 4; - } - } - - // Backwards compat with 1.3.x - this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char')); - - this.indent_empty_lines = this._get_boolean('indent_empty_lines'); - - // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty', 'angular'] - // For now, 'auto' = all off for javascript, all except angular on for html (and inline javascript/css). - // other values ignored - this.templating = this._get_selection_list('templating', ['auto', 'none', 'angular', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']); -} - -Options.prototype._get_array = function(name, default_value) { - var option_value = this.raw_options[name]; - var result = default_value || []; - if (typeof option_value === 'object') { - if (option_value !== null && typeof option_value.concat === 'function') { - result = option_value.concat(); - } - } else if (typeof option_value === 'string') { - result = option_value.split(/[^a-zA-Z0-9_\/\-]+/); - } - return result; -}; - -Options.prototype._get_boolean = function(name, default_value) { - var option_value = this.raw_options[name]; - var result = option_value === undefined ? !!default_value : !!option_value; - return result; -}; - -Options.prototype._get_characters = function(name, default_value) { - var option_value = this.raw_options[name]; - var result = default_value || ''; - if (typeof option_value === 'string') { - result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t'); - } - return result; -}; - -Options.prototype._get_number = function(name, default_value) { - var option_value = this.raw_options[name]; - default_value = parseInt(default_value, 10); - if (isNaN(default_value)) { - default_value = 0; - } - var result = parseInt(option_value, 10); - if (isNaN(result)) { - result = default_value; - } - return result; -}; - -Options.prototype._get_selection = function(name, selection_list, default_value) { - var result = this._get_selection_list(name, selection_list, default_value); - if (result.length !== 1) { - throw new Error( - "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" + - selection_list + "\nYou passed in: '" + this.raw_options[name] + "'"); - } - - return result[0]; -}; - - -Options.prototype._get_selection_list = function(name, selection_list, default_value) { - if (!selection_list || selection_list.length === 0) { - throw new Error("Selection list cannot be empty."); - } - - default_value = default_value || [selection_list[0]]; - if (!this._is_valid_selection(default_value, selection_list)) { - throw new Error("Invalid Default Value!"); - } - - var result = this._get_array(name, default_value); - if (!this._is_valid_selection(result, selection_list)) { - throw new Error( - "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" + - selection_list + "\nYou passed in: '" + this.raw_options[name] + "'"); - } - - return result; -}; - -Options.prototype._is_valid_selection = function(result, selection_list) { - return result.length && selection_list.length && - !result.some(function(item) { return selection_list.indexOf(item) === -1; }); -}; - - -// merges child options up with the parent options object -// Example: obj = {a: 1, b: {a: 2}} -// mergeOpts(obj, 'b') -// -// Returns: {a: 2} -function _mergeOpts(allOptions, childFieldName) { - var finalOpts = {}; - allOptions = _normalizeOpts(allOptions); - var name; - - for (name in allOptions) { - if (name !== childFieldName) { - finalOpts[name] = allOptions[name]; - } - } - - //merge in the per type settings for the childFieldName - if (childFieldName && allOptions[childFieldName]) { - for (name in allOptions[childFieldName]) { - finalOpts[name] = allOptions[childFieldName][name]; - } - } - return finalOpts; -} - -function _normalizeOpts(options) { - var convertedOpts = {}; - var key; - - for (key in options) { - var newKey = key.replace(/-/g, "_"); - convertedOpts[newKey] = options[key]; - } - return convertedOpts; -} - -module.exports.Options = Options; -module.exports.normalizeOpts = _normalizeOpts; -module.exports.mergeOpts = _mergeOpts; - - -/***/ }), -/* 7 */, -/* 8 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky'); - -function InputScanner(input_string) { - this.__input = input_string || ''; - this.__input_length = this.__input.length; - this.__position = 0; -} - -InputScanner.prototype.restart = function() { - this.__position = 0; -}; - -InputScanner.prototype.back = function() { - if (this.__position > 0) { - this.__position -= 1; - } -}; - -InputScanner.prototype.hasNext = function() { - return this.__position < this.__input_length; -}; - -InputScanner.prototype.next = function() { - var val = null; - if (this.hasNext()) { - val = this.__input.charAt(this.__position); - this.__position += 1; - } - return val; -}; - -InputScanner.prototype.peek = function(index) { - var val = null; - index = index || 0; - index += this.__position; - if (index >= 0 && index < this.__input_length) { - val = this.__input.charAt(index); - } - return val; -}; - -// This is a JavaScript only helper function (not in python) -// Javascript doesn't have a match method -// and not all implementation support "sticky" flag. -// If they do not support sticky then both this.match() and this.test() method -// must get the match and check the index of the match. -// If sticky is supported and set, this method will use it. -// Otherwise it will check that global is set, and fall back to the slower method. -InputScanner.prototype.__match = function(pattern, index) { - pattern.lastIndex = index; - var pattern_match = pattern.exec(this.__input); - - if (pattern_match && !(regexp_has_sticky && pattern.sticky)) { - if (pattern_match.index !== index) { - pattern_match = null; - } - } - - return pattern_match; -}; - -InputScanner.prototype.test = function(pattern, index) { - index = index || 0; - index += this.__position; - - if (index >= 0 && index < this.__input_length) { - return !!this.__match(pattern, index); - } else { - return false; - } -}; - -InputScanner.prototype.testChar = function(pattern, index) { - // test one character regex match - var val = this.peek(index); - pattern.lastIndex = 0; - return val !== null && pattern.test(val); -}; - -InputScanner.prototype.match = function(pattern) { - var pattern_match = this.__match(pattern, this.__position); - if (pattern_match) { - this.__position += pattern_match[0].length; - } else { - pattern_match = null; - } - return pattern_match; -}; - -InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) { - var val = ''; - var match; - if (starting_pattern) { - match = this.match(starting_pattern); - if (match) { - val += match[0]; - } - } - if (until_pattern && (match || !starting_pattern)) { - val += this.readUntil(until_pattern, until_after); - } - return val; -}; - -InputScanner.prototype.readUntil = function(pattern, until_after) { - var val = ''; - var match_index = this.__position; - pattern.lastIndex = this.__position; - var pattern_match = pattern.exec(this.__input); - if (pattern_match) { - match_index = pattern_match.index; - if (until_after) { - match_index += pattern_match[0].length; - } - } else { - match_index = this.__input_length; - } - - val = this.__input.substring(this.__position, match_index); - this.__position = match_index; - return val; -}; - -InputScanner.prototype.readUntilAfter = function(pattern) { - return this.readUntil(pattern, true); -}; - -InputScanner.prototype.get_regexp = function(pattern, match_from) { - var result = null; - var flags = 'g'; - if (match_from && regexp_has_sticky) { - flags = 'y'; - } - // strings are converted to regexp - if (typeof pattern === "string" && pattern !== '') { - // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags); - result = new RegExp(pattern, flags); - } else if (pattern) { - result = new RegExp(pattern.source, flags); - } - return result; -}; - -InputScanner.prototype.get_literal_regexp = function(literal_string) { - return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')); -}; - -/* css beautifier legacy helpers */ -InputScanner.prototype.peekUntilAfter = function(pattern) { - var start = this.__position; - var val = this.readUntilAfter(pattern); - this.__position = start; - return val; -}; - -InputScanner.prototype.lookBack = function(testVal) { - var start = this.__position - 1; - return start >= testVal.length && this.__input.substring(start - testVal.length, start) - .toLowerCase() === testVal; -}; - -module.exports.InputScanner = InputScanner; - - -/***/ }), -/* 9 */, -/* 10 */, -/* 11 */, -/* 12 */, -/* 13 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function Directives(start_block_pattern, end_block_pattern) { - start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source; - end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source; - this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g'); - this.__directive_pattern = / (\w+)[:](\w+)/g; - - this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g'); -} - -Directives.prototype.get_directives = function(text) { - if (!text.match(this.__directives_block_pattern)) { - return null; - } - - var directives = {}; - this.__directive_pattern.lastIndex = 0; - var directive_match = this.__directive_pattern.exec(text); - - while (directive_match) { - directives[directive_match[1]] = directive_match[2]; - directive_match = this.__directive_pattern.exec(text); - } - - return directives; -}; - -Directives.prototype.readIgnored = function(input) { - return input.readUntilAfter(this.__directives_end_ignore_pattern); -}; - - -module.exports.Directives = Directives; - - -/***/ }), -/* 14 */, -/* 15 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -var Beautifier = (__webpack_require__(16).Beautifier), - Options = (__webpack_require__(17).Options); - -function css_beautify(source_text, options) { - var beautifier = new Beautifier(source_text, options); - return beautifier.beautify(); -} - -module.exports = css_beautify; -module.exports.defaultOptions = function() { - return new Options(); -}; - - -/***/ }), -/* 16 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -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(/\/\*/, /\*\//); - -var lineBreak = /\r\n|[\r\n]/; -var allLineBreaks = /\r\n|[\r\n]/g; - -// tokenizer -var whitespaceChar = /\s/; -var whitespacePattern = /(?:\s|\n)+/g; -var block_comment_pattern = /\/\*(?:[\s\S]*?)((?:\*\/)|$)/g; -var comment_pattern = /\/\/(?:[^\n\r\u2028\u2029]*)/g; - -function Beautifier(source_text, options) { - this._source_text = source_text || ''; - // Allow the setting of language/file-type specific options - // with inheritance of overall settings - this._options = new Options(options); - this._ch = null; - this._input = null; - - // https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule - this.NESTED_AT_RULE = { - "page": true, - "font-face": true, - "keyframes": true, - // also in CONDITIONAL_GROUP_RULE below - "media": true, - "supports": true, - "document": true - }; - this.CONDITIONAL_GROUP_RULE = { - "media": true, - "supports": true, - "document": true - }; - this.NON_SEMICOLON_NEWLINE_PROPERTY = [ - "grid-template-areas", - "grid-template" - ]; - -} - -Beautifier.prototype.eatString = function(endChars) { - var result = ''; - this._ch = this._input.next(); - while (this._ch) { - result += this._ch; - if (this._ch === "\\") { - result += this._input.next(); - } else if (endChars.indexOf(this._ch) !== -1 || this._ch === "\n") { - break; - } - this._ch = this._input.next(); - } - return result; -}; - -// Skips any white space in the source text from the current position. -// When allowAtLeastOneNewLine is true, will output new lines for each -// newline character found; if the user has preserve_newlines off, only -// the first newline will be output -Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) { - var result = whitespaceChar.test(this._input.peek()); - var newline_count = 0; - while (whitespaceChar.test(this._input.peek())) { - this._ch = this._input.next(); - if (allowAtLeastOneNewLine && this._ch === '\n') { - if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) { - newline_count++; - this._output.add_new_line(true); - } - } - } - return result; -}; - -// Nested pseudo-class if we are insideRule -// and the next special character found opens -// a new block -Beautifier.prototype.foundNestedPseudoClass = function() { - var openParen = 0; - var i = 1; - var ch = this._input.peek(i); - while (ch) { - if (ch === "{") { - return true; - } else if (ch === '(') { - // pseudoclasses can contain () - openParen += 1; - } else if (ch === ')') { - if (openParen === 0) { - return false; - } - openParen -= 1; - } else if (ch === ";" || ch === "}") { - return false; - } - i++; - ch = this._input.peek(i); - } - return false; -}; - -Beautifier.prototype.print_string = function(output_string) { - this._output.set_indent(this._indentLevel); - this._output.non_breaking_space = true; - this._output.add_token(output_string); -}; - -Beautifier.prototype.preserveSingleSpace = function(isAfterSpace) { - if (isAfterSpace) { - this._output.space_before_token = true; - } -}; - -Beautifier.prototype.indent = function() { - this._indentLevel++; -}; - -Beautifier.prototype.outdent = function() { - if (this._indentLevel > 0) { - this._indentLevel--; - } -}; - -/*_____________________--------------------_____________________*/ - -Beautifier.prototype.beautify = function() { - if (this._options.disabled) { - return this._source_text; - } - - var source_text = this._source_text; - var eol = this._options.eol; - if (eol === 'auto') { - eol = '\n'; - if (source_text && lineBreak.test(source_text || '')) { - eol = source_text.match(lineBreak)[0]; - } - } - - - // HACK: newline parsing inconsistent. This brute force normalizes the this._input. - source_text = source_text.replace(allLineBreaks, '\n'); - - // reset - var baseIndentString = source_text.match(/^[\t ]*/)[0]; - - this._output = new Output(this._options, baseIndentString); - this._input = new InputScanner(source_text); - this._indentLevel = 0; - this._nestedLevel = 0; - - this._ch = null; - var parenLevel = 0; - - var insideRule = false; - // This is the value side of a property value pair (blue in the following ex) - // label { content: blue } - var insidePropertyValue = false; - var enteringConditionalGroup = false; - var insideNonNestedAtRule = false; - var insideScssMap = false; - var topCharacter = this._ch; - var insideNonSemiColonValues = false; - var whitespace; - var isAfterSpace; - var previous_ch; - - while (true) { - whitespace = this._input.read(whitespacePattern); - isAfterSpace = whitespace !== ''; - previous_ch = topCharacter; - this._ch = this._input.next(); - if (this._ch === '\\' && this._input.hasNext()) { - this._ch += this._input.next(); - } - topCharacter = this._ch; - - if (!this._ch) { - break; - } else if (this._ch === '/' && this._input.peek() === '*') { - // /* css comment */ - // Always start block comments on a new line. - // This handles scenarios where a block comment immediately - // follows a property definition on the same line or where - // minified code is being beautified. - this._output.add_new_line(); - this._input.back(); - - var comment = this._input.read(block_comment_pattern); - - // Handle ignore directive - var directives = directives_core.get_directives(comment); - if (directives && directives.ignore === 'start') { - comment += directives_core.readIgnored(this._input); - } - - this.print_string(comment); - - // Ensures any new lines following the comment are preserved - this.eatWhitespace(true); - - // Block comments are followed by a new line so they don't - // share a line with other properties - this._output.add_new_line(); - } else if (this._ch === '/' && this._input.peek() === '/') { - // // single line comment - // Preserves the space before a comment - // on the same line as a rule - this._output.space_before_token = true; - this._input.back(); - this.print_string(this._input.read(comment_pattern)); - - // Ensures any new lines following the comment are preserved - this.eatWhitespace(true); - } else if (this._ch === '$') { - this.preserveSingleSpace(isAfterSpace); - - 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; - } - - // 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 { - this.print_string(this._ch); - - // strip trailing space, if present, for hash property checks - var variableOrRule = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g); - - if (variableOrRule.match(/[ :]$/)) { - // we have a variable or pseudo-class, add it and insert one space before continuing - variableOrRule = this.eatString(": ").replace(/\s+$/, ''); - this.print_string(variableOrRule); - this._output.space_before_token = true; - } - - // might be less variable - if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) { - insidePropertyValue = true; - this.indent(); - - // 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 a non-nested at-rule - } else if (parenLevel === 0 && !insidePropertyValue) { - insideNonNestedAtRule = true; - } - } - } else if (this._ch === '#' && this._input.peek() === '{') { - this.preserveSingleSpace(isAfterSpace); - this.print_string(this._ch + this.eatString('}')); - } else if (this._ch === '{') { - if (insidePropertyValue) { - insidePropertyValue = false; - this.outdent(); - } - - // non nested at rule becomes nested - insideNonNestedAtRule = false; - - // when entering conditional groups, only rulesets are allowed - if (enteringConditionalGroup) { - enteringConditionalGroup = false; - insideRule = (this._indentLevel >= this._nestedLevel); - } else { - // otherwise, declarations are also allowed - insideRule = (this._indentLevel >= this._nestedLevel - 1); - } - if (this._options.newline_between_rules && insideRule) { - if (this._output.previous_line && this._output.previous_line.item(-1) !== '{') { - this._output.ensure_empty_line_above('/', ','); - } - } - - this._output.space_before_token = true; - - // The difference in print_string and indent order is necessary to indent the '{' correctly - if (this._options.brace_style === 'expand') { - this._output.add_new_line(); - this.print_string(this._ch); - this.indent(); - this._output.set_indent(this._indentLevel); - } else { - // 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); - } - - this.eatWhitespace(true); - this._output.add_new_line(); - } else if (this._ch === '}') { - this.outdent(); - this._output.add_new_line(); - if (previous_ch === '{') { - this._output.trim(true); - } - - if (insidePropertyValue) { - this.outdent(); - insidePropertyValue = false; - } - this.print_string(this._ch); - insideRule = false; - if (this._nestedLevel) { - this._nestedLevel--; - } - - this.eatWhitespace(true); - this._output.add_new_line(); - - if (this._options.newline_between_rules && !this._output.just_added_blankline()) { - if (this._input.peek() !== '}') { - 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("(") && !insideNonNestedAtRule && parenLevel === 0) { - // 'property: value' delimiter - // which could be in a conditional group query - - this.print_string(':'); - if (!insidePropertyValue) { - insidePropertyValue = true; - this._output.space_before_token = true; - this.eatWhitespace(true); - this.indent(); - } - } else { - // sass/less parent reference don't use a space - // sass nested pseudo-class don't use a space - - // preserve space before pseudoclasses/pseudoelements, as it means "in any child" - if (this._input.lookBack(" ")) { - this._output.space_before_token = true; - } - if (this._input.peek() === ":") { - // pseudo-element - this._ch = this._input.next(); - this.print_string("::"); - } else { - // pseudo-class - this.print_string(':'); - } - } - } else if (this._ch === '"' || this._ch === '\'') { - 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(); - insidePropertyValue = false; - } - insideNonNestedAtRule = false; - this.print_string(this._ch); - this.eatWhitespace(true); - - // This maintains single line comments on the same - // line. Block comments are also affected, but - // a new line is always output before one inside - // that section - if (this._input.peek() !== '/') { - this._output.add_new_line(); - } - } else { - this.print_string(this._ch); - this.eatWhitespace(true); - this._output.space_before_token = true; - } - } else if (this._ch === '(') { // may be a url - if (this._input.lookBack("url")) { - this.print_string(this._ch); - this.eatWhitespace(); - parenLevel++; - this.indent(); - this._ch = this._input.next(); - if (this._ch === ')' || this._ch === '"' || this._ch === '\'') { - this._input.back(); - } else if (this._ch) { - this.print_string(this._ch + this.eatString(')')); - if (parenLevel) { - parenLevel--; - this.outdent(); - } - } - } else { - 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); - - // 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 || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) { - this._output.add_new_line(); - } else { - this._output.space_before_token = true; - } - } else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) { - //handle combinator spacing - if (this._options.space_around_combinator) { - this._output.space_before_token = true; - this.print_string(this._ch); - this._output.space_before_token = true; - } else { - this.print_string(this._ch); - this.eatWhitespace(); - // squash extra whitespace - if (this._ch && whitespaceChar.test(this._ch)) { - this._ch = ''; - } - } - } else if (this._ch === ']') { - this.print_string(this._ch); - } else if (this._ch === '[') { - this.preserveSingleSpace(isAfterSpace); - this.print_string(this._ch); - } else if (this._ch === '=') { // no whitespace before or after - this.eatWhitespace(); - this.print_string('='); - if (whitespaceChar.test(this._ch)) { - this._ch = ''; - } - } else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important - this._output.space_before_token = true; - this.print_string(this._ch); - } else { - 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(); - } - } - } - - var sweetCode = this._output.get_code(eol); - - return sweetCode; -}; - -module.exports.Beautifier = Beautifier; - - -/***/ }), -/* 17 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -var BaseOptions = (__webpack_require__(6).Options); - -function Options(options) { - BaseOptions.call(this, options, 'css'); - - this.selector_separator_newline = this._get_boolean('selector_separator_newline', true); - this.newline_between_rules = this._get_boolean('newline_between_rules', true); - var space_around_selector_separator = this._get_boolean('space_around_selector_separator'); - this.space_around_combinator = this._get_boolean('space_around_combinator') || space_around_selector_separator; - - var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']); - this.brace_style = 'collapse'; - for (var bs = 0; bs < brace_style_split.length; bs++) { - if (brace_style_split[bs] !== 'expand') { - // default to collapse, as only collapse|expand is implemented for now - this.brace_style = 'collapse'; - } else { - this.brace_style = brace_style_split[bs]; - } - } -} -Options.prototype = new BaseOptions(); - - - -module.exports.Options = Options; - - -/***/ }) -/******/ ]); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ -/******/ // startup -/******/ // Load entry module and return exports -/******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __webpack_require__(15); -/******/ legacy_beautify_css = __webpack_exports__; -/******/ -/******/ })() -; - -export var css_beautify = legacy_beautify_css; \ No newline at end of file diff --git a/src/beautify/esm/beautify-html.js b/src/beautify/esm/beautify-html.js deleted file mode 100644 index 6b87d69..0000000 --- a/src/beautify/esm/beautify-html.js +++ /dev/null @@ -1,3212 +0,0 @@ -// copied from js-beautify/js/lib/beautify-html.js -// version: 1.15.4 -/* AUTO-GENERATED. DO NOT MODIFY. */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. - - - Style HTML ---------------- - - Written by Nochum Sossonko, (nsossonko@hotmail.com) - - Based on code initially developed by: Einar Lielmanis, - https://beautifier.io/ - - Usage: - style_html(html_source); - - style_html(html_source, options); - - The options are: - indent_inner_html (default false) — indent and sections, - indent_size (default 4) — indentation size, - indent_char (default space) — character to indent with, - wrap_line_length (default 250) - maximum amount of characters per line (0 = disable) - brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none" - 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. - inline (defaults to inline tags) - list of tags to be considered inline tags - unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted - content_unformatted (defaults to ["pre", "textarea"] tags) - list of tags, whose content shouldn't be reformatted - indent_scripts (default normal) - "keep"|"separate"|"normal" - preserve_newlines (default true) - whether existing line breaks before elements should be preserved - Only works before elements, not inside tags or for text. - max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk - indent_handlebars (default false) - format and indent {{#foo}} and {{/foo}} - end_with_newline (false) - end with a newline - extra_liners (default [head,body,/html]) -List of tags that should have an extra newline before them. - - e.g. - - style_html(html_source, { - 'indent_inner_html': false, - 'indent_size': 2, - 'indent_char': ' ', - 'wrap_line_length': 78, - 'brace_style': 'expand', - 'preserve_newlines': true, - 'max_preserve_newlines': 5, - 'indent_handlebars': false, - 'extra_liners': ['/html'] - }); -*/ - -import { js_beautify } from "./beautify"; -import { css_beautify } from "./beautify-css"; - -var legacy_beautify_html; -/******/ (function() { // webpackBootstrap -/******/ "use strict"; -/******/ var __webpack_modules__ = ([ -/* 0 */, -/* 1 */, -/* 2 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function OutputLine(parent) { - this.__parent = parent; - this.__character_count = 0; - // use indent_count as a marker for this.__lines that have preserved indentation - this.__indent_count = -1; - this.__alignment_count = 0; - this.__wrap_point_index = 0; - this.__wrap_point_character_count = 0; - this.__wrap_point_indent_count = -1; - this.__wrap_point_alignment_count = 0; - - this.__items = []; -} - -OutputLine.prototype.clone_empty = function() { - var line = new OutputLine(this.__parent); - line.set_indent(this.__indent_count, this.__alignment_count); - return line; -}; - -OutputLine.prototype.item = function(index) { - if (index < 0) { - return this.__items[this.__items.length + index]; - } else { - return this.__items[index]; - } -}; - -OutputLine.prototype.has_match = function(pattern) { - for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) { - if (this.__items[lastCheckedOutput].match(pattern)) { - return true; - } - } - return false; -}; - -OutputLine.prototype.set_indent = function(indent, alignment) { - if (this.is_empty()) { - this.__indent_count = indent || 0; - this.__alignment_count = alignment || 0; - this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count); - } -}; - -OutputLine.prototype._set_wrap_point = function() { - if (this.__parent.wrap_line_length) { - this.__wrap_point_index = this.__items.length; - this.__wrap_point_character_count = this.__character_count; - this.__wrap_point_indent_count = this.__parent.next_line.__indent_count; - this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count; - } -}; - -OutputLine.prototype._should_wrap = function() { - return this.__wrap_point_index && - this.__character_count > this.__parent.wrap_line_length && - this.__wrap_point_character_count > this.__parent.next_line.__character_count; -}; - -OutputLine.prototype._allow_wrap = function() { - if (this._should_wrap()) { - this.__parent.add_new_line(); - var next = this.__parent.current_line; - next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count); - next.__items = this.__items.slice(this.__wrap_point_index); - this.__items = this.__items.slice(0, this.__wrap_point_index); - - next.__character_count += this.__character_count - this.__wrap_point_character_count; - this.__character_count = this.__wrap_point_character_count; - - if (next.__items[0] === " ") { - next.__items.splice(0, 1); - next.__character_count -= 1; - } - return true; - } - return false; -}; - -OutputLine.prototype.is_empty = function() { - return this.__items.length === 0; -}; - -OutputLine.prototype.last = function() { - if (!this.is_empty()) { - return this.__items[this.__items.length - 1]; - } else { - return null; - } -}; - -OutputLine.prototype.push = function(item) { - this.__items.push(item); - var last_newline_index = item.lastIndexOf('\n'); - if (last_newline_index !== -1) { - this.__character_count = item.length - last_newline_index; - } else { - this.__character_count += item.length; - } -}; - -OutputLine.prototype.pop = function() { - var item = null; - if (!this.is_empty()) { - item = this.__items.pop(); - this.__character_count -= item.length; - } - return item; -}; - - -OutputLine.prototype._remove_indent = function() { - if (this.__indent_count > 0) { - this.__indent_count -= 1; - this.__character_count -= this.__parent.indent_size; - } -}; - -OutputLine.prototype._remove_wrap_indent = function() { - if (this.__wrap_point_indent_count > 0) { - this.__wrap_point_indent_count -= 1; - } -}; -OutputLine.prototype.trim = function() { - while (this.last() === ' ') { - this.__items.pop(); - this.__character_count -= 1; - } -}; - -OutputLine.prototype.toString = function() { - var result = ''; - if (this.is_empty()) { - if (this.__parent.indent_empty_lines) { - result = this.__parent.get_indent_string(this.__indent_count); - } - } else { - result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count); - result += this.__items.join(''); - } - return result; -}; - -function IndentStringCache(options, baseIndentString) { - this.__cache = ['']; - this.__indent_size = options.indent_size; - this.__indent_string = options.indent_char; - if (!options.indent_with_tabs) { - this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char); - } - - // Set to null to continue support for auto detection of base indent - baseIndentString = baseIndentString || ''; - if (options.indent_level > 0) { - baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string); - } - - this.__base_string = baseIndentString; - this.__base_string_length = baseIndentString.length; -} - -IndentStringCache.prototype.get_indent_size = function(indent, column) { - var result = this.__base_string_length; - column = column || 0; - if (indent < 0) { - result = 0; - } - result += indent * this.__indent_size; - result += column; - return result; -}; - -IndentStringCache.prototype.get_indent_string = function(indent_level, column) { - var result = this.__base_string; - column = column || 0; - if (indent_level < 0) { - indent_level = 0; - result = ''; - } - column += indent_level * this.__indent_size; - this.__ensure_cache(column); - result += this.__cache[column]; - return result; -}; - -IndentStringCache.prototype.__ensure_cache = function(column) { - while (column >= this.__cache.length) { - this.__add_column(); - } -}; - -IndentStringCache.prototype.__add_column = function() { - var column = this.__cache.length; - var indent = 0; - var result = ''; - if (this.__indent_size && column >= this.__indent_size) { - indent = Math.floor(column / this.__indent_size); - column -= indent * this.__indent_size; - result = new Array(indent + 1).join(this.__indent_string); - } - if (column) { - result += new Array(column + 1).join(' '); - } - - this.__cache.push(result); -}; - -function Output(options, baseIndentString) { - this.__indent_cache = new IndentStringCache(options, baseIndentString); - this.raw = false; - this._end_with_newline = options.end_with_newline; - this.indent_size = options.indent_size; - this.wrap_line_length = options.wrap_line_length; - this.indent_empty_lines = options.indent_empty_lines; - this.__lines = []; - this.previous_line = null; - this.current_line = null; - this.next_line = new OutputLine(this); - this.space_before_token = false; - this.non_breaking_space = false; - this.previous_token_wrapped = false; - // initialize - this.__add_outputline(); -} - -Output.prototype.__add_outputline = function() { - this.previous_line = this.current_line; - this.current_line = this.next_line.clone_empty(); - this.__lines.push(this.current_line); -}; - -Output.prototype.get_line_number = function() { - return this.__lines.length; -}; - -Output.prototype.get_indent_string = function(indent, column) { - return this.__indent_cache.get_indent_string(indent, column); -}; - -Output.prototype.get_indent_size = function(indent, column) { - return this.__indent_cache.get_indent_size(indent, column); -}; - -Output.prototype.is_empty = function() { - return !this.previous_line && this.current_line.is_empty(); -}; - -Output.prototype.add_new_line = function(force_newline) { - // never newline at the start of file - // otherwise, newline only if we didn't just add one or we're forced - if (this.is_empty() || - (!force_newline && this.just_added_newline())) { - return false; - } - - // if raw output is enabled, don't print additional newlines, - // but still return True as though you had - if (!this.raw) { - this.__add_outputline(); - } - return true; -}; - -Output.prototype.get_code = function(eol) { - this.trim(true); - - // handle some edge cases where the last tokens - // has text that ends with newline(s) - var last_item = this.current_line.pop(); - if (last_item) { - if (last_item[last_item.length - 1] === '\n') { - last_item = last_item.replace(/\n+$/g, ''); - } - this.current_line.push(last_item); - } - - if (this._end_with_newline) { - this.__add_outputline(); - } - - var sweet_code = this.__lines.join('\n'); - - if (eol !== '\n') { - sweet_code = sweet_code.replace(/[\n]/g, eol); - } - return sweet_code; -}; - -Output.prototype.set_wrap_point = function() { - this.current_line._set_wrap_point(); -}; - -Output.prototype.set_indent = function(indent, alignment) { - indent = indent || 0; - alignment = alignment || 0; - - // Next line stores alignment values - this.next_line.set_indent(indent, alignment); - - // Never indent your first output indent at the start of the file - if (this.__lines.length > 1) { - this.current_line.set_indent(indent, alignment); - return true; - } - - this.current_line.set_indent(); - return false; -}; - -Output.prototype.add_raw_token = function(token) { - for (var x = 0; x < token.newlines; x++) { - this.__add_outputline(); - } - this.current_line.set_indent(-1); - this.current_line.push(token.whitespace_before); - this.current_line.push(token.text); - this.space_before_token = false; - this.non_breaking_space = false; - this.previous_token_wrapped = false; -}; - -Output.prototype.add_token = function(printable_token) { - this.__add_space_before_token(); - this.current_line.push(printable_token); - this.space_before_token = false; - this.non_breaking_space = false; - this.previous_token_wrapped = this.current_line._allow_wrap(); -}; - -Output.prototype.__add_space_before_token = function() { - if (this.space_before_token && !this.just_added_newline()) { - if (!this.non_breaking_space) { - this.set_wrap_point(); - } - this.current_line.push(' '); - } -}; - -Output.prototype.remove_indent = function(index) { - var output_length = this.__lines.length; - while (index < output_length) { - this.__lines[index]._remove_indent(); - index++; - } - this.current_line._remove_wrap_indent(); -}; - -Output.prototype.trim = function(eat_newlines) { - eat_newlines = (eat_newlines === undefined) ? false : eat_newlines; - - this.current_line.trim(); - - while (eat_newlines && this.__lines.length > 1 && - this.current_line.is_empty()) { - this.__lines.pop(); - this.current_line = this.__lines[this.__lines.length - 1]; - this.current_line.trim(); - } - - this.previous_line = this.__lines.length > 1 ? - this.__lines[this.__lines.length - 2] : null; -}; - -Output.prototype.just_added_newline = function() { - return this.current_line.is_empty(); -}; - -Output.prototype.just_added_blankline = function() { - return this.is_empty() || - (this.current_line.is_empty() && this.previous_line.is_empty()); -}; - -Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) { - var index = this.__lines.length - 2; - while (index >= 0) { - var potentialEmptyLine = this.__lines[index]; - if (potentialEmptyLine.is_empty()) { - break; - } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 && - potentialEmptyLine.item(-1) !== ends_with) { - this.__lines.splice(index + 1, 0, new OutputLine(this)); - this.previous_line = this.__lines[this.__lines.length - 2]; - break; - } - index--; - } -}; - -module.exports.Output = Output; - - -/***/ }), -/* 3 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function Token(type, text, newlines, whitespace_before) { - this.type = type; - this.text = text; - - // comments_before are - // comments that have a new line before them - // and may or may not have a newline after - // this is a set of comments before - this.comments_before = null; /* inline comment*/ - - - // this.comments_after = new TokenStream(); // no new line before and newline after - this.newlines = newlines || 0; - this.whitespace_before = whitespace_before || ''; - this.parent = null; - this.next = null; - this.previous = null; - this.opened = null; - this.closed = null; - this.directives = null; -} - - -module.exports.Token = Token; - - -/***/ }), -/* 4 */, -/* 5 */, -/* 6 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function Options(options, merge_child_field) { - this.raw_options = _mergeOpts(options, merge_child_field); - - // Support passing the source text back with no change - this.disabled = this._get_boolean('disabled'); - - this.eol = this._get_characters('eol', 'auto'); - this.end_with_newline = this._get_boolean('end_with_newline'); - this.indent_size = this._get_number('indent_size', 4); - this.indent_char = this._get_characters('indent_char', ' '); - this.indent_level = this._get_number('indent_level'); - - this.preserve_newlines = this._get_boolean('preserve_newlines', true); - this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786); - if (!this.preserve_newlines) { - this.max_preserve_newlines = 0; - } - - this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t'); - if (this.indent_with_tabs) { - this.indent_char = '\t'; - - // indent_size behavior changed after 1.8.6 - // It used to be that indent_size would be - // set to 1 for indent_with_tabs. That is no longer needed and - // actually doesn't make sense - why not use spaces? Further, - // that might produce unexpected behavior - tabs being used - // for single-column alignment. So, when indent_with_tabs is true - // and indent_size is 1, reset indent_size to 4. - if (this.indent_size === 1) { - this.indent_size = 4; - } - } - - // Backwards compat with 1.3.x - this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char')); - - this.indent_empty_lines = this._get_boolean('indent_empty_lines'); - - // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty', 'angular'] - // For now, 'auto' = all off for javascript, all except angular on for html (and inline javascript/css). - // other values ignored - this.templating = this._get_selection_list('templating', ['auto', 'none', 'angular', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']); -} - -Options.prototype._get_array = function(name, default_value) { - var option_value = this.raw_options[name]; - var result = default_value || []; - if (typeof option_value === 'object') { - if (option_value !== null && typeof option_value.concat === 'function') { - result = option_value.concat(); - } - } else if (typeof option_value === 'string') { - result = option_value.split(/[^a-zA-Z0-9_\/\-]+/); - } - return result; -}; - -Options.prototype._get_boolean = function(name, default_value) { - var option_value = this.raw_options[name]; - var result = option_value === undefined ? !!default_value : !!option_value; - return result; -}; - -Options.prototype._get_characters = function(name, default_value) { - var option_value = this.raw_options[name]; - var result = default_value || ''; - if (typeof option_value === 'string') { - result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t'); - } - return result; -}; - -Options.prototype._get_number = function(name, default_value) { - var option_value = this.raw_options[name]; - default_value = parseInt(default_value, 10); - if (isNaN(default_value)) { - default_value = 0; - } - var result = parseInt(option_value, 10); - if (isNaN(result)) { - result = default_value; - } - return result; -}; - -Options.prototype._get_selection = function(name, selection_list, default_value) { - var result = this._get_selection_list(name, selection_list, default_value); - if (result.length !== 1) { - throw new Error( - "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" + - selection_list + "\nYou passed in: '" + this.raw_options[name] + "'"); - } - - return result[0]; -}; - - -Options.prototype._get_selection_list = function(name, selection_list, default_value) { - if (!selection_list || selection_list.length === 0) { - throw new Error("Selection list cannot be empty."); - } - - default_value = default_value || [selection_list[0]]; - if (!this._is_valid_selection(default_value, selection_list)) { - throw new Error("Invalid Default Value!"); - } - - var result = this._get_array(name, default_value); - if (!this._is_valid_selection(result, selection_list)) { - throw new Error( - "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" + - selection_list + "\nYou passed in: '" + this.raw_options[name] + "'"); - } - - return result; -}; - -Options.prototype._is_valid_selection = function(result, selection_list) { - return result.length && selection_list.length && - !result.some(function(item) { return selection_list.indexOf(item) === -1; }); -}; - - -// merges child options up with the parent options object -// Example: obj = {a: 1, b: {a: 2}} -// mergeOpts(obj, 'b') -// -// Returns: {a: 2} -function _mergeOpts(allOptions, childFieldName) { - var finalOpts = {}; - allOptions = _normalizeOpts(allOptions); - var name; - - for (name in allOptions) { - if (name !== childFieldName) { - finalOpts[name] = allOptions[name]; - } - } - - //merge in the per type settings for the childFieldName - if (childFieldName && allOptions[childFieldName]) { - for (name in allOptions[childFieldName]) { - finalOpts[name] = allOptions[childFieldName][name]; - } - } - return finalOpts; -} - -function _normalizeOpts(options) { - var convertedOpts = {}; - var key; - - for (key in options) { - var newKey = key.replace(/-/g, "_"); - convertedOpts[newKey] = options[key]; - } - return convertedOpts; -} - -module.exports.Options = Options; -module.exports.normalizeOpts = _normalizeOpts; -module.exports.mergeOpts = _mergeOpts; - - -/***/ }), -/* 7 */, -/* 8 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky'); - -function InputScanner(input_string) { - this.__input = input_string || ''; - this.__input_length = this.__input.length; - this.__position = 0; -} - -InputScanner.prototype.restart = function() { - this.__position = 0; -}; - -InputScanner.prototype.back = function() { - if (this.__position > 0) { - this.__position -= 1; - } -}; - -InputScanner.prototype.hasNext = function() { - return this.__position < this.__input_length; -}; - -InputScanner.prototype.next = function() { - var val = null; - if (this.hasNext()) { - val = this.__input.charAt(this.__position); - this.__position += 1; - } - return val; -}; - -InputScanner.prototype.peek = function(index) { - var val = null; - index = index || 0; - index += this.__position; - if (index >= 0 && index < this.__input_length) { - val = this.__input.charAt(index); - } - return val; -}; - -// This is a JavaScript only helper function (not in python) -// Javascript doesn't have a match method -// and not all implementation support "sticky" flag. -// If they do not support sticky then both this.match() and this.test() method -// must get the match and check the index of the match. -// If sticky is supported and set, this method will use it. -// Otherwise it will check that global is set, and fall back to the slower method. -InputScanner.prototype.__match = function(pattern, index) { - pattern.lastIndex = index; - var pattern_match = pattern.exec(this.__input); - - if (pattern_match && !(regexp_has_sticky && pattern.sticky)) { - if (pattern_match.index !== index) { - pattern_match = null; - } - } - - return pattern_match; -}; - -InputScanner.prototype.test = function(pattern, index) { - index = index || 0; - index += this.__position; - - if (index >= 0 && index < this.__input_length) { - return !!this.__match(pattern, index); - } else { - return false; - } -}; - -InputScanner.prototype.testChar = function(pattern, index) { - // test one character regex match - var val = this.peek(index); - pattern.lastIndex = 0; - return val !== null && pattern.test(val); -}; - -InputScanner.prototype.match = function(pattern) { - var pattern_match = this.__match(pattern, this.__position); - if (pattern_match) { - this.__position += pattern_match[0].length; - } else { - pattern_match = null; - } - return pattern_match; -}; - -InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) { - var val = ''; - var match; - if (starting_pattern) { - match = this.match(starting_pattern); - if (match) { - val += match[0]; - } - } - if (until_pattern && (match || !starting_pattern)) { - val += this.readUntil(until_pattern, until_after); - } - return val; -}; - -InputScanner.prototype.readUntil = function(pattern, until_after) { - var val = ''; - var match_index = this.__position; - pattern.lastIndex = this.__position; - var pattern_match = pattern.exec(this.__input); - if (pattern_match) { - match_index = pattern_match.index; - if (until_after) { - match_index += pattern_match[0].length; - } - } else { - match_index = this.__input_length; - } - - val = this.__input.substring(this.__position, match_index); - this.__position = match_index; - return val; -}; - -InputScanner.prototype.readUntilAfter = function(pattern) { - return this.readUntil(pattern, true); -}; - -InputScanner.prototype.get_regexp = function(pattern, match_from) { - var result = null; - var flags = 'g'; - if (match_from && regexp_has_sticky) { - flags = 'y'; - } - // strings are converted to regexp - if (typeof pattern === "string" && pattern !== '') { - // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags); - result = new RegExp(pattern, flags); - } else if (pattern) { - result = new RegExp(pattern.source, flags); - } - return result; -}; - -InputScanner.prototype.get_literal_regexp = function(literal_string) { - return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')); -}; - -/* css beautifier legacy helpers */ -InputScanner.prototype.peekUntilAfter = function(pattern) { - var start = this.__position; - var val = this.readUntilAfter(pattern); - this.__position = start; - return val; -}; - -InputScanner.prototype.lookBack = function(testVal) { - var start = this.__position - 1; - return start >= testVal.length && this.__input.substring(start - testVal.length, start) - .toLowerCase() === testVal; -}; - -module.exports.InputScanner = InputScanner; - - -/***/ }), -/* 9 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -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', - RAW: 'TK_RAW', - EOF: 'TK_EOF' -}; - -var Tokenizer = function(input_string, options) { - this._input = new InputScanner(input_string); - this._options = options || {}; - this.__tokens = null; - - this._patterns = {}; - this._patterns.whitespace = new WhitespacePattern(this._input); -}; - -Tokenizer.prototype.tokenize = function() { - this._input.restart(); - this.__tokens = new TokenStream(); - - this._reset(); - - var current; - var previous = new Token(TOKEN.START, ''); - var open_token = null; - var open_stack = []; - var comments = new TokenStream(); - - while (previous.type !== TOKEN.EOF) { - current = this._get_next_token(previous, open_token); - while (this._is_comment(current)) { - comments.add(current); - current = this._get_next_token(previous, open_token); - } - - if (!comments.isEmpty()) { - current.comments_before = comments; - comments = new TokenStream(); - } - - current.parent = open_token; - - if (this._is_opening(current)) { - open_stack.push(open_token); - open_token = current; - } else if (open_token && this._is_closing(current, open_token)) { - current.opened = open_token; - open_token.closed = current; - open_token = open_stack.pop(); - current.parent = open_token; - } - - current.previous = previous; - previous.next = current; - - this.__tokens.add(current); - previous = current; - } - - return this.__tokens; -}; - - -Tokenizer.prototype._is_first_token = function() { - return this.__tokens.isEmpty(); -}; - -Tokenizer.prototype._reset = function() {}; - -Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false - this._readWhitespace(); - var resulting_string = this._input.read(/.+/g); - if (resulting_string) { - return this._create_token(TOKEN.RAW, resulting_string); - } else { - return this._create_token(TOKEN.EOF, ''); - } -}; - -Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false - return false; -}; - -Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false - return false; -}; - -Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false - return false; -}; - -Tokenizer.prototype._create_token = function(type, text) { - var token = new Token(type, text, - this._patterns.whitespace.newline_count, - this._patterns.whitespace.whitespace_before_token); - return token; -}; - -Tokenizer.prototype._readWhitespace = function() { - return this._patterns.whitespace.read(); -}; - - - -module.exports.Tokenizer = Tokenizer; -module.exports.TOKEN = TOKEN; - - -/***/ }), -/* 10 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function TokenStream(parent_token) { - // private - this.__tokens = []; - this.__tokens_length = this.__tokens.length; - this.__position = 0; - this.__parent_token = parent_token; -} - -TokenStream.prototype.restart = function() { - this.__position = 0; -}; - -TokenStream.prototype.isEmpty = function() { - return this.__tokens_length === 0; -}; - -TokenStream.prototype.hasNext = function() { - return this.__position < this.__tokens_length; -}; - -TokenStream.prototype.next = function() { - var val = null; - if (this.hasNext()) { - val = this.__tokens[this.__position]; - this.__position += 1; - } - return val; -}; - -TokenStream.prototype.peek = function(index) { - var val = null; - index = index || 0; - index += this.__position; - if (index >= 0 && index < this.__tokens_length) { - val = this.__tokens[index]; - } - return val; -}; - -TokenStream.prototype.add = function(token) { - if (this.__parent_token) { - token.parent = this.__parent_token; - } - this.__tokens.push(token); - this.__tokens_length += 1; -}; - -module.exports.TokenStream = TokenStream; - - -/***/ }), -/* 11 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -var Pattern = (__webpack_require__(12).Pattern); - -function WhitespacePattern(input_scanner, parent) { - Pattern.call(this, input_scanner, parent); - if (parent) { - this._line_regexp = this._input.get_regexp(parent._line_regexp); - } else { - this.__set_whitespace_patterns('', ''); - } - - this.newline_count = 0; - this.whitespace_before_token = ''; -} -WhitespacePattern.prototype = new Pattern(); - -WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) { - whitespace_chars += '\\t '; - newline_chars += '\\n\\r'; - - this._match_pattern = this._input.get_regexp( - '[' + whitespace_chars + newline_chars + ']+', true); - this._newline_regexp = this._input.get_regexp( - '\\r\\n|[' + newline_chars + ']'); -}; - -WhitespacePattern.prototype.read = function() { - this.newline_count = 0; - this.whitespace_before_token = ''; - - var resulting_string = this._input.read(this._match_pattern); - if (resulting_string === ' ') { - this.whitespace_before_token = ' '; - } else if (resulting_string) { - var matches = this.__split(this._newline_regexp, resulting_string); - this.newline_count = matches.length - 1; - this.whitespace_before_token = matches[this.newline_count]; - } - - return resulting_string; -}; - -WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) { - var result = this._create(); - result.__set_whitespace_patterns(whitespace_chars, newline_chars); - result._update(); - return result; -}; - -WhitespacePattern.prototype._create = function() { - return new WhitespacePattern(this._input, this); -}; - -WhitespacePattern.prototype.__split = function(regexp, input_string) { - regexp.lastIndex = 0; - var start_index = 0; - var result = []; - var next_match = regexp.exec(input_string); - while (next_match) { - result.push(input_string.substring(start_index, next_match.index)); - start_index = next_match.index + next_match[0].length; - next_match = regexp.exec(input_string); - } - - if (start_index < input_string.length) { - result.push(input_string.substring(start_index, input_string.length)); - } else { - result.push(''); - } - - return result; -}; - - - -module.exports.WhitespacePattern = WhitespacePattern; - - -/***/ }), -/* 12 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function Pattern(input_scanner, parent) { - this._input = input_scanner; - this._starting_pattern = null; - this._match_pattern = null; - this._until_pattern = null; - this._until_after = false; - - if (parent) { - this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true); - this._match_pattern = this._input.get_regexp(parent._match_pattern, true); - this._until_pattern = this._input.get_regexp(parent._until_pattern); - this._until_after = parent._until_after; - } -} - -Pattern.prototype.read = function() { - var result = this._input.read(this._starting_pattern); - if (!this._starting_pattern || result) { - result += this._input.read(this._match_pattern, this._until_pattern, this._until_after); - } - return result; -}; - -Pattern.prototype.read_match = function() { - return this._input.match(this._match_pattern); -}; - -Pattern.prototype.until_after = function(pattern) { - var result = this._create(); - result._until_after = true; - result._until_pattern = this._input.get_regexp(pattern); - result._update(); - return result; -}; - -Pattern.prototype.until = function(pattern) { - var result = this._create(); - result._until_after = false; - result._until_pattern = this._input.get_regexp(pattern); - result._update(); - return result; -}; - -Pattern.prototype.starting_with = function(pattern) { - var result = this._create(); - result._starting_pattern = this._input.get_regexp(pattern, true); - result._update(); - return result; -}; - -Pattern.prototype.matching = function(pattern) { - var result = this._create(); - result._match_pattern = this._input.get_regexp(pattern, true); - result._update(); - return result; -}; - -Pattern.prototype._create = function() { - return new Pattern(this._input, this); -}; - -Pattern.prototype._update = function() {}; - -module.exports.Pattern = Pattern; - - -/***/ }), -/* 13 */ -/***/ (function(module) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -function Directives(start_block_pattern, end_block_pattern) { - start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source; - end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source; - this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g'); - this.__directive_pattern = / (\w+)[:](\w+)/g; - - this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g'); -} - -Directives.prototype.get_directives = function(text) { - if (!text.match(this.__directives_block_pattern)) { - return null; - } - - var directives = {}; - this.__directive_pattern.lastIndex = 0; - var directive_match = this.__directive_pattern.exec(text); - - while (directive_match) { - directives[directive_match[1]] = directive_match[2]; - directive_match = this.__directive_pattern.exec(text); - } - - return directives; -}; - -Directives.prototype.readIgnored = function(input) { - return input.readUntilAfter(this.__directives_end_ignore_pattern); -}; - - -module.exports.Directives = Directives; - - -/***/ }), -/* 14 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -var Pattern = (__webpack_require__(12).Pattern); - - -var template_names = { - django: false, - erb: false, - handlebars: false, - php: false, - smarty: false, - angular: false -}; - -// This lets templates appear anywhere we would do a readUntil -// The cost is higher but it is pay to play. -function TemplatablePattern(input_scanner, parent) { - Pattern.call(this, input_scanner, parent); - this.__template_pattern = null; - this._disabled = Object.assign({}, template_names); - this._excluded = Object.assign({}, template_names); - - if (parent) { - this.__template_pattern = this._input.get_regexp(parent.__template_pattern); - this._excluded = Object.assign(this._excluded, parent._excluded); - this._disabled = Object.assign(this._disabled, parent._disabled); - } - var pattern = new Pattern(input_scanner); - this.__patterns = { - handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/), - handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/), - handlebars: pattern.starting_with(/{{/).until_after(/}}/), - php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/), - erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/), - // django coflicts with handlebars a bit. - django: pattern.starting_with(/{%/).until_after(/%}/), - django_value: pattern.starting_with(/{{/).until_after(/}}/), - django_comment: pattern.starting_with(/{#/).until_after(/#}/), - smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/), - smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/), - smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/) - }; -} -TemplatablePattern.prototype = new Pattern(); - -TemplatablePattern.prototype._create = function() { - return new TemplatablePattern(this._input, this); -}; - -TemplatablePattern.prototype._update = function() { - this.__set_templated_pattern(); -}; - -TemplatablePattern.prototype.disable = function(language) { - var result = this._create(); - result._disabled[language] = true; - result._update(); - return result; -}; - -TemplatablePattern.prototype.read_options = function(options) { - var result = this._create(); - for (var language in template_names) { - result._disabled[language] = options.templating.indexOf(language) === -1; - } - result._update(); - return result; -}; - -TemplatablePattern.prototype.exclude = function(language) { - var result = this._create(); - result._excluded[language] = true; - result._update(); - return result; -}; - -TemplatablePattern.prototype.read = function() { - var result = ''; - if (this._match_pattern) { - result = this._input.read(this._starting_pattern); - } else { - result = this._input.read(this._starting_pattern, this.__template_pattern); - } - var next = this._read_template(); - while (next) { - if (this._match_pattern) { - next += this._input.read(this._match_pattern); - } else { - next += this._input.readUntil(this.__template_pattern); - } - result += next; - next = this._read_template(); - } - - if (this._until_after) { - result += this._input.readUntilAfter(this._until_pattern); - } - return result; -}; - -TemplatablePattern.prototype.__set_templated_pattern = function() { - var items = []; - - if (!this._disabled.php) { - items.push(this.__patterns.php._starting_pattern.source); - } - if (!this._disabled.handlebars) { - items.push(this.__patterns.handlebars._starting_pattern.source); - } - if (!this._disabled.angular) { - // Handlebars ('{{' and '}}') are also special tokens in Angular) - items.push(this.__patterns.handlebars._starting_pattern.source); - } - if (!this._disabled.erb) { - items.push(this.__patterns.erb._starting_pattern.source); - } - if (!this._disabled.django) { - items.push(this.__patterns.django._starting_pattern.source); - // The starting pattern for django is more complex because it has different - // patterns for value, comment, and other sections - items.push(this.__patterns.django_value._starting_pattern.source); - items.push(this.__patterns.django_comment._starting_pattern.source); - } - if (!this._disabled.smarty) { - items.push(this.__patterns.smarty._starting_pattern.source); - } - - if (this._until_pattern) { - items.push(this._until_pattern.source); - } - this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')'); -}; - -TemplatablePattern.prototype._read_template = function() { - var resulting_string = ''; - var c = this._input.peek(); - if (c === '<') { - var peek1 = this._input.peek(1); - //if we're in a comment, do something special - // We treat all comments as literals, even more than preformatted tags - // we just look for the appropriate close tag - if (!this._disabled.php && !this._excluded.php && peek1 === '?') { - resulting_string = resulting_string || - this.__patterns.php.read(); - } - if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') { - resulting_string = resulting_string || - this.__patterns.erb.read(); - } - } else if (c === '{') { - if (!this._disabled.handlebars && !this._excluded.handlebars) { - resulting_string = resulting_string || - this.__patterns.handlebars_comment.read(); - resulting_string = resulting_string || - this.__patterns.handlebars_unescaped.read(); - resulting_string = resulting_string || - this.__patterns.handlebars.read(); - } - if (!this._disabled.django) { - // django coflicts with handlebars a bit. - if (!this._excluded.django && !this._excluded.handlebars) { - resulting_string = resulting_string || - this.__patterns.django_value.read(); - } - if (!this._excluded.django) { - resulting_string = resulting_string || - this.__patterns.django_comment.read(); - resulting_string = resulting_string || - this.__patterns.django.read(); - } - } - if (!this._disabled.smarty) { - // smarty cannot be enabled with django or handlebars enabled - if (this._disabled.django && this._disabled.handlebars) { - resulting_string = resulting_string || - this.__patterns.smarty_comment.read(); - resulting_string = resulting_string || - this.__patterns.smarty_literal.read(); - resulting_string = resulting_string || - this.__patterns.smarty.read(); - } - } - } - return resulting_string; -}; - - -module.exports.TemplatablePattern = TemplatablePattern; - - -/***/ }), -/* 15 */, -/* 16 */, -/* 17 */, -/* 18 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -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); - return beautifier.beautify(); -} - -module.exports = style_html; -module.exports.defaultOptions = function() { - return new Options(); -}; - - -/***/ }), -/* 19 */ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -/*jshint node:true */ -/* - - The MIT License (MIT) - - Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. - - 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. -*/ - - - -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; - -var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions - - this.indent_level = 0; - this.alignment_size = 0; - this.max_preserve_newlines = options.max_preserve_newlines; - this.preserve_newlines = options.preserve_newlines; - - this._output = new Output(options, base_indent_string); - -}; - -Printer.prototype.current_line_has_match = function(pattern) { - return this._output.current_line.has_match(pattern); -}; - -Printer.prototype.set_space_before_token = function(value, non_breaking) { - this._output.space_before_token = value; - this._output.non_breaking_space = non_breaking; -}; - -Printer.prototype.set_wrap_point = function() { - this._output.set_indent(this.indent_level, this.alignment_size); - this._output.set_wrap_point(); -}; - - -Printer.prototype.add_raw_token = function(token) { - this._output.add_raw_token(token); -}; - -Printer.prototype.print_preserved_newlines = function(raw_token) { - var newlines = 0; - if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) { - newlines = raw_token.newlines ? 1 : 0; - } - - if (this.preserve_newlines) { - newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1; - } - for (var n = 0; n < newlines; n++) { - this.print_newline(n > 0); - } - - return newlines !== 0; -}; - -Printer.prototype.traverse_whitespace = function(raw_token) { - if (raw_token.whitespace_before || raw_token.newlines) { - if (!this.print_preserved_newlines(raw_token)) { - this._output.space_before_token = true; - } - return true; - } - return false; -}; - -Printer.prototype.previous_token_wrapped = function() { - return this._output.previous_token_wrapped; -}; - -Printer.prototype.print_newline = function(force) { - this._output.add_new_line(force); -}; - -Printer.prototype.print_token = function(token) { - if (token.text) { - this._output.set_indent(this.indent_level, this.alignment_size); - this._output.add_token(token.text); - } -}; - -Printer.prototype.indent = function() { - this.indent_level++; -}; - -Printer.prototype.deindent = function() { - if (this.indent_level > 0) { - this.indent_level--; - this._output.set_indent(this.indent_level, this.alignment_size); - } -}; - -Printer.prototype.get_full_indent = function(level) { - level = this.indent_level + (level || 0); - if (level < 1) { - return ''; - } - - return this._output.get_indent_string(level); -}; - -var get_type_attribute = function(start_token) { - var result = null; - var raw_token = start_token.next; - - // Search attributes for a type attribute - while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) { - if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') { - if (raw_token.next && raw_token.next.type === TOKEN.EQUALS && - raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) { - result = raw_token.next.next.text; - } - break; - } - raw_token = raw_token.next; - } - - return result; -}; - -var get_custom_beautifier_name = function(tag_check, raw_token) { - var typeAttribute = null; - var result = null; - - if (!raw_token.closed) { - return null; - } - - if (tag_check === 'script') { - typeAttribute = 'text/javascript'; - } else if (tag_check === 'style') { - typeAttribute = 'text/css'; - } - - typeAttribute = get_type_attribute(raw_token) || typeAttribute; - - // For script and style tags that have a type attribute, only enable custom beautifiers for matching values - // For those without a type attribute use default; - if (typeAttribute.search('text/css') > -1) { - result = 'css'; - } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) { - result = 'javascript'; - } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) { - result = 'html'; - } else if (typeAttribute.search(/test\/null/) > -1) { - // Test only mime-type for testing the beautifier when null is passed as beautifing function - result = 'null'; - } - - return result; -}; - -function in_array(what, arr) { - return arr.indexOf(what) !== -1; -} - -function TagFrame(parent, parser_token, indent_level) { - this.parent = parent || null; - this.tag = parser_token ? parser_token.tag_name : ''; - this.indent_level = indent_level || 0; - this.parser_token = parser_token || null; -} - -function TagStack(printer) { - this._printer = printer; - this._current_frame = null; -} - -TagStack.prototype.get_parser_token = function() { - return this._current_frame ? this._current_frame.parser_token : null; -}; - -TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object - var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level); - this._current_frame = new_frame; -}; - -TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer - var parser_token = null; - - if (frame) { - parser_token = frame.parser_token; - this._printer.indent_level = frame.indent_level; - this._current_frame = frame.parent; - } - - return parser_token; -}; - -TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer - var frame = this._current_frame; - - while (frame) { //till we reach '' (the initial value); - if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it - break; - } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) { - frame = null; - break; - } - frame = frame.parent; - } - - return frame; -}; - -TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer - var frame = this._get_frame([tag], stop_list); - return this._try_pop_frame(frame); -}; - -TagStack.prototype.indent_to_tag = function(tag_list) { - var frame = this._get_frame(tag_list); - if (frame) { - this._printer.indent_level = frame.indent_level; - } -}; - -function Beautifier(source_text, options, js_beautify, css_beautify) { - //Wrapper function to invoke all the necessary constructors and deal with the output. - this._source_text = source_text || ''; - options = options || {}; - this._js_beautify = js_beautify; - this._css_beautify = css_beautify; - this._tag_stack = null; - - // Allow the setting of language/file-type specific options - // with inheritance of overall settings - var optionHtml = new Options(options, 'html'); - - this._options = optionHtml; - - this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force'; - this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline'); - this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned'); - this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple'); - this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve'; - this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned'); -} - -Beautifier.prototype.beautify = function() { - - // if disabled, return the input unchanged. - if (this._options.disabled) { - return this._source_text; - } - - var source_text = this._source_text; - var eol = this._options.eol; - if (this._options.eol === 'auto') { - eol = '\n'; - if (source_text && lineBreak.test(source_text)) { - eol = source_text.match(lineBreak)[0]; - } - } - - // HACK: newline parsing inconsistent. This brute force normalizes the input. - source_text = source_text.replace(allLineBreaks, '\n'); - - var baseIndentString = source_text.match(/^[\t ]*/)[0]; - - var last_token = { - text: '', - type: '' - }; - - var last_tag_token = new TagOpenParserToken(this._options); - - var printer = new Printer(this._options, baseIndentString); - var tokens = new Tokenizer(source_text, this._options).tokenize(); - - this._tag_stack = new TagStack(printer); - - var parser_token = null; - var raw_token = tokens.next(); - 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, 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, 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) { - parser_token = this._handle_text(printer, raw_token, last_tag_token); - } else if (raw_token.type === TOKEN.CONTROL_FLOW_OPEN) { - parser_token = this._handle_control_flow_open(printer, raw_token); - } else if (raw_token.type === TOKEN.CONTROL_FLOW_CLOSE) { - parser_token = this._handle_control_flow_close(printer, raw_token); - } else { - // This should never happen, but if it does. Print the raw token - printer.add_raw_token(raw_token); - } - - last_token = parser_token; - - raw_token = tokens.next(); - } - var sweet_code = printer._output.get_code(eol); - - return sweet_code; -}; - -Beautifier.prototype._handle_control_flow_open = function(printer, raw_token) { - var parser_token = { - text: raw_token.text, - type: raw_token.type - }; - printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); - if (raw_token.newlines) { - printer.print_preserved_newlines(raw_token); - } else { - printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); - } - printer.print_token(raw_token); - printer.indent(); - return parser_token; -}; - -Beautifier.prototype._handle_control_flow_close = function(printer, raw_token) { - var parser_token = { - text: raw_token.text, - type: raw_token.type - }; - - printer.deindent(); - if (raw_token.newlines) { - printer.print_preserved_newlines(raw_token); - } else { - printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); - } - printer.print_token(raw_token); - return parser_token; -}; - -Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) { - var parser_token = { - text: raw_token.text, - type: raw_token.type - }; - printer.alignment_size = 0; - last_tag_token.tag_complete = true; - - printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); - if (last_tag_token.is_unformatted) { - printer.add_raw_token(raw_token); - } else { - if (last_tag_token.tag_start_char === '<') { - printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before > - if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) { - printer.print_newline(false); - } - } - printer.print_token(raw_token); - - } - - if (last_tag_token.indent_content && - !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) { - printer.indent(); - - // only indent once per opened tag - last_tag_token.indent_content = false; - } - - if (!last_tag_token.is_inline_element && - !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) { - printer.set_wrap_point(); - } - - return parser_token; -}; - -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, - type: raw_token.type - }; - - printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); - if (last_tag_token.is_unformatted) { - printer.add_raw_token(raw_token); - } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) { - // For the insides of handlebars allow newlines or a single space between open and contents - if (printer.print_preserved_newlines(raw_token)) { - raw_token.newlines = 0; - printer.add_raw_token(raw_token); - } else { - printer.print_token(raw_token); - } - } else { - if (raw_token.type === TOKEN.ATTRIBUTE) { - printer.set_space_before_token(true); - } 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 - printer.set_space_before_token(false); - } - - if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') { - if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) { - printer.traverse_whitespace(raw_token); - wrapped = wrapped || raw_token.newlines !== 0; - } - - // 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); - wrapped = wrapped || printer.previous_token_wrapped(); - last_tag_token.has_wrapped_attrs = wrapped; - } - return parser_token; -}; - -Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) { - var parser_token = { - text: raw_token.text, - type: 'TK_CONTENT' - }; - if (last_tag_token.custom_beautifier_name) { //check if we need to format javascript - this._print_custom_beatifier_text(printer, raw_token, last_tag_token); - } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) { - printer.add_raw_token(raw_token); - } else { - printer.traverse_whitespace(raw_token); - printer.print_token(raw_token); - } - return parser_token; -}; - -Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) { - var local = this; - if (raw_token.text !== '') { - - var text = raw_token.text, - _beautifier, - script_indent_level = 1, - pre = '', - post = ''; - if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') { - _beautifier = this._js_beautify; - } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') { - _beautifier = this._css_beautify; - } else if (last_tag_token.custom_beautifier_name === 'html') { - _beautifier = function(html_source, options) { - var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify); - return beautifier.beautify(); - }; - } - - if (this._options.indent_scripts === "keep") { - script_indent_level = 0; - } else if (this._options.indent_scripts === "separate") { - script_indent_level = -printer.indent_level; - } - - var indentation = printer.get_full_indent(script_indent_level); - - // if there is at least one empty line at the end of this text, strip it - // we'll be adding one back after the text but before the containing tag. - text = text.replace(/\n[ \t]*$/, ''); - - // Handle the case where content is wrapped in a comment or cdata. - if (last_tag_token.custom_beautifier_name !== 'html' && - text[0] === '<' && text.match(/^(|]]>)$/.exec(text); - - // if we start to wrap but don't finish, print raw - if (!matched) { - printer.add_raw_token(raw_token); - return; - } - - pre = indentation + matched[1] + '\n'; - text = matched[4]; - if (matched[5]) { - post = indentation + matched[5]; - } - - // if there is at least one empty line at the end of this text, strip it - // we'll be adding one back after the text but before the containing tag. - text = text.replace(/\n[ \t]*$/, ''); - - if (matched[2] || matched[3].indexOf('\n') !== -1) { - // if the first line of the non-comment text has spaces - // use that as the basis for indenting in null case. - matched = matched[3].match(/[ \t]+$/); - if (matched) { - raw_token.whitespace_before = matched[0]; - } - } - } - - if (text) { - if (_beautifier) { - - // call the Beautifier if avaliable - var Child_options = function() { - this.eol = '\n'; - }; - Child_options.prototype = this._options.raw_options; - var child_options = new Child_options(); - text = _beautifier(indentation + text, child_options); - } else { - // simply indent the string otherwise - var white = raw_token.whitespace_before; - if (white) { - text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n'); - } - - text = indentation + text.replace(/\n/g, '\n' + indentation); - } - } - - if (pre) { - if (!text) { - text = pre + post; - } else { - text = pre + text + '\n' + post; - } - } - - printer.print_newline(false); - if (text) { - raw_token.text = text; - raw_token.whitespace_before = ''; - raw_token.newlines = 0; - printer.add_raw_token(raw_token); - printer.print_newline(true); - } - } -}; - -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 && !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); - parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); - } else { - printer.traverse_whitespace(raw_token); - this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token); - if (!parser_token.is_inline_element) { - printer.set_wrap_point(); - } - 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; - } - - if (!parser_token.tag_complete && !parser_token.is_unformatted) { - printer.alignment_size = parser_token.alignment_size; - } - - return parser_token; -}; - -var TagOpenParserToken = function(options, parent, raw_token) { - this.parent = parent || null; - this.text = ''; - this.type = 'TK_TAG_OPEN'; - this.tag_name = ''; - this.is_inline_element = false; - this.is_unformatted = false; - this.is_content_unformatted = false; - this.is_empty_element = false; - this.is_start_tag = false; - this.is_end_tag = false; - this.indent_content = false; - this.multiline_content = false; - this.custom_beautifier_name = null; - this.start_tag_token = null; - this.attr_count = 0; - this.has_wrapped_attrs = false; - this.alignment_size = 0; - this.tag_complete = false; - this.tag_start_char = ''; - this.tag_check = ''; - - if (!raw_token) { - this.tag_complete = true; - } else { - var tag_check_match; - - this.tag_start_char = raw_token.text[0]; - this.text = raw_token.text; - - if (this.tag_start_char === '<') { - 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}]+)/); - this.tag_check = tag_check_match ? tag_check_match[1] : ''; - - // 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) { - this.tag_complete = true; - } - - this.is_start_tag = this.tag_check.charAt(0) !== '/'; - this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check; - 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. - // if they start with # or ^, they are still considered single tags if indenting of handlebars is set to false - this.is_end_tag = this.is_end_tag || - (this.tag_start_char === '{' && (!options.indent_handlebars || this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts))))); - } -}; - -Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type - var parser_token = new TagOpenParserToken(this._options, this._tag_stack.get_parser_token(), raw_token); - - parser_token.alignment_size = this._options.wrap_attributes_indent_size; - - parser_token.is_end_tag = parser_token.is_end_tag || - in_array(parser_token.tag_check, this._options.void_elements); - - parser_token.is_empty_element = parser_token.tag_complete || - (parser_token.is_start_tag && parser_token.is_end_tag); - - 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) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{'; - - return parser_token; -}; - -Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) { - - if (!parser_token.is_empty_element) { - if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending - parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors - } else { // it's a start-tag - // check if this tag is starting an element that has optional end element - // and do an ending needed - if (this._do_optional_end_element(parser_token)) { - if (!parser_token.is_inline_element) { - printer.print_newline(false); - } - } - - this._tag_stack.record_tag(parser_token); //push it on the tag stack - - if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') && - !(parser_token.is_unformatted || parser_token.is_content_unformatted)) { - parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token); - } - } - } - - if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line - printer.print_newline(false); - if (!printer._output.just_added_blankline()) { - printer.print_newline(true); - } - } - - if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /) - - // if you hit an else case, reset the indent level if you are inside an: - // 'if', 'unless', or 'each' block. - if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') { - this._tag_stack.indent_to_tag(['if', 'unless', 'each']); - parser_token.indent_content = true; - // Don't add a newline if opening {{#if}} tag is on the current line - var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/); - if (!foundIfOnCurrentLine) { - printer.print_newline(false); - } - } - - // Don't add a newline before elements that should remain where they are. - if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE && - last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) { - //Do nothing. Leave comments on same line. - } else { - if (!(parser_token.is_inline_element || parser_token.is_unformatted)) { - printer.print_newline(false); - } - this._calcluate_parent_multiline(printer, parser_token); - } - } else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending - var do_end_expand = false; - - // deciding whether a block is multiline should not be this hard - do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content; - do_end_expand = do_end_expand || (!parser_token.is_inline_element && - !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) && - !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) && - last_token.type !== 'TK_CONTENT' - ); - - if (parser_token.is_content_unformatted || parser_token.is_unformatted) { - do_end_expand = false; - } - - if (do_end_expand) { - printer.print_newline(false); - } - } else { // it's a start-tag - parser_token.indent_content = !parser_token.custom_beautifier_name; - - if (parser_token.tag_start_char === '<') { - if (parser_token.tag_name === 'html') { - parser_token.indent_content = this._options.indent_inner_html; - } else if (parser_token.tag_name === 'head') { - parser_token.indent_content = this._options.indent_head_inner_html; - } else if (parser_token.tag_name === 'body') { - parser_token.indent_content = this._options.indent_body_inner_html; - } - } - - if (!(parser_token.is_inline_element || parser_token.is_unformatted) && - (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) { - printer.print_newline(false); - } - - this._calcluate_parent_multiline(printer, parser_token); - } -}; - -Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) { - if (parser_token.parent && printer._output.just_added_newline() && - !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) { - parser_token.parent.multiline_content = true; - } -}; - -//To be used for

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', '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) { - var result = null; - // NOTE: cases of "if there is no more content in the parent element" - // are handled automatically by the beautifier. - // It assumes parent or ancestor close tag closes all children. - // https://www.w3.org/TR/html5/syntax.html#optional-tags - if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) { - return; - - } - - if (parser_token.tag_name === 'body') { - // A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment. - result = result || this._tag_stack.try_pop('head'); - - //} else if (parser_token.tag_name === 'body') { - // DONE: A body element’s end tag may be omitted if the body element is not immediately followed by a comment. - - } else if (parser_token.tag_name === 'li') { - // An li element’s 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', 'menu']); - - } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') { - // A dd element’s 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. - // A dt element’s end tag may be omitted if the dt element is immediately followed by another dt element or a dd element. - result = result || this._tag_stack.try_pop('dt', ['dl']); - result = result || this._tag_stack.try_pop('dd', ['dl']); - - - } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) { - // IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method - // check for the parent element is an HTML element that is not an ,