beautify-html.js 86 KB

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