beautify-html.js 85 KB

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