beautify-html.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473
  1. 
  2. /* AUTO-GENERATED. DO NOT MODIFY. */
  3. /*
  4. The MIT License (MIT)
  5. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  6. Permission is hereby granted, free of charge, to any person
  7. obtaining a copy of this software and associated documentation files
  8. (the "Software"), to deal in the Software without restriction,
  9. including without limitation the rights to use, copy, modify, merge,
  10. publish, distribute, sublicense, and/or sell copies of the Software,
  11. and to permit persons to whom the Software is furnished to do so,
  12. subject to the following conditions:
  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. SOFTWARE.
  23. Style HTML
  24. ---------------
  25. Written by Nochum Sossonko, (nsossonko@hotmail.com)
  26. Based on code initially developed by: Einar Lielmanis, <einar@beautifier.io>
  27. https://beautifier.io/
  28. Usage:
  29. style_html(html_source);
  30. style_html(html_source, options);
  31. The options are:
  32. indent_inner_html (default false) 鈥� indent <head> and <body> sections,
  33. indent_size (default 4) 鈥� indentation size,
  34. indent_char (default space) 鈥� character to indent with,
  35. wrap_line_length (default 250) - maximum amount of characters per line (0 = disable)
  36. brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none"
  37. 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.
  38. inline (defaults to inline tags) - list of tags to be considered inline tags
  39. unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted
  40. content_unformatted (defaults to ["pre", "textarea"] tags) - list of tags, whose content shouldn't be reformatted
  41. indent_scripts (default normal) - "keep"|"separate"|"normal"
  42. preserve_newlines (default true) - whether existing line breaks before elements should be preserved
  43. Only works before elements, not inside tags or for text.
  44. max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk
  45. indent_handlebars (default false) - format and indent {{#foo}} and {{/foo}}
  46. end_with_newline (false) - end with a newline
  47. extra_liners (default [head,body,/html]) -List of tags that should have an extra newline before them.
  48. e.g.
  49. style_html(html_source, {
  50. 'indent_inner_html': false,
  51. 'indent_size': 2,
  52. 'indent_char': ' ',
  53. 'wrap_line_length': 78,
  54. 'brace_style': 'expand',
  55. 'preserve_newlines': true,
  56. 'max_preserve_newlines': 5,
  57. 'indent_handlebars': false,
  58. 'extra_liners': ['/html']
  59. });
  60. */
  61. (function() {
  62. /* GENERATED_BUILD_OUTPUT */
  63. var legacy_beautify_html =
  64. /******/ (function(modules) { // webpackBootstrap
  65. /******/ // The module cache
  66. /******/ var installedModules = {};
  67. /******/
  68. /******/ // The require function
  69. /******/ function __webpack_require__(moduleId) {
  70. /******/
  71. /******/ // Check if module is in cache
  72. /******/ if(installedModules[moduleId]) {
  73. /******/ return installedModules[moduleId].exports;
  74. /******/ }
  75. /******/ // Create a new module (and put it into the cache)
  76. /******/ var module = installedModules[moduleId] = {
  77. /******/ i: moduleId,
  78. /******/ l: false,
  79. /******/ exports: {}
  80. /******/ };
  81. /******/
  82. /******/ // Execute the module function
  83. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  84. /******/
  85. /******/ // Flag the module as loaded
  86. /******/ module.l = true;
  87. /******/
  88. /******/ // Return the exports of the module
  89. /******/ return module.exports;
  90. /******/ }
  91. /******/
  92. /******/
  93. /******/ // expose the modules object (__webpack_modules__)
  94. /******/ __webpack_require__.m = modules;
  95. /******/
  96. /******/ // expose the module cache
  97. /******/ __webpack_require__.c = installedModules;
  98. /******/
  99. /******/ // define getter function for harmony exports
  100. /******/ __webpack_require__.d = function(exports, name, getter) {
  101. /******/ if(!__webpack_require__.o(exports, name)) {
  102. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  103. /******/ }
  104. /******/ };
  105. /******/
  106. /******/ // define __esModule on exports
  107. /******/ __webpack_require__.r = function(exports) {
  108. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  109. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  110. /******/ }
  111. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  112. /******/ };
  113. /******/
  114. /******/ // create a fake namespace object
  115. /******/ // mode & 1: value is a module id, require it
  116. /******/ // mode & 2: merge all properties of value into the ns
  117. /******/ // mode & 4: return value when already ns object
  118. /******/ // mode & 8|1: behave like require
  119. /******/ __webpack_require__.t = function(value, mode) {
  120. /******/ if(mode & 1) value = __webpack_require__(value);
  121. /******/ if(mode & 8) return value;
  122. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  123. /******/ var ns = Object.create(null);
  124. /******/ __webpack_require__.r(ns);
  125. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  126. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  127. /******/ return ns;
  128. /******/ };
  129. /******/
  130. /******/ // getDefaultExport function for compatibility with non-harmony modules
  131. /******/ __webpack_require__.n = function(module) {
  132. /******/ var getter = module && module.__esModule ?
  133. /******/ function getDefault() { return module['default']; } :
  134. /******/ function getModuleExports() { return module; };
  135. /******/ __webpack_require__.d(getter, 'a', getter);
  136. /******/ return getter;
  137. /******/ };
  138. /******/
  139. /******/ // Object.prototype.hasOwnProperty.call
  140. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  141. /******/
  142. /******/ // __webpack_public_path__
  143. /******/ __webpack_require__.p = "";
  144. /******/
  145. /******/
  146. /******/ // Load entry module and return exports
  147. /******/ return __webpack_require__(__webpack_require__.s = 15);
  148. /******/ })
  149. /************************************************************************/
  150. /******/ ([
  151. /* 0 */,
  152. /* 1 */,
  153. /* 2 */
  154. /***/ (function(module, exports, __webpack_require__) {
  155. "use strict";
  156. /*jshint node:true */
  157. /*
  158. The MIT License (MIT)
  159. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  160. Permission is hereby granted, free of charge, to any person
  161. obtaining a copy of this software and associated documentation files
  162. (the "Software"), to deal in the Software without restriction,
  163. including without limitation the rights to use, copy, modify, merge,
  164. publish, distribute, sublicense, and/or sell copies of the Software,
  165. and to permit persons to whom the Software is furnished to do so,
  166. subject to the following conditions:
  167. The above copyright notice and this permission notice shall be
  168. included in all copies or substantial portions of the Software.
  169. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  170. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  171. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  172. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  173. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  174. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  175. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  176. SOFTWARE.
  177. */
  178. function OutputLine(parent) {
  179. this.__parent = parent;
  180. this.__character_count = 0;
  181. // use indent_count as a marker for this.__lines that have preserved indentation
  182. this.__indent_count = -1;
  183. this.__alignment_count = 0;
  184. this.__items = [];
  185. }
  186. OutputLine.prototype.item = function(index) {
  187. if (index < 0) {
  188. return this.__items[this.__items.length + index];
  189. } else {
  190. return this.__items[index];
  191. }
  192. };
  193. OutputLine.prototype.has_match = function(pattern) {
  194. for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
  195. if (this.__items[lastCheckedOutput].match(pattern)) {
  196. return true;
  197. }
  198. }
  199. return false;
  200. };
  201. OutputLine.prototype.set_indent = function(indent, alignment) {
  202. this.__indent_count = indent || 0;
  203. this.__alignment_count = alignment || 0;
  204. this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
  205. };
  206. OutputLine.prototype.get_character_count = function() {
  207. return this.__character_count;
  208. };
  209. OutputLine.prototype.is_empty = function() {
  210. return this.__items.length === 0;
  211. };
  212. OutputLine.prototype.last = function() {
  213. if (!this.is_empty()) {
  214. return this.__items[this.__items.length - 1];
  215. } else {
  216. return null;
  217. }
  218. };
  219. OutputLine.prototype.push = function(item) {
  220. this.__items.push(item);
  221. this.__character_count += item.length;
  222. };
  223. OutputLine.prototype.push_raw = function(item) {
  224. this.push(item);
  225. var last_newline_index = item.lastIndexOf('\n');
  226. if (last_newline_index !== -1) {
  227. this.__character_count = item.length - last_newline_index;
  228. }
  229. };
  230. OutputLine.prototype.pop = function() {
  231. var item = null;
  232. if (!this.is_empty()) {
  233. item = this.__items.pop();
  234. this.__character_count -= item.length;
  235. }
  236. return item;
  237. };
  238. OutputLine.prototype.remove_indent = function() {
  239. if (this.__indent_count > 0) {
  240. this.__indent_count -= 1;
  241. this.__character_count -= this.__parent.indent_size;
  242. }
  243. };
  244. OutputLine.prototype.trim = function() {
  245. while (this.last() === ' ') {
  246. this.__items.pop();
  247. this.__character_count -= 1;
  248. }
  249. };
  250. OutputLine.prototype.toString = function() {
  251. var result = '';
  252. if (!this.is_empty()) {
  253. result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
  254. result += this.__items.join('');
  255. }
  256. return result;
  257. };
  258. function IndentStringCache(options, baseIndentString) {
  259. this.__cache = [''];
  260. this.__indent_size = options.indent_size;
  261. this.__indent_string = options.indent_char;
  262. if (!options.indent_with_tabs) {
  263. this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
  264. }
  265. // Set to null to continue support for auto detection of base indent
  266. baseIndentString = baseIndentString || '';
  267. if (options.indent_level > 0) {
  268. baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
  269. }
  270. this.__base_string = baseIndentString;
  271. this.__base_string_length = baseIndentString.length;
  272. }
  273. IndentStringCache.prototype.get_indent_size = function(indent, column) {
  274. var result = this.__base_string_length;
  275. column = column || 0;
  276. if (indent < 0) {
  277. result = 0;
  278. }
  279. result += indent * this.__indent_size;
  280. result += column;
  281. return result;
  282. };
  283. IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
  284. var result = this.__base_string;
  285. column = column || 0;
  286. if (indent_level < 0) {
  287. indent_level = 0;
  288. result = '';
  289. }
  290. column += indent_level * this.__indent_size;
  291. this.__ensure_cache(column);
  292. result += this.__cache[column];
  293. return result;
  294. };
  295. IndentStringCache.prototype.__ensure_cache = function(column) {
  296. while (column >= this.__cache.length) {
  297. this.__add_column();
  298. }
  299. };
  300. IndentStringCache.prototype.__add_column = function() {
  301. var column = this.__cache.length;
  302. var indent = 0;
  303. var result = '';
  304. if (this.__indent_size && column >= this.__indent_size) {
  305. indent = Math.floor(column / this.__indent_size);
  306. column -= indent * this.__indent_size;
  307. result = new Array(indent + 1).join(this.__indent_string);
  308. }
  309. if (column) {
  310. result += new Array(column + 1).join(' ');
  311. }
  312. this.__cache.push(result);
  313. };
  314. function Output(options, baseIndentString) {
  315. this.__indent_cache = new IndentStringCache(options, baseIndentString);
  316. this.raw = false;
  317. this._end_with_newline = options.end_with_newline;
  318. this.indent_size = options.indent_size;
  319. this.__lines = [];
  320. this.previous_line = null;
  321. this.current_line = null;
  322. this.space_before_token = false;
  323. // initialize
  324. this.__add_outputline();
  325. }
  326. Output.prototype.__add_outputline = function() {
  327. this.previous_line = this.current_line;
  328. this.current_line = new OutputLine(this);
  329. this.__lines.push(this.current_line);
  330. };
  331. Output.prototype.get_line_number = function() {
  332. return this.__lines.length;
  333. };
  334. Output.prototype.get_indent_string = function(indent, column) {
  335. return this.__indent_cache.get_indent_string(indent, column);
  336. };
  337. Output.prototype.get_indent_size = function(indent, column) {
  338. return this.__indent_cache.get_indent_size(indent, column);
  339. };
  340. Output.prototype.is_empty = function() {
  341. return !this.previous_line && this.current_line.is_empty();
  342. };
  343. Output.prototype.add_new_line = function(force_newline) {
  344. // never newline at the start of file
  345. // otherwise, newline only if we didn't just add one or we're forced
  346. if (this.is_empty() ||
  347. (!force_newline && this.just_added_newline())) {
  348. return false;
  349. }
  350. // if raw output is enabled, don't print additional newlines,
  351. // but still return True as though you had
  352. if (!this.raw) {
  353. this.__add_outputline();
  354. }
  355. return true;
  356. };
  357. Output.prototype.get_code = function(eol) {
  358. var sweet_code = this.__lines.join('\n').replace(/[\r\n\t ]+$/, '');
  359. if (this._end_with_newline) {
  360. sweet_code += '\n';
  361. }
  362. if (eol !== '\n') {
  363. sweet_code = sweet_code.replace(/[\n]/g, eol);
  364. }
  365. return sweet_code;
  366. };
  367. Output.prototype.set_indent = function(indent, alignment) {
  368. indent = indent || 0;
  369. alignment = alignment || 0;
  370. // Never indent your first output indent at the start of the file
  371. if (this.__lines.length > 1) {
  372. this.current_line.set_indent(indent, alignment);
  373. return true;
  374. }
  375. this.current_line.set_indent();
  376. return false;
  377. };
  378. Output.prototype.add_raw_token = function(token) {
  379. for (var x = 0; x < token.newlines; x++) {
  380. this.__add_outputline();
  381. }
  382. this.current_line.push(token.whitespace_before);
  383. this.current_line.push_raw(token.text);
  384. this.space_before_token = false;
  385. };
  386. Output.prototype.add_token = function(printable_token) {
  387. this.add_space_before_token();
  388. this.current_line.push(printable_token);
  389. };
  390. Output.prototype.add_space_before_token = function() {
  391. if (this.space_before_token && !this.just_added_newline()) {
  392. this.current_line.push(' ');
  393. }
  394. this.space_before_token = false;
  395. };
  396. Output.prototype.remove_indent = function(index) {
  397. var output_length = this.__lines.length;
  398. while (index < output_length) {
  399. this.__lines[index].remove_indent();
  400. index++;
  401. }
  402. };
  403. Output.prototype.trim = function(eat_newlines) {
  404. eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
  405. this.current_line.trim(this.indent_string, this.baseIndentString);
  406. while (eat_newlines && this.__lines.length > 1 &&
  407. this.current_line.is_empty()) {
  408. this.__lines.pop();
  409. this.current_line = this.__lines[this.__lines.length - 1];
  410. this.current_line.trim();
  411. }
  412. this.previous_line = this.__lines.length > 1 ?
  413. this.__lines[this.__lines.length - 2] : null;
  414. };
  415. Output.prototype.just_added_newline = function() {
  416. return this.current_line.is_empty();
  417. };
  418. Output.prototype.just_added_blankline = function() {
  419. return this.is_empty() ||
  420. (this.current_line.is_empty() && this.previous_line.is_empty());
  421. };
  422. Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
  423. var index = this.__lines.length - 2;
  424. while (index >= 0) {
  425. var potentialEmptyLine = this.__lines[index];
  426. if (potentialEmptyLine.is_empty()) {
  427. break;
  428. } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
  429. potentialEmptyLine.item(-1) !== ends_with) {
  430. this.__lines.splice(index + 1, 0, new OutputLine(this));
  431. this.previous_line = this.__lines[this.__lines.length - 2];
  432. break;
  433. }
  434. index--;
  435. }
  436. };
  437. module.exports.Output = Output;
  438. /***/ }),
  439. /* 3 */
  440. /***/ (function(module, exports, __webpack_require__) {
  441. "use strict";
  442. /*jshint node:true */
  443. /*
  444. The MIT License (MIT)
  445. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  446. Permission is hereby granted, free of charge, to any person
  447. obtaining a copy of this software and associated documentation files
  448. (the "Software"), to deal in the Software without restriction,
  449. including without limitation the rights to use, copy, modify, merge,
  450. publish, distribute, sublicense, and/or sell copies of the Software,
  451. and to permit persons to whom the Software is furnished to do so,
  452. subject to the following conditions:
  453. The above copyright notice and this permission notice shall be
  454. included in all copies or substantial portions of the Software.
  455. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  456. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  457. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  458. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  459. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  460. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  461. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  462. SOFTWARE.
  463. */
  464. function Token(type, text, newlines, whitespace_before) {
  465. this.type = type;
  466. this.text = text;
  467. // comments_before are
  468. // comments that have a new line before them
  469. // and may or may not have a newline after
  470. // this is a set of comments before
  471. this.comments_before = null; /* inline comment*/
  472. // this.comments_after = new TokenStream(); // no new line before and newline after
  473. this.newlines = newlines || 0;
  474. this.whitespace_before = whitespace_before || '';
  475. this.parent = null;
  476. this.next = null;
  477. this.previous = null;
  478. this.opened = null;
  479. this.closed = null;
  480. this.directives = null;
  481. }
  482. module.exports.Token = Token;
  483. /***/ }),
  484. /* 4 */,
  485. /* 5 */,
  486. /* 6 */
  487. /***/ (function(module, exports, __webpack_require__) {
  488. "use strict";
  489. /*jshint node:true */
  490. /*
  491. The MIT License (MIT)
  492. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  493. Permission is hereby granted, free of charge, to any person
  494. obtaining a copy of this software and associated documentation files
  495. (the "Software"), to deal in the Software without restriction,
  496. including without limitation the rights to use, copy, modify, merge,
  497. publish, distribute, sublicense, and/or sell copies of the Software,
  498. and to permit persons to whom the Software is furnished to do so,
  499. subject to the following conditions:
  500. The above copyright notice and this permission notice shall be
  501. included in all copies or substantial portions of the Software.
  502. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  503. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  504. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  505. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  506. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  507. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  508. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  509. SOFTWARE.
  510. */
  511. function Options(options, merge_child_field) {
  512. this.raw_options = _mergeOpts(options, merge_child_field);
  513. // Support passing the source text back with no change
  514. this.disabled = this._get_boolean('disabled');
  515. this.eol = this._get_characters('eol', 'auto');
  516. this.end_with_newline = this._get_boolean('end_with_newline');
  517. this.indent_size = this._get_number('indent_size', 4);
  518. this.indent_char = this._get_characters('indent_char', ' ');
  519. this.indent_level = this._get_number('indent_level');
  520. this.preserve_newlines = this._get_boolean('preserve_newlines', true);
  521. this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
  522. if (!this.preserve_newlines) {
  523. this.max_preserve_newlines = 0;
  524. }
  525. this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
  526. if (this.indent_with_tabs) {
  527. this.indent_char = '\t';
  528. // indent_size behavior changed after 1.8.6
  529. // It used to be that indent_size would be
  530. // set to 1 for indent_with_tabs. That is no longer needed and
  531. // actually doesn't make sense - why not use spaces? Further,
  532. // that might produce unexpected behavior - tabs being used
  533. // for single-column alignment. So, when indent_with_tabs is true
  534. // and indent_size is 1, reset indent_size to 4.
  535. if (this.indent_size === 1) {
  536. this.indent_size = 4;
  537. }
  538. }
  539. // Backwards compat with 1.3.x
  540. this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
  541. }
  542. Options.prototype._get_array = function(name, default_value) {
  543. var option_value = this.raw_options[name];
  544. var result = default_value || [];
  545. if (typeof option_value === 'object') {
  546. if (option_value !== null && typeof option_value.concat === 'function') {
  547. result = option_value.concat();
  548. }
  549. } else if (typeof option_value === 'string') {
  550. result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
  551. }
  552. return result;
  553. };
  554. Options.prototype._get_boolean = function(name, default_value) {
  555. var option_value = this.raw_options[name];
  556. var result = option_value === undefined ? !!default_value : !!option_value;
  557. return result;
  558. };
  559. Options.prototype._get_characters = function(name, default_value) {
  560. var option_value = this.raw_options[name];
  561. var result = default_value || '';
  562. if (typeof option_value === 'string') {
  563. result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
  564. }
  565. return result;
  566. };
  567. Options.prototype._get_number = function(name, default_value) {
  568. var option_value = this.raw_options[name];
  569. default_value = parseInt(default_value, 10);
  570. if (isNaN(default_value)) {
  571. default_value = 0;
  572. }
  573. var result = parseInt(option_value, 10);
  574. if (isNaN(result)) {
  575. result = default_value;
  576. }
  577. return result;
  578. };
  579. Options.prototype._get_selection = function(name, selection_list, default_value) {
  580. var result = this._get_selection_list(name, selection_list, default_value);
  581. if (result.length !== 1) {
  582. throw new Error(
  583. "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
  584. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  585. }
  586. return result[0];
  587. };
  588. Options.prototype._get_selection_list = function(name, selection_list, default_value) {
  589. if (!selection_list || selection_list.length === 0) {
  590. throw new Error("Selection list cannot be empty.");
  591. }
  592. default_value = default_value || [selection_list[0]];
  593. if (!this._is_valid_selection(default_value, selection_list)) {
  594. throw new Error("Invalid Default Value!");
  595. }
  596. var result = this._get_array(name, default_value);
  597. if (!this._is_valid_selection(result, selection_list)) {
  598. throw new Error(
  599. "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
  600. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  601. }
  602. return result;
  603. };
  604. Options.prototype._is_valid_selection = function(result, selection_list) {
  605. return result.length && selection_list.length &&
  606. !result.some(function(item) { return selection_list.indexOf(item) === -1; });
  607. };
  608. // merges child options up with the parent options object
  609. // Example: obj = {a: 1, b: {a: 2}}
  610. // mergeOpts(obj, 'b')
  611. //
  612. // Returns: {a: 2}
  613. function _mergeOpts(allOptions, childFieldName) {
  614. var finalOpts = {};
  615. allOptions = _normalizeOpts(allOptions);
  616. var name;
  617. for (name in allOptions) {
  618. if (name !== childFieldName) {
  619. finalOpts[name] = allOptions[name];
  620. }
  621. }
  622. //merge in the per type settings for the childFieldName
  623. if (childFieldName && allOptions[childFieldName]) {
  624. for (name in allOptions[childFieldName]) {
  625. finalOpts[name] = allOptions[childFieldName][name];
  626. }
  627. }
  628. return finalOpts;
  629. }
  630. function _normalizeOpts(options) {
  631. var convertedOpts = {};
  632. var key;
  633. for (key in options) {
  634. var newKey = key.replace(/-/g, "_");
  635. convertedOpts[newKey] = options[key];
  636. }
  637. return convertedOpts;
  638. }
  639. module.exports.Options = Options;
  640. module.exports.normalizeOpts = _normalizeOpts;
  641. module.exports.mergeOpts = _mergeOpts;
  642. /***/ }),
  643. /* 7 */,
  644. /* 8 */
  645. /***/ (function(module, exports, __webpack_require__) {
  646. "use strict";
  647. /*jshint node:true */
  648. /*
  649. The MIT License (MIT)
  650. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  651. Permission is hereby granted, free of charge, to any person
  652. obtaining a copy of this software and associated documentation files
  653. (the "Software"), to deal in the Software without restriction,
  654. including without limitation the rights to use, copy, modify, merge,
  655. publish, distribute, sublicense, and/or sell copies of the Software,
  656. and to permit persons to whom the Software is furnished to do so,
  657. subject to the following conditions:
  658. The above copyright notice and this permission notice shall be
  659. included in all copies or substantial portions of the Software.
  660. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  661. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  662. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  663. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  664. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  665. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  666. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  667. SOFTWARE.
  668. */
  669. function InputScanner(input_string) {
  670. this.__input = input_string || '';
  671. this.__input_length = this.__input.length;
  672. this.__position = 0;
  673. }
  674. InputScanner.prototype.restart = function() {
  675. this.__position = 0;
  676. };
  677. InputScanner.prototype.back = function() {
  678. if (this.__position > 0) {
  679. this.__position -= 1;
  680. }
  681. };
  682. InputScanner.prototype.hasNext = function() {
  683. return this.__position < this.__input_length;
  684. };
  685. InputScanner.prototype.next = function() {
  686. var val = null;
  687. if (this.hasNext()) {
  688. val = this.__input.charAt(this.__position);
  689. this.__position += 1;
  690. }
  691. return val;
  692. };
  693. InputScanner.prototype.peek = function(index) {
  694. var val = null;
  695. index = index || 0;
  696. index += this.__position;
  697. if (index >= 0 && index < this.__input_length) {
  698. val = this.__input.charAt(index);
  699. }
  700. return val;
  701. };
  702. InputScanner.prototype.test = function(pattern, index) {
  703. index = index || 0;
  704. index += this.__position;
  705. pattern.lastIndex = index;
  706. if (index >= 0 && index < this.__input_length) {
  707. var pattern_match = pattern.exec(this.__input);
  708. return pattern_match && pattern_match.index === index;
  709. } else {
  710. return false;
  711. }
  712. };
  713. InputScanner.prototype.testChar = function(pattern, index) {
  714. // test one character regex match
  715. var val = this.peek(index);
  716. return val !== null && pattern.test(val);
  717. };
  718. InputScanner.prototype.match = function(pattern) {
  719. pattern.lastIndex = this.__position;
  720. var pattern_match = pattern.exec(this.__input);
  721. if (pattern_match && pattern_match.index === this.__position) {
  722. this.__position += pattern_match[0].length;
  723. } else {
  724. pattern_match = null;
  725. }
  726. return pattern_match;
  727. };
  728. InputScanner.prototype.read = function(pattern) {
  729. var val = '';
  730. var match = this.match(pattern);
  731. if (match) {
  732. val = match[0];
  733. }
  734. return val;
  735. };
  736. InputScanner.prototype.readUntil = function(pattern, include_match) {
  737. var val = '';
  738. var match_index = this.__position;
  739. pattern.lastIndex = this.__position;
  740. var pattern_match = pattern.exec(this.__input);
  741. if (pattern_match) {
  742. if (include_match) {
  743. match_index = pattern_match.index + pattern_match[0].length;
  744. } else {
  745. match_index = pattern_match.index;
  746. }
  747. } else {
  748. match_index = this.__input_length;
  749. }
  750. val = this.__input.substring(this.__position, match_index);
  751. this.__position = match_index;
  752. return val;
  753. };
  754. InputScanner.prototype.readUntilAfter = function(pattern) {
  755. return this.readUntil(pattern, true);
  756. };
  757. /* css beautifier legacy helpers */
  758. InputScanner.prototype.peekUntilAfter = function(pattern) {
  759. var start = this.__position;
  760. var val = this.readUntilAfter(pattern);
  761. this.__position = start;
  762. return val;
  763. };
  764. InputScanner.prototype.lookBack = function(testVal) {
  765. var start = this.__position - 1;
  766. return start >= testVal.length && this.__input.substring(start - testVal.length, start)
  767. .toLowerCase() === testVal;
  768. };
  769. module.exports.InputScanner = InputScanner;
  770. /***/ }),
  771. /* 9 */
  772. /***/ (function(module, exports, __webpack_require__) {
  773. "use strict";
  774. /*jshint node:true */
  775. /*
  776. The MIT License (MIT)
  777. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  778. Permission is hereby granted, free of charge, to any person
  779. obtaining a copy of this software and associated documentation files
  780. (the "Software"), to deal in the Software without restriction,
  781. including without limitation the rights to use, copy, modify, merge,
  782. publish, distribute, sublicense, and/or sell copies of the Software,
  783. and to permit persons to whom the Software is furnished to do so,
  784. subject to the following conditions:
  785. The above copyright notice and this permission notice shall be
  786. included in all copies or substantial portions of the Software.
  787. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  788. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  789. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  790. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  791. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  792. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  793. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  794. SOFTWARE.
  795. */
  796. var InputScanner = __webpack_require__(8).InputScanner;
  797. var Token = __webpack_require__(3).Token;
  798. var TokenStream = __webpack_require__(10).TokenStream;
  799. var TOKEN = {
  800. START: 'TK_START',
  801. RAW: 'TK_RAW',
  802. EOF: 'TK_EOF'
  803. };
  804. var Tokenizer = function(input_string, options) {
  805. this._input = new InputScanner(input_string);
  806. this._options = options || {};
  807. this.__tokens = null;
  808. this.__newline_count = 0;
  809. this.__whitespace_before_token = '';
  810. this._whitespace_pattern = /[\n\r\t ]+/g;
  811. this._newline_pattern = /([^\n\r]*)(\r\n|[\n\r])?/g;
  812. };
  813. Tokenizer.prototype.tokenize = function() {
  814. this._input.restart();
  815. this.__tokens = new TokenStream();
  816. this._reset();
  817. var current;
  818. var previous = new Token(TOKEN.START, '');
  819. var open_token = null;
  820. var open_stack = [];
  821. var comments = new TokenStream();
  822. while (previous.type !== TOKEN.EOF) {
  823. current = this._get_next_token(previous, open_token);
  824. while (this._is_comment(current)) {
  825. comments.add(current);
  826. current = this._get_next_token(previous, open_token);
  827. }
  828. if (!comments.isEmpty()) {
  829. current.comments_before = comments;
  830. comments = new TokenStream();
  831. }
  832. current.parent = open_token;
  833. if (this._is_opening(current)) {
  834. open_stack.push(open_token);
  835. open_token = current;
  836. } else if (open_token && this._is_closing(current, open_token)) {
  837. current.opened = open_token;
  838. open_token.closed = current;
  839. open_token = open_stack.pop();
  840. current.parent = open_token;
  841. }
  842. current.previous = previous;
  843. previous.next = current;
  844. this.__tokens.add(current);
  845. previous = current;
  846. }
  847. return this.__tokens;
  848. };
  849. Tokenizer.prototype._is_first_token = function() {
  850. return this.__tokens.isEmpty();
  851. };
  852. Tokenizer.prototype._reset = function() {};
  853. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  854. this._readWhitespace();
  855. var resulting_string = this._input.read(/.+/g);
  856. if (resulting_string) {
  857. return this._create_token(TOKEN.RAW, resulting_string);
  858. } else {
  859. return this._create_token(TOKEN.EOF, '');
  860. }
  861. };
  862. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  863. return false;
  864. };
  865. Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
  866. return false;
  867. };
  868. Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
  869. return false;
  870. };
  871. Tokenizer.prototype._create_token = function(type, text) {
  872. var token = new Token(type, text, this.__newline_count, this.__whitespace_before_token);
  873. this.__newline_count = 0;
  874. this.__whitespace_before_token = '';
  875. return token;
  876. };
  877. Tokenizer.prototype._readWhitespace = function() {
  878. var resulting_string = this._input.read(this._whitespace_pattern);
  879. if (resulting_string === ' ') {
  880. this.__whitespace_before_token = resulting_string;
  881. } else if (resulting_string !== '') {
  882. this._newline_pattern.lastIndex = 0;
  883. var nextMatch = this._newline_pattern.exec(resulting_string);
  884. while (nextMatch[2]) {
  885. this.__newline_count += 1;
  886. nextMatch = this._newline_pattern.exec(resulting_string);
  887. }
  888. this.__whitespace_before_token = nextMatch[1];
  889. }
  890. };
  891. module.exports.Tokenizer = Tokenizer;
  892. module.exports.TOKEN = TOKEN;
  893. /***/ }),
  894. /* 10 */
  895. /***/ (function(module, exports, __webpack_require__) {
  896. "use strict";
  897. /*jshint node:true */
  898. /*
  899. The MIT License (MIT)
  900. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  901. Permission is hereby granted, free of charge, to any person
  902. obtaining a copy of this software and associated documentation files
  903. (the "Software"), to deal in the Software without restriction,
  904. including without limitation the rights to use, copy, modify, merge,
  905. publish, distribute, sublicense, and/or sell copies of the Software,
  906. and to permit persons to whom the Software is furnished to do so,
  907. subject to the following conditions:
  908. The above copyright notice and this permission notice shall be
  909. included in all copies or substantial portions of the Software.
  910. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  911. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  912. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  913. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  914. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  915. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  916. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  917. SOFTWARE.
  918. */
  919. function TokenStream(parent_token) {
  920. // private
  921. this.__tokens = [];
  922. this.__tokens_length = this.__tokens.length;
  923. this.__position = 0;
  924. this.__parent_token = parent_token;
  925. }
  926. TokenStream.prototype.restart = function() {
  927. this.__position = 0;
  928. };
  929. TokenStream.prototype.isEmpty = function() {
  930. return this.__tokens_length === 0;
  931. };
  932. TokenStream.prototype.hasNext = function() {
  933. return this.__position < this.__tokens_length;
  934. };
  935. TokenStream.prototype.next = function() {
  936. var val = null;
  937. if (this.hasNext()) {
  938. val = this.__tokens[this.__position];
  939. this.__position += 1;
  940. }
  941. return val;
  942. };
  943. TokenStream.prototype.peek = function(index) {
  944. var val = null;
  945. index = index || 0;
  946. index += this.__position;
  947. if (index >= 0 && index < this.__tokens_length) {
  948. val = this.__tokens[index];
  949. }
  950. return val;
  951. };
  952. TokenStream.prototype.add = function(token) {
  953. if (this.__parent_token) {
  954. token.parent = this.__parent_token;
  955. }
  956. this.__tokens.push(token);
  957. this.__tokens_length += 1;
  958. };
  959. module.exports.TokenStream = TokenStream;
  960. /***/ }),
  961. /* 11 */
  962. /***/ (function(module, exports, __webpack_require__) {
  963. "use strict";
  964. /*jshint node:true */
  965. /*
  966. The MIT License (MIT)
  967. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  968. Permission is hereby granted, free of charge, to any person
  969. obtaining a copy of this software and associated documentation files
  970. (the "Software"), to deal in the Software without restriction,
  971. including without limitation the rights to use, copy, modify, merge,
  972. publish, distribute, sublicense, and/or sell copies of the Software,
  973. and to permit persons to whom the Software is furnished to do so,
  974. subject to the following conditions:
  975. The above copyright notice and this permission notice shall be
  976. included in all copies or substantial portions of the Software.
  977. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  978. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  979. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  980. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  981. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  982. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  983. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  984. SOFTWARE.
  985. */
  986. function Directives(start_block_pattern, end_block_pattern) {
  987. start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
  988. end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
  989. this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
  990. this.__directive_pattern = / (\w+)[:](\w+)/g;
  991. this.__directives_end_ignore_pattern = new RegExp('(?:[\\s\\S]*?)((?:' + start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern + ')|$)', 'g');
  992. }
  993. Directives.prototype.get_directives = function(text) {
  994. if (!text.match(this.__directives_block_pattern)) {
  995. return null;
  996. }
  997. var directives = {};
  998. this.__directive_pattern.lastIndex = 0;
  999. var directive_match = this.__directive_pattern.exec(text);
  1000. while (directive_match) {
  1001. directives[directive_match[1]] = directive_match[2];
  1002. directive_match = this.__directive_pattern.exec(text);
  1003. }
  1004. return directives;
  1005. };
  1006. Directives.prototype.readIgnored = function(input) {
  1007. return input.read(this.__directives_end_ignore_pattern);
  1008. };
  1009. module.exports.Directives = Directives;
  1010. /***/ }),
  1011. /* 12 */,
  1012. /* 13 */,
  1013. /* 14 */,
  1014. /* 15 */
  1015. /***/ (function(module, exports, __webpack_require__) {
  1016. "use strict";
  1017. /*jshint node:true */
  1018. /*
  1019. The MIT License (MIT)
  1020. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1021. Permission is hereby granted, free of charge, to any person
  1022. obtaining a copy of this software and associated documentation files
  1023. (the "Software"), to deal in the Software without restriction,
  1024. including without limitation the rights to use, copy, modify, merge,
  1025. publish, distribute, sublicense, and/or sell copies of the Software,
  1026. and to permit persons to whom the Software is furnished to do so,
  1027. subject to the following conditions:
  1028. The above copyright notice and this permission notice shall be
  1029. included in all copies or substantial portions of the Software.
  1030. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1031. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1032. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1033. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1034. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1035. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1036. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1037. SOFTWARE.
  1038. */
  1039. var Beautifier = __webpack_require__(16).Beautifier,
  1040. Options = __webpack_require__(17).Options;
  1041. function style_html(html_source, options, js_beautify, css_beautify) {
  1042. var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
  1043. return beautifier.beautify();
  1044. }
  1045. module.exports = style_html;
  1046. module.exports.defaultOptions = function() {
  1047. return new Options();
  1048. };
  1049. /***/ }),
  1050. /* 16 */
  1051. /***/ (function(module, exports, __webpack_require__) {
  1052. "use strict";
  1053. /*jshint node:true */
  1054. /*
  1055. The MIT License (MIT)
  1056. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1057. Permission is hereby granted, free of charge, to any person
  1058. obtaining a copy of this software and associated documentation files
  1059. (the "Software"), to deal in the Software without restriction,
  1060. including without limitation the rights to use, copy, modify, merge,
  1061. publish, distribute, sublicense, and/or sell copies of the Software,
  1062. and to permit persons to whom the Software is furnished to do so,
  1063. subject to the following conditions:
  1064. The above copyright notice and this permission notice shall be
  1065. included in all copies or substantial portions of the Software.
  1066. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1067. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1068. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1069. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1070. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1071. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1072. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1073. SOFTWARE.
  1074. */
  1075. var Options = __webpack_require__(17).Options;
  1076. var Output = __webpack_require__(2).Output;
  1077. var Tokenizer = __webpack_require__(18).Tokenizer;
  1078. var TOKEN = __webpack_require__(18).TOKEN;
  1079. var lineBreak = /\r\n|[\r\n]/;
  1080. var allLineBreaks = /\r\n|[\r\n]/g;
  1081. var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions
  1082. this.indent_level = 0;
  1083. this.alignment_size = 0;
  1084. this.wrap_line_length = options.wrap_line_length;
  1085. this.max_preserve_newlines = options.max_preserve_newlines;
  1086. this.preserve_newlines = options.preserve_newlines;
  1087. this._output = new Output(options, base_indent_string);
  1088. };
  1089. Printer.prototype.current_line_has_match = function(pattern) {
  1090. return this._output.current_line.has_match(pattern);
  1091. };
  1092. Printer.prototype.set_space_before_token = function(value) {
  1093. this._output.space_before_token = value;
  1094. };
  1095. Printer.prototype.add_raw_token = function(token) {
  1096. this._output.add_raw_token(token);
  1097. };
  1098. Printer.prototype.print_preserved_newlines = function(raw_token) {
  1099. var newlines = 0;
  1100. if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
  1101. newlines = raw_token.newlines ? 1 : 0;
  1102. }
  1103. if (this.preserve_newlines) {
  1104. newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
  1105. }
  1106. for (var n = 0; n < newlines; n++) {
  1107. this.print_newline(n > 0);
  1108. }
  1109. return newlines !== 0;
  1110. };
  1111. Printer.prototype.traverse_whitespace = function(raw_token) {
  1112. if (raw_token.whitespace_before || raw_token.newlines) {
  1113. if (!this.print_preserved_newlines(raw_token)) {
  1114. this._output.space_before_token = true;
  1115. this.print_space_or_wrap(raw_token.text);
  1116. }
  1117. return true;
  1118. }
  1119. return false;
  1120. };
  1121. // Append a space to the given content (string array) or, if we are
  1122. // at the wrap_line_length, append a newline/indentation.
  1123. // return true if a newline was added, false if a space was added
  1124. Printer.prototype.print_space_or_wrap = function(text) {
  1125. if (this.wrap_line_length) {
  1126. if (this._output.current_line.get_character_count() + text.length + 1 >= this.wrap_line_length) { //insert a line when the wrap_line_length is reached
  1127. return this._output.add_new_line();
  1128. }
  1129. }
  1130. return false;
  1131. };
  1132. Printer.prototype.print_newline = function(force) {
  1133. this._output.add_new_line(force);
  1134. };
  1135. Printer.prototype.print_token = function(text) {
  1136. if (text) {
  1137. if (this._output.current_line.is_empty()) {
  1138. this._output.set_indent(this.indent_level, this.alignment_size);
  1139. }
  1140. this._output.add_token(text);
  1141. }
  1142. };
  1143. Printer.prototype.print_raw_text = function(text) {
  1144. this._output.current_line.push_raw(text);
  1145. };
  1146. Printer.prototype.indent = function() {
  1147. this.indent_level++;
  1148. };
  1149. Printer.prototype.unindent = function() {
  1150. if (this.indent_level > 0) {
  1151. this.indent_level--;
  1152. }
  1153. };
  1154. Printer.prototype.get_full_indent = function(level) {
  1155. level = this.indent_level + (level || 0);
  1156. if (level < 1) {
  1157. return '';
  1158. }
  1159. return this._output.get_indent_string(level);
  1160. };
  1161. var uses_beautifier = function(tag_check, start_token) {
  1162. var raw_token = start_token.next;
  1163. if (!start_token.closed) {
  1164. return false;
  1165. }
  1166. while (raw_token.type !== TOKEN.EOF && raw_token.closed !== start_token) {
  1167. if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
  1168. // For script and style tags that have a type attribute, only enable custom beautifiers for matching values
  1169. var peekEquals = raw_token.next ? raw_token.next : raw_token;
  1170. var peekValue = peekEquals.next ? peekEquals.next : peekEquals;
  1171. if (peekEquals.type === TOKEN.EQUALS && peekValue.type === TOKEN.VALUE) {
  1172. return (tag_check === 'style' && peekValue.text.search('text/css') > -1) ||
  1173. (tag_check === 'script' && peekValue.text.search(/(text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect)/) > -1);
  1174. }
  1175. return false;
  1176. }
  1177. raw_token = raw_token.next;
  1178. }
  1179. return true;
  1180. };
  1181. function in_array(what, arr) {
  1182. return arr.indexOf(what) !== -1;
  1183. }
  1184. function TagFrame(parent, parser_token, indent_level) {
  1185. this.parent = parent || null;
  1186. this.tag = parser_token ? parser_token.tag_name : '';
  1187. this.indent_level = indent_level || 0;
  1188. this.parser_token = parser_token || null;
  1189. }
  1190. function TagStack(printer) {
  1191. this._printer = printer;
  1192. this._current_frame = null;
  1193. }
  1194. TagStack.prototype.get_parser_token = function() {
  1195. return this._current_frame ? this._current_frame.parser_token : null;
  1196. };
  1197. TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object
  1198. var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
  1199. this._current_frame = new_frame;
  1200. };
  1201. TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer
  1202. var parser_token = null;
  1203. if (frame) {
  1204. parser_token = frame.parser_token;
  1205. this._printer.indent_level = frame.indent_level;
  1206. this._current_frame = frame.parent;
  1207. }
  1208. return parser_token;
  1209. };
  1210. TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer
  1211. var frame = this._current_frame;
  1212. while (frame) { //till we reach '' (the initial value);
  1213. if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it
  1214. break;
  1215. } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
  1216. frame = null;
  1217. break;
  1218. }
  1219. frame = frame.parent;
  1220. }
  1221. return frame;
  1222. };
  1223. TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer
  1224. var frame = this._get_frame([tag], stop_list);
  1225. return this._try_pop_frame(frame);
  1226. };
  1227. TagStack.prototype.indent_to_tag = function(tag_list) {
  1228. var frame = this._get_frame(tag_list);
  1229. if (frame) {
  1230. this._printer.indent_level = frame.indent_level;
  1231. }
  1232. };
  1233. function Beautifier(source_text, options, js_beautify, css_beautify) {
  1234. //Wrapper function to invoke all the necessary constructors and deal with the output.
  1235. this._source_text = source_text || '';
  1236. options = options || {};
  1237. this._js_beautify = js_beautify;
  1238. this._css_beautify = css_beautify;
  1239. this._tag_stack = null;
  1240. // Allow the setting of language/file-type specific options
  1241. // with inheritance of overall settings
  1242. var optionHtml = new Options(options, 'html');
  1243. this._options = optionHtml;
  1244. this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
  1245. this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
  1246. this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
  1247. this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
  1248. this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
  1249. this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
  1250. }
  1251. Beautifier.prototype.beautify = function() {
  1252. // if disabled, return the input unchanged.
  1253. if (this._options.disabled) {
  1254. return this._source_text;
  1255. }
  1256. var source_text = this._source_text;
  1257. var eol = this._options.eol;
  1258. if (this._options.eol === 'auto') {
  1259. eol = '\n';
  1260. if (source_text && lineBreak.test(source_text)) {
  1261. eol = source_text.match(lineBreak)[0];
  1262. }
  1263. }
  1264. // HACK: newline parsing inconsistent. This brute force normalizes the input.
  1265. source_text = source_text.replace(allLineBreaks, '\n');
  1266. var baseIndentString = '';
  1267. // Including commented out text would change existing html beautifier behavior to autodetect base indent.
  1268. // baseIndentString = source_text.match(/^[\t ]*/)[0];
  1269. var last_token = {
  1270. text: '',
  1271. type: ''
  1272. };
  1273. var last_tag_token = new TagOpenParserToken();
  1274. var printer = new Printer(this._options, baseIndentString);
  1275. var tokens = new Tokenizer(source_text, this._options).tokenize();
  1276. this._tag_stack = new TagStack(printer);
  1277. var parser_token = null;
  1278. var raw_token = tokens.next();
  1279. while (raw_token.type !== TOKEN.EOF) {
  1280. if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
  1281. parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token);
  1282. last_tag_token = parser_token;
  1283. } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
  1284. (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
  1285. parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, tokens);
  1286. } else if (raw_token.type === TOKEN.TAG_CLOSE) {
  1287. parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
  1288. } else if (raw_token.type === TOKEN.TEXT) {
  1289. parser_token = this._handle_text(printer, raw_token, last_tag_token);
  1290. } else {
  1291. // This should never happen, but if it does. Print the raw token
  1292. printer.add_raw_token(raw_token);
  1293. }
  1294. last_token = parser_token;
  1295. raw_token = tokens.next();
  1296. }
  1297. var sweet_code = printer._output.get_code(eol);
  1298. return sweet_code;
  1299. };
  1300. Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
  1301. var parser_token = {
  1302. text: raw_token.text,
  1303. type: raw_token.type
  1304. };
  1305. printer.alignment_size = 0;
  1306. last_tag_token.tag_complete = true;
  1307. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '');
  1308. if (last_tag_token.is_unformatted) {
  1309. printer.add_raw_token(raw_token);
  1310. } else {
  1311. if (last_tag_token.tag_start_char === '<') {
  1312. printer.set_space_before_token(raw_token.text[0] === '/'); // space before />, no space before >
  1313. if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
  1314. printer.print_newline(false);
  1315. }
  1316. }
  1317. printer.print_token(raw_token.text);
  1318. }
  1319. if (last_tag_token.indent_content &&
  1320. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  1321. printer.indent();
  1322. // only indent once per opened tag
  1323. last_tag_token.indent_content = false;
  1324. }
  1325. return parser_token;
  1326. };
  1327. Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
  1328. var parser_token = {
  1329. text: raw_token.text,
  1330. type: raw_token.type
  1331. };
  1332. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '');
  1333. if (last_tag_token.is_unformatted) {
  1334. printer.add_raw_token(raw_token);
  1335. } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
  1336. // For the insides of handlebars allow newlines or a single space between open and contents
  1337. if (printer.print_preserved_newlines(raw_token)) {
  1338. printer.print_raw_text(raw_token.whitespace_before + raw_token.text);
  1339. } else {
  1340. printer.print_token(raw_token.text);
  1341. }
  1342. } else {
  1343. if (raw_token.type === TOKEN.ATTRIBUTE) {
  1344. printer.set_space_before_token(true);
  1345. last_tag_token.attr_count += 1;
  1346. } else if (raw_token.type === TOKEN.EQUALS) { //no space before =
  1347. printer.set_space_before_token(false);
  1348. } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
  1349. printer.set_space_before_token(false);
  1350. }
  1351. if (printer._output.space_before_token && last_tag_token.tag_start_char === '<') {
  1352. // Allow the current attribute to wrap
  1353. // Set wrapped to true if the line is wrapped
  1354. var wrapped = printer.print_space_or_wrap(raw_token.text);
  1355. if (raw_token.type === TOKEN.ATTRIBUTE) {
  1356. if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
  1357. printer.traverse_whitespace(raw_token);
  1358. wrapped = wrapped || raw_token.newlines !== 0;
  1359. }
  1360. // Save whether we have wrapped any attributes
  1361. last_tag_token.has_wrapped_attrs = last_tag_token.has_wrapped_attrs || wrapped;
  1362. if (this._is_wrap_attributes_force) {
  1363. var force_attr_wrap = last_tag_token.attr_count > 1;
  1364. if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
  1365. var is_only_attribute = true;
  1366. var peek_index = 0;
  1367. var peek_token;
  1368. do {
  1369. peek_token = tokens.peek(peek_index);
  1370. if (peek_token.type === TOKEN.ATTRIBUTE) {
  1371. is_only_attribute = false;
  1372. break;
  1373. }
  1374. peek_index += 1;
  1375. } while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
  1376. force_attr_wrap = !is_only_attribute;
  1377. }
  1378. if (force_attr_wrap) {
  1379. printer.print_newline(false);
  1380. last_tag_token.has_wrapped_attrs = true;
  1381. }
  1382. }
  1383. }
  1384. }
  1385. printer.print_token(raw_token.text);
  1386. }
  1387. return parser_token;
  1388. };
  1389. Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
  1390. var parser_token = {
  1391. text: raw_token.text,
  1392. type: 'TK_CONTENT'
  1393. };
  1394. if (last_tag_token.custom_beautifier) { //check if we need to format javascript
  1395. this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
  1396. } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
  1397. printer.add_raw_token(raw_token);
  1398. } else {
  1399. printer.traverse_whitespace(raw_token);
  1400. printer.print_token(raw_token.text);
  1401. }
  1402. return parser_token;
  1403. };
  1404. Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
  1405. if (raw_token.text !== '') {
  1406. printer.print_newline(false);
  1407. var text = raw_token.text,
  1408. _beautifier,
  1409. script_indent_level = 1;
  1410. if (last_tag_token.tag_name === 'script') {
  1411. _beautifier = typeof this._js_beautify === 'function' && this._js_beautify;
  1412. } else if (last_tag_token.tag_name === 'style') {
  1413. _beautifier = typeof this._css_beautify === 'function' && this._css_beautify;
  1414. }
  1415. if (this._options.indent_scripts === "keep") {
  1416. script_indent_level = 0;
  1417. } else if (this._options.indent_scripts === "separate") {
  1418. script_indent_level = -printer.indent_level;
  1419. }
  1420. var indentation = printer.get_full_indent(script_indent_level);
  1421. // if there is at least one empty line at the end of this text, strip it
  1422. // we'll be adding one back after the text but before the containing tag.
  1423. text = text.replace(/\n[ \t]*$/, '');
  1424. if (_beautifier) {
  1425. // call the Beautifier if avaliable
  1426. var Child_options = function() {
  1427. this.eol = '\n';
  1428. };
  1429. Child_options.prototype = this._options.raw_options;
  1430. var child_options = new Child_options();
  1431. text = _beautifier(indentation + text, child_options);
  1432. } else {
  1433. // simply indent the string otherwise
  1434. var white = text.match(/^\s*/)[0];
  1435. var _level = white.match(/[^\n\r]*$/)[0].split(this._options.indent_string).length - 1;
  1436. var reindent = this._get_full_indent(script_indent_level - _level);
  1437. text = (indentation + text.trim())
  1438. .replace(/\r\n|\r|\n/g, '\n' + reindent);
  1439. }
  1440. if (text) {
  1441. printer.print_raw_text(text);
  1442. printer.print_newline(true);
  1443. }
  1444. }
  1445. };
  1446. Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
  1447. var parser_token = this._get_tag_open_token(raw_token);
  1448. if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
  1449. raw_token.type === TOKEN.TAG_OPEN && raw_token.text.indexOf('</') === 0) {
  1450. // End element tags for unformatted or content_unformatted elements
  1451. // are printed raw to keep any newlines inside them exactly the same.
  1452. printer.add_raw_token(raw_token);
  1453. } else {
  1454. printer.traverse_whitespace(raw_token);
  1455. this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
  1456. printer.print_token(raw_token.text);
  1457. }
  1458. //indent attributes an auto, forced, aligned or forced-align line-wrap
  1459. if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
  1460. parser_token.alignment_size = raw_token.text.length + 1;
  1461. }
  1462. if (!parser_token.tag_complete && !parser_token.is_unformatted) {
  1463. printer.alignment_size = parser_token.alignment_size;
  1464. }
  1465. return parser_token;
  1466. };
  1467. var TagOpenParserToken = function(parent, raw_token) {
  1468. this.parent = parent || null;
  1469. this.text = '';
  1470. this.type = 'TK_TAG_OPEN';
  1471. this.tag_name = '';
  1472. this.is_inline_element = false;
  1473. this.is_unformatted = false;
  1474. this.is_content_unformatted = false;
  1475. this.is_empty_element = false;
  1476. this.is_start_tag = false;
  1477. this.is_end_tag = false;
  1478. this.indent_content = false;
  1479. this.multiline_content = false;
  1480. this.custom_beautifier = false;
  1481. this.start_tag_token = null;
  1482. this.attr_count = 0;
  1483. this.has_wrapped_attrs = false;
  1484. this.alignment_size = 0;
  1485. this.tag_complete = false;
  1486. this.tag_start_char = '';
  1487. this.tag_check = '';
  1488. if (!raw_token) {
  1489. this.tag_complete = true;
  1490. } else {
  1491. var tag_check_match;
  1492. this.tag_start_char = raw_token.text[0];
  1493. this.text = raw_token.text;
  1494. if (this.tag_start_char === '<') {
  1495. tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
  1496. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  1497. } else {
  1498. tag_check_match = raw_token.text.match(/^{{\#?([^\s}]+)/);
  1499. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  1500. }
  1501. this.tag_check = this.tag_check.toLowerCase();
  1502. if (raw_token.type === TOKEN.COMMENT) {
  1503. this.tag_complete = true;
  1504. }
  1505. this.is_start_tag = this.tag_check.charAt(0) !== '/';
  1506. this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
  1507. this.is_end_tag = !this.is_start_tag ||
  1508. (raw_token.closed && raw_token.closed.text === '/>');
  1509. // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
  1510. this.is_end_tag = this.is_end_tag ||
  1511. (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(2)))));
  1512. }
  1513. };
  1514. Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
  1515. var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
  1516. parser_token.alignment_size = this._options.wrap_attributes_indent_size;
  1517. parser_token.is_end_tag = parser_token.is_end_tag ||
  1518. in_array(parser_token.tag_check, this._options.void_elements);
  1519. parser_token.is_empty_element = parser_token.tag_complete ||
  1520. (parser_token.is_start_tag && parser_token.is_end_tag);
  1521. parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
  1522. parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
  1523. parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_start_char === '{';
  1524. return parser_token;
  1525. };
  1526. Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
  1527. if (!parser_token.is_empty_element) {
  1528. if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  1529. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors
  1530. } else { // it's a start-tag
  1531. // check if this tag is starting an element that has optional end element
  1532. // and do an ending needed
  1533. this._do_optional_end_element(parser_token);
  1534. this._tag_stack.record_tag(parser_token); //push it on the tag stack
  1535. if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
  1536. !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
  1537. parser_token.custom_beautifier = uses_beautifier(parser_token.tag_check, raw_token);
  1538. }
  1539. }
  1540. }
  1541. if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line
  1542. printer.print_newline(false);
  1543. if (!printer._output.just_added_blankline()) {
  1544. printer.print_newline(true);
  1545. }
  1546. }
  1547. if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /)
  1548. // if you hit an else case, reset the indent level if you are inside an:
  1549. // 'if', 'unless', or 'each' block.
  1550. if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
  1551. this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
  1552. parser_token.indent_content = true;
  1553. // Don't add a newline if opening {{#if}} tag is on the current line
  1554. var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
  1555. if (!foundIfOnCurrentLine) {
  1556. printer.print_newline(false);
  1557. }
  1558. }
  1559. // Don't add a newline before elements that should remain where they are.
  1560. if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
  1561. last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) {
  1562. //Do nothing. Leave comments on same line.
  1563. } else if (!parser_token.is_inline_element && !parser_token.is_unformatted) {
  1564. printer.print_newline(false);
  1565. }
  1566. } else if (parser_token.is_unformatted || parser_token.is_content_unformatted) {
  1567. if (!parser_token.is_inline_element && !parser_token.is_unformatted) {
  1568. printer.print_newline(false);
  1569. }
  1570. } else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  1571. if ((parser_token.start_tag_token && parser_token.start_tag_token.multiline_content) ||
  1572. !(parser_token.is_inline_element ||
  1573. (last_tag_token.is_inline_element) ||
  1574. (last_token.type === TOKEN.TAG_CLOSE &&
  1575. parser_token.start_tag_token === last_tag_token) ||
  1576. (last_token.type === 'TK_CONTENT')
  1577. )) {
  1578. printer.print_newline(false);
  1579. }
  1580. } else { // it's a start-tag
  1581. parser_token.indent_content = !parser_token.custom_beautifier;
  1582. if (parser_token.tag_start_char === '<') {
  1583. if (parser_token.tag_name === 'html') {
  1584. parser_token.indent_content = this._options.indent_inner_html;
  1585. } else if (parser_token.tag_name === 'head') {
  1586. parser_token.indent_content = this._options.indent_head_inner_html;
  1587. } else if (parser_token.tag_name === 'body') {
  1588. parser_token.indent_content = this._options.indent_body_inner_html;
  1589. }
  1590. }
  1591. if (!parser_token.is_inline_element && last_token.type !== 'TK_CONTENT') {
  1592. if (parser_token.parent) {
  1593. parser_token.parent.multiline_content = true;
  1594. }
  1595. printer.print_newline(false);
  1596. }
  1597. }
  1598. };
  1599. //To be used for <p> tag special case:
  1600. //var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
  1601. Beautifier.prototype._do_optional_end_element = function(parser_token) {
  1602. // NOTE: cases of "if there is no more content in the parent element"
  1603. // are handled automatically by the beautifier.
  1604. // It assumes parent or ancestor close tag closes all children.
  1605. // https://www.w3.org/TR/html5/syntax.html#optional-tags
  1606. if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
  1607. return;
  1608. } else if (parser_token.tag_name === 'body') {
  1609. // A head element鈥檚 end tag may be omitted if the head element is not immediately followed by a space character or a comment.
  1610. this._tag_stack.try_pop('head');
  1611. //} else if (parser_token.tag_name === 'body') {
  1612. // DONE: A body element鈥檚 end tag may be omitted if the body element is not immediately followed by a comment.
  1613. } else if (parser_token.tag_name === 'li') {
  1614. // An li element鈥檚 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.
  1615. this._tag_stack.try_pop('li', ['ol', 'ul']);
  1616. } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
  1617. // A dd element鈥檚 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.
  1618. // A dt element鈥檚 end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.
  1619. this._tag_stack.try_pop('dt', ['dl']);
  1620. this._tag_stack.try_pop('dd', ['dl']);
  1621. //} else if (p_closers.indexOf(parser_token.tag_name) !== -1) {
  1622. //TODO: THIS IS A BUG FARM. We are not putting this into 1.8.0 as it is likely to blow up.
  1623. //A p element鈥檚 end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hr, main, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.
  1624. //this._tag_stack.try_pop('p', ['body']);
  1625. } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
  1626. // An rt element鈥檚 end tag may be omitted if the rt element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
  1627. // An rp element鈥檚 end tag may be omitted if the rp element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
  1628. this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
  1629. this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
  1630. } else if (parser_token.tag_name === 'optgroup') {
  1631. // An optgroup element鈥檚 end tag may be omitted if the optgroup element is immediately followed by another optgroup element, or if there is no more content in the parent element.
  1632. // An option element鈥檚 end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
  1633. this._tag_stack.try_pop('optgroup', ['select']);
  1634. //this._tag_stack.try_pop('option', ['select']);
  1635. } else if (parser_token.tag_name === 'option') {
  1636. // An option element鈥檚 end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
  1637. this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
  1638. } else if (parser_token.tag_name === 'colgroup') {
  1639. // DONE: A colgroup element鈥檚 end tag may be omitted if the colgroup element is not immediately followed by a space character or a comment.
  1640. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  1641. this._tag_stack.try_pop('caption', ['table']);
  1642. } else if (parser_token.tag_name === 'thead') {
  1643. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  1644. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  1645. this._tag_stack.try_pop('caption', ['table']);
  1646. this._tag_stack.try_pop('colgroup', ['table']);
  1647. //} else if (parser_token.tag_name === 'caption') {
  1648. // DONE: A caption element鈥檚 end tag may be omitted if the caption element is not immediately followed by a space character or a comment.
  1649. } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
  1650. // A thead element鈥檚 end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.
  1651. // A tbody element鈥檚 end tag may be omitted if the tbody element is immediately followed by a tbody or tfoot element, or if there is no more content in the parent element.
  1652. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  1653. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  1654. this._tag_stack.try_pop('caption', ['table']);
  1655. this._tag_stack.try_pop('colgroup', ['table']);
  1656. this._tag_stack.try_pop('thead', ['table']);
  1657. this._tag_stack.try_pop('tbody', ['table']);
  1658. //} else if (parser_token.tag_name === 'tfoot') {
  1659. // DONE: A tfoot element鈥檚 end tag may be omitted if there is no more content in the parent element.
  1660. } else if (parser_token.tag_name === 'tr') {
  1661. // A tr element鈥檚 end tag may be omitted if the tr element is immediately followed by another tr element, or if there is no more content in the parent element.
  1662. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  1663. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  1664. this._tag_stack.try_pop('caption', ['table']);
  1665. this._tag_stack.try_pop('colgroup', ['table']);
  1666. this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
  1667. } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
  1668. // A td element鈥檚 end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
  1669. // A th element鈥檚 end tag may be omitted if the th element is immediately followed by a td or th element, or if there is no more content in the parent element.
  1670. this._tag_stack.try_pop('td', ['tr']);
  1671. this._tag_stack.try_pop('th', ['tr']);
  1672. }
  1673. // Start element omission not handled currently
  1674. // A head element鈥檚 start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.
  1675. // A tbody element鈥檚 start tag may be omitted if the first thing inside the tbody element is a tr element, and if the element is not immediately preceded by a tbody, thead, or tfoot element whose end tag has been omitted. (It can鈥檛 be omitted if the element is empty.)
  1676. // A colgroup element鈥檚 start tag may be omitted if the first thing inside the colgroup element is a col element, and if the element is not immediately preceded by another colgroup element whose end tag has been omitted. (It can鈥檛 be omitted if the element is empty.)
  1677. // Fix up the parent of the parser token
  1678. parser_token.parent = this._tag_stack.get_parser_token();
  1679. };
  1680. module.exports.Beautifier = Beautifier;
  1681. /***/ }),
  1682. /* 17 */
  1683. /***/ (function(module, exports, __webpack_require__) {
  1684. "use strict";
  1685. /*jshint node:true */
  1686. /*
  1687. The MIT License (MIT)
  1688. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1689. Permission is hereby granted, free of charge, to any person
  1690. obtaining a copy of this software and associated documentation files
  1691. (the "Software"), to deal in the Software without restriction,
  1692. including without limitation the rights to use, copy, modify, merge,
  1693. publish, distribute, sublicense, and/or sell copies of the Software,
  1694. and to permit persons to whom the Software is furnished to do so,
  1695. subject to the following conditions:
  1696. The above copyright notice and this permission notice shall be
  1697. included in all copies or substantial portions of the Software.
  1698. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1699. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1700. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1701. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1702. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1703. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1704. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1705. SOFTWARE.
  1706. */
  1707. debugger;
  1708. var BaseOptions = __webpack_require__(6).Options;
  1709. function Options(options) {
  1710. BaseOptions.call(this, options, 'html');
  1711. this.indent_inner_html = this._get_boolean('indent_inner_html');
  1712. this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
  1713. this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
  1714. this.indent_handlebars = this._get_boolean('indent_handlebars', true);
  1715. this.wrap_attributes = this._get_selection('wrap_attributes',
  1716. ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
  1717. this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
  1718. this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
  1719. this.inline = this._get_array('inline', [
  1720. // https://www.w3.org/TR/html5/dom.html#phrasing-content
  1721. 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
  1722. 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
  1723. 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
  1724. 'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
  1725. 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
  1726. 'video', 'wbr', 'text',
  1727. // prexisting - not sure of full effect of removing, leaving in
  1728. 'acronym', 'address', 'big', 'dt', 'ins', 'strike', 'tt'
  1729. ]);
  1730. this.void_elements = this._get_array('void_elements', [
  1731. // HTLM void elements - aka self-closing tags - aka singletons
  1732. // https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
  1733. 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
  1734. 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
  1735. // NOTE: Optional tags are too complex for a simple list
  1736. // they are hard coded in _do_optional_end_element
  1737. // Doctype and xml elements
  1738. '!doctype', '?xml',
  1739. // ?php and ?= tags
  1740. '?php', '?=',
  1741. // other tags that were in this list, keeping just in case
  1742. 'basefont', 'isindex'
  1743. ]);
  1744. this.unformatted = this._get_array('unformatted', []);
  1745. this.content_unformatted = this._get_array('content_unformatted', [
  1746. 'pre', 'textarea'
  1747. ]);
  1748. this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
  1749. }
  1750. Options.prototype = new BaseOptions();
  1751. module.exports.Options = Options;
  1752. /***/ }),
  1753. /* 18 */
  1754. /***/ (function(module, exports, __webpack_require__) {
  1755. "use strict";
  1756. /*jshint node:true */
  1757. /*
  1758. The MIT License (MIT)
  1759. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1760. Permission is hereby granted, free of charge, to any person
  1761. obtaining a copy of this software and associated documentation files
  1762. (the "Software"), to deal in the Software without restriction,
  1763. including without limitation the rights to use, copy, modify, merge,
  1764. publish, distribute, sublicense, and/or sell copies of the Software,
  1765. and to permit persons to whom the Software is furnished to do so,
  1766. subject to the following conditions:
  1767. The above copyright notice and this permission notice shall be
  1768. included in all copies or substantial portions of the Software.
  1769. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1770. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1771. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1772. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1773. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1774. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1775. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1776. SOFTWARE.
  1777. */
  1778. var BaseTokenizer = __webpack_require__(9).Tokenizer;
  1779. var BASETOKEN = __webpack_require__(9).TOKEN;
  1780. var Directives = __webpack_require__(11).Directives;
  1781. var TOKEN = {
  1782. TAG_OPEN: 'TK_TAG_OPEN',
  1783. TAG_CLOSE: 'TK_TAG_CLOSE',
  1784. ATTRIBUTE: 'TK_ATTRIBUTE',
  1785. EQUALS: 'TK_EQUALS',
  1786. VALUE: 'TK_VALUE',
  1787. COMMENT: 'TK_COMMENT',
  1788. TEXT: 'TK_TEXT',
  1789. UNKNOWN: 'TK_UNKNOWN',
  1790. START: BASETOKEN.START,
  1791. RAW: BASETOKEN.RAW,
  1792. EOF: BASETOKEN.EOF
  1793. };
  1794. var directives_core = new Directives(/<\!--/, /-->/);
  1795. var Tokenizer = function(input_string, options) {
  1796. BaseTokenizer.call(this, input_string, options);
  1797. this._current_tag_name = '';
  1798. // Words end at whitespace or when a tag starts
  1799. // if we are indenting handlebars, they are considered tags
  1800. this._word_pattern = this._options.indent_handlebars ? /[\n\r\t <]|{{/g : /[\n\r\t <]/g;
  1801. };
  1802. Tokenizer.prototype = new BaseTokenizer();
  1803. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  1804. return false; //current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.UNKNOWN;
  1805. };
  1806. Tokenizer.prototype._is_opening = function(current_token) {
  1807. return current_token.type === TOKEN.TAG_OPEN;
  1808. };
  1809. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  1810. return current_token.type === TOKEN.TAG_CLOSE &&
  1811. (open_token && (
  1812. ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
  1813. (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
  1814. };
  1815. Tokenizer.prototype._reset = function() {
  1816. this._current_tag_name = '';
  1817. };
  1818. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  1819. this._readWhitespace();
  1820. var token = null;
  1821. var c = this._input.peek();
  1822. if (c === null) {
  1823. return this._create_token(TOKEN.EOF, '');
  1824. }
  1825. token = token || this._read_attribute(c, previous_token, open_token);
  1826. token = token || this._read_raw_content(previous_token, open_token);
  1827. token = token || this._read_comment(c);
  1828. token = token || this._read_open(c, open_token);
  1829. token = token || this._read_close(c, open_token);
  1830. token = token || this._read_content_word();
  1831. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  1832. return token;
  1833. };
  1834. Tokenizer.prototype._read_comment = function(c) { // jshint unused:false
  1835. var token = null;
  1836. if (c === '<' || c === '{') {
  1837. var peek1 = this._input.peek(1);
  1838. var peek2 = this._input.peek(2);
  1839. if ((c === '<' && (peek1 === '!' || peek1 === '?' || peek1 === '%')) ||
  1840. this._options.indent_handlebars && c === '{' && peek1 === '{' && peek2 === '!') {
  1841. //if we're in a comment, do something special
  1842. // We treat all comments as literals, even more than preformatted tags
  1843. // we just look for the appropriate close tag
  1844. // this is will have very poor perf, but will work for now.
  1845. var comment = '',
  1846. delimiter = '>',
  1847. matched = false;
  1848. var input_char = this._input.next();
  1849. while (input_char) {
  1850. comment += input_char;
  1851. // only need to check for the delimiter if the last chars match
  1852. if (comment.charAt(comment.length - 1) === delimiter.charAt(delimiter.length - 1) &&
  1853. comment.indexOf(delimiter) !== -1) {
  1854. break;
  1855. }
  1856. // only need to search for custom delimiter for the first few characters
  1857. if (!matched) {
  1858. matched = comment.length > 10;
  1859. if (comment.indexOf('<![if') === 0) { //peek for <![if conditional comment
  1860. delimiter = '<![endif]>';
  1861. matched = true;
  1862. } else if (comment.indexOf('<![cdata[') === 0) { //if it's a <[cdata[ comment...
  1863. delimiter = ']]>';
  1864. matched = true;
  1865. } else if (comment.indexOf('<![') === 0) { // some other ![ comment? ...
  1866. delimiter = ']>';
  1867. matched = true;
  1868. } else if (comment.indexOf('<!--') === 0) { // <!-- comment ...
  1869. delimiter = '-->';
  1870. matched = true;
  1871. } else if (comment.indexOf('{{!--') === 0) { // {{!-- handlebars comment
  1872. delimiter = '--}}';
  1873. matched = true;
  1874. } else if (comment.indexOf('{{!') === 0) { // {{! handlebars comment
  1875. if (comment.length === 5 && comment.indexOf('{{!--') === -1) {
  1876. delimiter = '}}';
  1877. matched = true;
  1878. }
  1879. } else if (comment.indexOf('<?') === 0) { // {{! handlebars comment
  1880. delimiter = '?>';
  1881. matched = true;
  1882. } else if (comment.indexOf('<%') === 0) { // {{! handlebars comment
  1883. delimiter = '%>';
  1884. matched = true;
  1885. }
  1886. }
  1887. input_char = this._input.next();
  1888. }
  1889. var directives = directives_core.get_directives(comment);
  1890. if (directives && directives.ignore === 'start') {
  1891. comment += directives_core.readIgnored(this._input);
  1892. }
  1893. token = this._create_token(TOKEN.COMMENT, comment);
  1894. token.directives = directives;
  1895. }
  1896. }
  1897. return token;
  1898. };
  1899. Tokenizer.prototype._read_open = function(c, open_token) {
  1900. var resulting_string = null;
  1901. var token = null;
  1902. if (!open_token) {
  1903. if (c === '<') {
  1904. resulting_string = this._input.read(/<(?:[^\n\r\t >{][^\n\r\t >{/]*)?/g);
  1905. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  1906. } else if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
  1907. resulting_string = this._input.readUntil(/[\n\r\t }]/g);
  1908. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  1909. }
  1910. }
  1911. return token;
  1912. };
  1913. Tokenizer.prototype._read_close = function(c, open_token) {
  1914. var resulting_string = null;
  1915. var token = null;
  1916. if (open_token) {
  1917. if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
  1918. resulting_string = this._input.next();
  1919. if (c === '/') { // for close tag "/>"
  1920. resulting_string += this._input.next();
  1921. }
  1922. token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
  1923. } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
  1924. this._input.next();
  1925. this._input.next();
  1926. token = this._create_token(TOKEN.TAG_CLOSE, '}}');
  1927. }
  1928. }
  1929. return token;
  1930. };
  1931. Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
  1932. var token = null;
  1933. var resulting_string = '';
  1934. if (open_token && open_token.text[0] === '<') {
  1935. if (c === '=') {
  1936. token = this._create_token(TOKEN.EQUALS, this._input.next());
  1937. } else if (c === '"' || c === "'") {
  1938. var content = this._input.next();
  1939. var input_string = '';
  1940. var string_pattern = new RegExp(c + '|{{', 'g');
  1941. while (this._input.hasNext()) {
  1942. input_string = this._input.readUntilAfter(string_pattern);
  1943. content += input_string;
  1944. if (input_string[input_string.length - 1] === '"' || input_string[input_string.length - 1] === "'") {
  1945. break;
  1946. } else if (this._input.hasNext()) {
  1947. content += this._input.readUntilAfter(/}}/g);
  1948. }
  1949. }
  1950. token = this._create_token(TOKEN.VALUE, content);
  1951. } else {
  1952. if (c === '{' && this._input.peek(1) === '{') {
  1953. resulting_string = this._input.readUntilAfter(/}}/g);
  1954. } else {
  1955. resulting_string = this._input.readUntil(/[\n\r\t =\/>]/g);
  1956. }
  1957. if (resulting_string) {
  1958. if (previous_token.type === TOKEN.EQUALS) {
  1959. token = this._create_token(TOKEN.VALUE, resulting_string);
  1960. } else {
  1961. token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
  1962. }
  1963. }
  1964. }
  1965. }
  1966. return token;
  1967. };
  1968. Tokenizer.prototype._is_content_unformatted = function(tag_name) {
  1969. // void_elements have no content and so cannot have unformatted content
  1970. // script and style tags should always be read as unformatted content
  1971. // finally content_unformatted and unformatted element contents are unformatted
  1972. return this._options.void_elements.indexOf(tag_name) === -1 &&
  1973. (tag_name === 'script' || tag_name === 'style' ||
  1974. this._options.content_unformatted.indexOf(tag_name) !== -1 ||
  1975. this._options.unformatted.indexOf(tag_name) !== -1);
  1976. };
  1977. Tokenizer.prototype._read_raw_content = function(previous_token, open_token) { // jshint unused:false
  1978. var resulting_string = '';
  1979. if (open_token && open_token.text[0] === '{') {
  1980. resulting_string = this._input.readUntil(/}}/g);
  1981. } else if (previous_token.type === TOKEN.TAG_CLOSE && (previous_token.opened.text[0] === '<')) {
  1982. var tag_name = previous_token.opened.text.substr(1).toLowerCase();
  1983. if (this._is_content_unformatted(tag_name)) {
  1984. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  1985. }
  1986. }
  1987. if (resulting_string) {
  1988. return this._create_token(TOKEN.TEXT, resulting_string);
  1989. }
  1990. return null;
  1991. };
  1992. Tokenizer.prototype._read_content_word = function() {
  1993. // if we get here and we see handlebars treat them as plain text
  1994. var resulting_string = this._input.readUntil(this._word_pattern);
  1995. if (resulting_string) {
  1996. return this._create_token(TOKEN.TEXT, resulting_string);
  1997. }
  1998. };
  1999. module.exports.Tokenizer = Tokenizer;
  2000. module.exports.TOKEN = TOKEN;
  2001. /***/ })
  2002. /******/ ]);
  2003. var style_html = legacy_beautify_html;
  2004. /* Footer */
  2005. if (typeof define === "function" && define.amd) {
  2006. // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
  2007. define(["require", "./beautify", "./beautify-css"], function(requireamd) {
  2008. var js_beautify = requireamd("./beautify");
  2009. var css_beautify = requireamd("./beautify-css");
  2010. return {
  2011. html_beautify: function(html_source, options) {
  2012. return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
  2013. }
  2014. };
  2015. });
  2016. } else if (typeof exports !== "undefined") {
  2017. // Add support for CommonJS. Just put this file somewhere on your require.paths
  2018. // and you will be able to `var html_beautify = require("beautify").html_beautify`.
  2019. var js_beautify = require('./beautify.js');
  2020. var css_beautify = require('./beautify-css.js');
  2021. exports.html_beautify = function(html_source, options) {
  2022. return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
  2023. };
  2024. } else if (typeof window !== "undefined") {
  2025. // If we're running a web page and don't have either of the above, add our one global
  2026. window.html_beautify = function(html_source, options) {
  2027. return style_html(html_source, options, window.js_beautify, window.css_beautify);
  2028. };
  2029. } else if (typeof global !== "undefined") {
  2030. // If we don't even have window, try global.
  2031. global.html_beautify = function(html_source, options) {
  2032. return style_html(html_source, options, global.js_beautify, global.css_beautify);
  2033. };
  2034. }
  2035. }());