beautify-html.js 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123
  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() { // webpackBootstrap
  64. /******/ "use strict";
  65. /******/ var __webpack_modules__ = ([
  66. /* 0 */,
  67. /* 1 */,
  68. /* 2 */
  69. /***/ (function(module) {
  70. /*jshint node:true */
  71. /*
  72. The MIT License (MIT)
  73. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  74. Permission is hereby granted, free of charge, to any person
  75. obtaining a copy of this software and associated documentation files
  76. (the "Software"), to deal in the Software without restriction,
  77. including without limitation the rights to use, copy, modify, merge,
  78. publish, distribute, sublicense, and/or sell copies of the Software,
  79. and to permit persons to whom the Software is furnished to do so,
  80. subject to the following conditions:
  81. The above copyright notice and this permission notice shall be
  82. included in all copies or substantial portions of the Software.
  83. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  84. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  85. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  86. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  87. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  88. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  89. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  90. SOFTWARE.
  91. */
  92. function OutputLine(parent) {
  93. this.__parent = parent;
  94. this.__character_count = 0;
  95. // use indent_count as a marker for this.__lines that have preserved indentation
  96. this.__indent_count = -1;
  97. this.__alignment_count = 0;
  98. this.__wrap_point_index = 0;
  99. this.__wrap_point_character_count = 0;
  100. this.__wrap_point_indent_count = -1;
  101. this.__wrap_point_alignment_count = 0;
  102. this.__items = [];
  103. }
  104. OutputLine.prototype.clone_empty = function() {
  105. var line = new OutputLine(this.__parent);
  106. line.set_indent(this.__indent_count, this.__alignment_count);
  107. return line;
  108. };
  109. OutputLine.prototype.item = function(index) {
  110. if (index < 0) {
  111. return this.__items[this.__items.length + index];
  112. } else {
  113. return this.__items[index];
  114. }
  115. };
  116. OutputLine.prototype.has_match = function(pattern) {
  117. for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
  118. if (this.__items[lastCheckedOutput].match(pattern)) {
  119. return true;
  120. }
  121. }
  122. return false;
  123. };
  124. OutputLine.prototype.set_indent = function(indent, alignment) {
  125. if (this.is_empty()) {
  126. this.__indent_count = indent || 0;
  127. this.__alignment_count = alignment || 0;
  128. this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
  129. }
  130. };
  131. OutputLine.prototype._set_wrap_point = function() {
  132. if (this.__parent.wrap_line_length) {
  133. this.__wrap_point_index = this.__items.length;
  134. this.__wrap_point_character_count = this.__character_count;
  135. this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
  136. this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
  137. }
  138. };
  139. OutputLine.prototype._should_wrap = function() {
  140. return this.__wrap_point_index &&
  141. this.__character_count > this.__parent.wrap_line_length &&
  142. this.__wrap_point_character_count > this.__parent.next_line.__character_count;
  143. };
  144. OutputLine.prototype._allow_wrap = function() {
  145. if (this._should_wrap()) {
  146. this.__parent.add_new_line();
  147. var next = this.__parent.current_line;
  148. next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
  149. next.__items = this.__items.slice(this.__wrap_point_index);
  150. this.__items = this.__items.slice(0, this.__wrap_point_index);
  151. next.__character_count += this.__character_count - this.__wrap_point_character_count;
  152. this.__character_count = this.__wrap_point_character_count;
  153. if (next.__items[0] === " ") {
  154. next.__items.splice(0, 1);
  155. next.__character_count -= 1;
  156. }
  157. return true;
  158. }
  159. return false;
  160. };
  161. OutputLine.prototype.is_empty = function() {
  162. return this.__items.length === 0;
  163. };
  164. OutputLine.prototype.last = function() {
  165. if (!this.is_empty()) {
  166. return this.__items[this.__items.length - 1];
  167. } else {
  168. return null;
  169. }
  170. };
  171. OutputLine.prototype.push = function(item) {
  172. this.__items.push(item);
  173. var last_newline_index = item.lastIndexOf('\n');
  174. if (last_newline_index !== -1) {
  175. this.__character_count = item.length - last_newline_index;
  176. } else {
  177. this.__character_count += item.length;
  178. }
  179. };
  180. OutputLine.prototype.pop = function() {
  181. var item = null;
  182. if (!this.is_empty()) {
  183. item = this.__items.pop();
  184. this.__character_count -= item.length;
  185. }
  186. return item;
  187. };
  188. OutputLine.prototype._remove_indent = function() {
  189. if (this.__indent_count > 0) {
  190. this.__indent_count -= 1;
  191. this.__character_count -= this.__parent.indent_size;
  192. }
  193. };
  194. OutputLine.prototype._remove_wrap_indent = function() {
  195. if (this.__wrap_point_indent_count > 0) {
  196. this.__wrap_point_indent_count -= 1;
  197. }
  198. };
  199. OutputLine.prototype.trim = function() {
  200. while (this.last() === ' ') {
  201. this.__items.pop();
  202. this.__character_count -= 1;
  203. }
  204. };
  205. OutputLine.prototype.toString = function() {
  206. var result = '';
  207. if (this.is_empty()) {
  208. if (this.__parent.indent_empty_lines) {
  209. result = this.__parent.get_indent_string(this.__indent_count);
  210. }
  211. } else {
  212. result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
  213. result += this.__items.join('');
  214. }
  215. return result;
  216. };
  217. function IndentStringCache(options, baseIndentString) {
  218. this.__cache = [''];
  219. this.__indent_size = options.indent_size;
  220. this.__indent_string = options.indent_char;
  221. if (!options.indent_with_tabs) {
  222. this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
  223. }
  224. // Set to null to continue support for auto detection of base indent
  225. baseIndentString = baseIndentString || '';
  226. if (options.indent_level > 0) {
  227. baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
  228. }
  229. this.__base_string = baseIndentString;
  230. this.__base_string_length = baseIndentString.length;
  231. }
  232. IndentStringCache.prototype.get_indent_size = function(indent, column) {
  233. var result = this.__base_string_length;
  234. column = column || 0;
  235. if (indent < 0) {
  236. result = 0;
  237. }
  238. result += indent * this.__indent_size;
  239. result += column;
  240. return result;
  241. };
  242. IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
  243. var result = this.__base_string;
  244. column = column || 0;
  245. if (indent_level < 0) {
  246. indent_level = 0;
  247. result = '';
  248. }
  249. column += indent_level * this.__indent_size;
  250. this.__ensure_cache(column);
  251. result += this.__cache[column];
  252. return result;
  253. };
  254. IndentStringCache.prototype.__ensure_cache = function(column) {
  255. while (column >= this.__cache.length) {
  256. this.__add_column();
  257. }
  258. };
  259. IndentStringCache.prototype.__add_column = function() {
  260. var column = this.__cache.length;
  261. var indent = 0;
  262. var result = '';
  263. if (this.__indent_size && column >= this.__indent_size) {
  264. indent = Math.floor(column / this.__indent_size);
  265. column -= indent * this.__indent_size;
  266. result = new Array(indent + 1).join(this.__indent_string);
  267. }
  268. if (column) {
  269. result += new Array(column + 1).join(' ');
  270. }
  271. this.__cache.push(result);
  272. };
  273. function Output(options, baseIndentString) {
  274. this.__indent_cache = new IndentStringCache(options, baseIndentString);
  275. this.raw = false;
  276. this._end_with_newline = options.end_with_newline;
  277. this.indent_size = options.indent_size;
  278. this.wrap_line_length = options.wrap_line_length;
  279. this.indent_empty_lines = options.indent_empty_lines;
  280. this.__lines = [];
  281. this.previous_line = null;
  282. this.current_line = null;
  283. this.next_line = new OutputLine(this);
  284. this.space_before_token = false;
  285. this.non_breaking_space = false;
  286. this.previous_token_wrapped = false;
  287. // initialize
  288. this.__add_outputline();
  289. }
  290. Output.prototype.__add_outputline = function() {
  291. this.previous_line = this.current_line;
  292. this.current_line = this.next_line.clone_empty();
  293. this.__lines.push(this.current_line);
  294. };
  295. Output.prototype.get_line_number = function() {
  296. return this.__lines.length;
  297. };
  298. Output.prototype.get_indent_string = function(indent, column) {
  299. return this.__indent_cache.get_indent_string(indent, column);
  300. };
  301. Output.prototype.get_indent_size = function(indent, column) {
  302. return this.__indent_cache.get_indent_size(indent, column);
  303. };
  304. Output.prototype.is_empty = function() {
  305. return !this.previous_line && this.current_line.is_empty();
  306. };
  307. Output.prototype.add_new_line = function(force_newline) {
  308. // never newline at the start of file
  309. // otherwise, newline only if we didn't just add one or we're forced
  310. if (this.is_empty() ||
  311. (!force_newline && this.just_added_newline())) {
  312. return false;
  313. }
  314. // if raw output is enabled, don't print additional newlines,
  315. // but still return True as though you had
  316. if (!this.raw) {
  317. this.__add_outputline();
  318. }
  319. return true;
  320. };
  321. Output.prototype.get_code = function(eol) {
  322. this.trim(true);
  323. // handle some edge cases where the last tokens
  324. // has text that ends with newline(s)
  325. var last_item = this.current_line.pop();
  326. if (last_item) {
  327. if (last_item[last_item.length - 1] === '\n') {
  328. last_item = last_item.replace(/\n+$/g, '');
  329. }
  330. this.current_line.push(last_item);
  331. }
  332. if (this._end_with_newline) {
  333. this.__add_outputline();
  334. }
  335. var sweet_code = this.__lines.join('\n');
  336. if (eol !== '\n') {
  337. sweet_code = sweet_code.replace(/[\n]/g, eol);
  338. }
  339. return sweet_code;
  340. };
  341. Output.prototype.set_wrap_point = function() {
  342. this.current_line._set_wrap_point();
  343. };
  344. Output.prototype.set_indent = function(indent, alignment) {
  345. indent = indent || 0;
  346. alignment = alignment || 0;
  347. // Next line stores alignment values
  348. this.next_line.set_indent(indent, alignment);
  349. // Never indent your first output indent at the start of the file
  350. if (this.__lines.length > 1) {
  351. this.current_line.set_indent(indent, alignment);
  352. return true;
  353. }
  354. this.current_line.set_indent();
  355. return false;
  356. };
  357. Output.prototype.add_raw_token = function(token) {
  358. for (var x = 0; x < token.newlines; x++) {
  359. this.__add_outputline();
  360. }
  361. this.current_line.set_indent(-1);
  362. this.current_line.push(token.whitespace_before);
  363. this.current_line.push(token.text);
  364. this.space_before_token = false;
  365. this.non_breaking_space = false;
  366. this.previous_token_wrapped = false;
  367. };
  368. Output.prototype.add_token = function(printable_token) {
  369. this.__add_space_before_token();
  370. this.current_line.push(printable_token);
  371. this.space_before_token = false;
  372. this.non_breaking_space = false;
  373. this.previous_token_wrapped = this.current_line._allow_wrap();
  374. };
  375. Output.prototype.__add_space_before_token = function() {
  376. if (this.space_before_token && !this.just_added_newline()) {
  377. if (!this.non_breaking_space) {
  378. this.set_wrap_point();
  379. }
  380. this.current_line.push(' ');
  381. }
  382. };
  383. Output.prototype.remove_indent = function(index) {
  384. var output_length = this.__lines.length;
  385. while (index < output_length) {
  386. this.__lines[index]._remove_indent();
  387. index++;
  388. }
  389. this.current_line._remove_wrap_indent();
  390. };
  391. Output.prototype.trim = function(eat_newlines) {
  392. eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
  393. this.current_line.trim();
  394. while (eat_newlines && this.__lines.length > 1 &&
  395. this.current_line.is_empty()) {
  396. this.__lines.pop();
  397. this.current_line = this.__lines[this.__lines.length - 1];
  398. this.current_line.trim();
  399. }
  400. this.previous_line = this.__lines.length > 1 ?
  401. this.__lines[this.__lines.length - 2] : null;
  402. };
  403. Output.prototype.just_added_newline = function() {
  404. return this.current_line.is_empty();
  405. };
  406. Output.prototype.just_added_blankline = function() {
  407. return this.is_empty() ||
  408. (this.current_line.is_empty() && this.previous_line.is_empty());
  409. };
  410. Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
  411. var index = this.__lines.length - 2;
  412. while (index >= 0) {
  413. var potentialEmptyLine = this.__lines[index];
  414. if (potentialEmptyLine.is_empty()) {
  415. break;
  416. } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
  417. potentialEmptyLine.item(-1) !== ends_with) {
  418. this.__lines.splice(index + 1, 0, new OutputLine(this));
  419. this.previous_line = this.__lines[this.__lines.length - 2];
  420. break;
  421. }
  422. index--;
  423. }
  424. };
  425. module.exports.Output = Output;
  426. /***/ }),
  427. /* 3 */
  428. /***/ (function(module) {
  429. /*jshint node:true */
  430. /*
  431. The MIT License (MIT)
  432. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  433. Permission is hereby granted, free of charge, to any person
  434. obtaining a copy of this software and associated documentation files
  435. (the "Software"), to deal in the Software without restriction,
  436. including without limitation the rights to use, copy, modify, merge,
  437. publish, distribute, sublicense, and/or sell copies of the Software,
  438. and to permit persons to whom the Software is furnished to do so,
  439. subject to the following conditions:
  440. The above copyright notice and this permission notice shall be
  441. included in all copies or substantial portions of the Software.
  442. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  443. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  444. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  445. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  446. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  447. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  448. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  449. SOFTWARE.
  450. */
  451. function Token(type, text, newlines, whitespace_before) {
  452. this.type = type;
  453. this.text = text;
  454. // comments_before are
  455. // comments that have a new line before them
  456. // and may or may not have a newline after
  457. // this is a set of comments before
  458. this.comments_before = null; /* inline comment*/
  459. // this.comments_after = new TokenStream(); // no new line before and newline after
  460. this.newlines = newlines || 0;
  461. this.whitespace_before = whitespace_before || '';
  462. this.parent = null;
  463. this.next = null;
  464. this.previous = null;
  465. this.opened = null;
  466. this.closed = null;
  467. this.directives = null;
  468. }
  469. module.exports.Token = Token;
  470. /***/ }),
  471. /* 4 */,
  472. /* 5 */,
  473. /* 6 */
  474. /***/ (function(module) {
  475. /*jshint node:true */
  476. /*
  477. The MIT License (MIT)
  478. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  479. Permission is hereby granted, free of charge, to any person
  480. obtaining a copy of this software and associated documentation files
  481. (the "Software"), to deal in the Software without restriction,
  482. including without limitation the rights to use, copy, modify, merge,
  483. publish, distribute, sublicense, and/or sell copies of the Software,
  484. and to permit persons to whom the Software is furnished to do so,
  485. subject to the following conditions:
  486. The above copyright notice and this permission notice shall be
  487. included in all copies or substantial portions of the Software.
  488. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  489. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  490. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  491. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  492. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  493. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  494. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  495. SOFTWARE.
  496. */
  497. function Options(options, merge_child_field) {
  498. this.raw_options = _mergeOpts(options, merge_child_field);
  499. // Support passing the source text back with no change
  500. this.disabled = this._get_boolean('disabled');
  501. this.eol = this._get_characters('eol', 'auto');
  502. this.end_with_newline = this._get_boolean('end_with_newline');
  503. this.indent_size = this._get_number('indent_size', 4);
  504. this.indent_char = this._get_characters('indent_char', ' ');
  505. this.indent_level = this._get_number('indent_level');
  506. this.preserve_newlines = this._get_boolean('preserve_newlines', true);
  507. this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
  508. if (!this.preserve_newlines) {
  509. this.max_preserve_newlines = 0;
  510. }
  511. this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
  512. if (this.indent_with_tabs) {
  513. this.indent_char = '\t';
  514. // indent_size behavior changed after 1.8.6
  515. // It used to be that indent_size would be
  516. // set to 1 for indent_with_tabs. That is no longer needed and
  517. // actually doesn't make sense - why not use spaces? Further,
  518. // that might produce unexpected behavior - tabs being used
  519. // for single-column alignment. So, when indent_with_tabs is true
  520. // and indent_size is 1, reset indent_size to 4.
  521. if (this.indent_size === 1) {
  522. this.indent_size = 4;
  523. }
  524. }
  525. // Backwards compat with 1.3.x
  526. this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
  527. this.indent_empty_lines = this._get_boolean('indent_empty_lines');
  528. // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty']
  529. // For now, 'auto' = all off for javascript, all on for html (and inline javascript).
  530. // other values ignored
  531. this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
  532. }
  533. Options.prototype._get_array = function(name, default_value) {
  534. var option_value = this.raw_options[name];
  535. var result = default_value || [];
  536. if (typeof option_value === 'object') {
  537. if (option_value !== null && typeof option_value.concat === 'function') {
  538. result = option_value.concat();
  539. }
  540. } else if (typeof option_value === 'string') {
  541. result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
  542. }
  543. return result;
  544. };
  545. Options.prototype._get_boolean = function(name, default_value) {
  546. var option_value = this.raw_options[name];
  547. var result = option_value === undefined ? !!default_value : !!option_value;
  548. return result;
  549. };
  550. Options.prototype._get_characters = function(name, default_value) {
  551. var option_value = this.raw_options[name];
  552. var result = default_value || '';
  553. if (typeof option_value === 'string') {
  554. result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
  555. }
  556. return result;
  557. };
  558. Options.prototype._get_number = function(name, default_value) {
  559. var option_value = this.raw_options[name];
  560. default_value = parseInt(default_value, 10);
  561. if (isNaN(default_value)) {
  562. default_value = 0;
  563. }
  564. var result = parseInt(option_value, 10);
  565. if (isNaN(result)) {
  566. result = default_value;
  567. }
  568. return result;
  569. };
  570. Options.prototype._get_selection = function(name, selection_list, default_value) {
  571. var result = this._get_selection_list(name, selection_list, default_value);
  572. if (result.length !== 1) {
  573. throw new Error(
  574. "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
  575. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  576. }
  577. return result[0];
  578. };
  579. Options.prototype._get_selection_list = function(name, selection_list, default_value) {
  580. if (!selection_list || selection_list.length === 0) {
  581. throw new Error("Selection list cannot be empty.");
  582. }
  583. default_value = default_value || [selection_list[0]];
  584. if (!this._is_valid_selection(default_value, selection_list)) {
  585. throw new Error("Invalid Default Value!");
  586. }
  587. var result = this._get_array(name, default_value);
  588. if (!this._is_valid_selection(result, selection_list)) {
  589. throw new Error(
  590. "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
  591. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  592. }
  593. return result;
  594. };
  595. Options.prototype._is_valid_selection = function(result, selection_list) {
  596. return result.length && selection_list.length &&
  597. !result.some(function(item) { return selection_list.indexOf(item) === -1; });
  598. };
  599. // merges child options up with the parent options object
  600. // Example: obj = {a: 1, b: {a: 2}}
  601. // mergeOpts(obj, 'b')
  602. //
  603. // Returns: {a: 2}
  604. function _mergeOpts(allOptions, childFieldName) {
  605. var finalOpts = {};
  606. allOptions = _normalizeOpts(allOptions);
  607. var name;
  608. for (name in allOptions) {
  609. if (name !== childFieldName) {
  610. finalOpts[name] = allOptions[name];
  611. }
  612. }
  613. //merge in the per type settings for the childFieldName
  614. if (childFieldName && allOptions[childFieldName]) {
  615. for (name in allOptions[childFieldName]) {
  616. finalOpts[name] = allOptions[childFieldName][name];
  617. }
  618. }
  619. return finalOpts;
  620. }
  621. function _normalizeOpts(options) {
  622. var convertedOpts = {};
  623. var key;
  624. for (key in options) {
  625. var newKey = key.replace(/-/g, "_");
  626. convertedOpts[newKey] = options[key];
  627. }
  628. return convertedOpts;
  629. }
  630. module.exports.Options = Options;
  631. module.exports.normalizeOpts = _normalizeOpts;
  632. module.exports.mergeOpts = _mergeOpts;
  633. /***/ }),
  634. /* 7 */,
  635. /* 8 */
  636. /***/ (function(module) {
  637. /*jshint node:true */
  638. /*
  639. The MIT License (MIT)
  640. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  641. Permission is hereby granted, free of charge, to any person
  642. obtaining a copy of this software and associated documentation files
  643. (the "Software"), to deal in the Software without restriction,
  644. including without limitation the rights to use, copy, modify, merge,
  645. publish, distribute, sublicense, and/or sell copies of the Software,
  646. and to permit persons to whom the Software is furnished to do so,
  647. subject to the following conditions:
  648. The above copyright notice and this permission notice shall be
  649. included in all copies or substantial portions of the Software.
  650. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  651. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  652. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  653. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  654. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  655. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  656. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  657. SOFTWARE.
  658. */
  659. var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
  660. function InputScanner(input_string) {
  661. this.__input = input_string || '';
  662. this.__input_length = this.__input.length;
  663. this.__position = 0;
  664. }
  665. InputScanner.prototype.restart = function() {
  666. this.__position = 0;
  667. };
  668. InputScanner.prototype.back = function() {
  669. if (this.__position > 0) {
  670. this.__position -= 1;
  671. }
  672. };
  673. InputScanner.prototype.hasNext = function() {
  674. return this.__position < this.__input_length;
  675. };
  676. InputScanner.prototype.next = function() {
  677. var val = null;
  678. if (this.hasNext()) {
  679. val = this.__input.charAt(this.__position);
  680. this.__position += 1;
  681. }
  682. return val;
  683. };
  684. InputScanner.prototype.peek = function(index) {
  685. var val = null;
  686. index = index || 0;
  687. index += this.__position;
  688. if (index >= 0 && index < this.__input_length) {
  689. val = this.__input.charAt(index);
  690. }
  691. return val;
  692. };
  693. // This is a JavaScript only helper function (not in python)
  694. // Javascript doesn't have a match method
  695. // and not all implementation support "sticky" flag.
  696. // If they do not support sticky then both this.match() and this.test() method
  697. // must get the match and check the index of the match.
  698. // If sticky is supported and set, this method will use it.
  699. // Otherwise it will check that global is set, and fall back to the slower method.
  700. InputScanner.prototype.__match = function(pattern, index) {
  701. pattern.lastIndex = index;
  702. var pattern_match = pattern.exec(this.__input);
  703. if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
  704. if (pattern_match.index !== index) {
  705. pattern_match = null;
  706. }
  707. }
  708. return pattern_match;
  709. };
  710. InputScanner.prototype.test = function(pattern, index) {
  711. index = index || 0;
  712. index += this.__position;
  713. if (index >= 0 && index < this.__input_length) {
  714. return !!this.__match(pattern, index);
  715. } else {
  716. return false;
  717. }
  718. };
  719. InputScanner.prototype.testChar = function(pattern, index) {
  720. // test one character regex match
  721. var val = this.peek(index);
  722. pattern.lastIndex = 0;
  723. return val !== null && pattern.test(val);
  724. };
  725. InputScanner.prototype.match = function(pattern) {
  726. var pattern_match = this.__match(pattern, this.__position);
  727. if (pattern_match) {
  728. this.__position += pattern_match[0].length;
  729. } else {
  730. pattern_match = null;
  731. }
  732. return pattern_match;
  733. };
  734. InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
  735. var val = '';
  736. var match;
  737. if (starting_pattern) {
  738. match = this.match(starting_pattern);
  739. if (match) {
  740. val += match[0];
  741. }
  742. }
  743. if (until_pattern && (match || !starting_pattern)) {
  744. val += this.readUntil(until_pattern, until_after);
  745. }
  746. return val;
  747. };
  748. InputScanner.prototype.readUntil = function(pattern, until_after) {
  749. var val = '';
  750. var match_index = this.__position;
  751. pattern.lastIndex = this.__position;
  752. var pattern_match = pattern.exec(this.__input);
  753. if (pattern_match) {
  754. match_index = pattern_match.index;
  755. if (until_after) {
  756. match_index += pattern_match[0].length;
  757. }
  758. } else {
  759. match_index = this.__input_length;
  760. }
  761. val = this.__input.substring(this.__position, match_index);
  762. this.__position = match_index;
  763. return val;
  764. };
  765. InputScanner.prototype.readUntilAfter = function(pattern) {
  766. return this.readUntil(pattern, true);
  767. };
  768. InputScanner.prototype.get_regexp = function(pattern, match_from) {
  769. var result = null;
  770. var flags = 'g';
  771. if (match_from && regexp_has_sticky) {
  772. flags = 'y';
  773. }
  774. // strings are converted to regexp
  775. if (typeof pattern === "string" && pattern !== '') {
  776. // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
  777. result = new RegExp(pattern, flags);
  778. } else if (pattern) {
  779. result = new RegExp(pattern.source, flags);
  780. }
  781. return result;
  782. };
  783. InputScanner.prototype.get_literal_regexp = function(literal_string) {
  784. return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  785. };
  786. /* css beautifier legacy helpers */
  787. InputScanner.prototype.peekUntilAfter = function(pattern) {
  788. var start = this.__position;
  789. var val = this.readUntilAfter(pattern);
  790. this.__position = start;
  791. return val;
  792. };
  793. InputScanner.prototype.lookBack = function(testVal) {
  794. var start = this.__position - 1;
  795. return start >= testVal.length && this.__input.substring(start - testVal.length, start)
  796. .toLowerCase() === testVal;
  797. };
  798. module.exports.InputScanner = InputScanner;
  799. /***/ }),
  800. /* 9 */
  801. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  802. /*jshint node:true */
  803. /*
  804. The MIT License (MIT)
  805. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  806. Permission is hereby granted, free of charge, to any person
  807. obtaining a copy of this software and associated documentation files
  808. (the "Software"), to deal in the Software without restriction,
  809. including without limitation the rights to use, copy, modify, merge,
  810. publish, distribute, sublicense, and/or sell copies of the Software,
  811. and to permit persons to whom the Software is furnished to do so,
  812. subject to the following conditions:
  813. The above copyright notice and this permission notice shall be
  814. included in all copies or substantial portions of the Software.
  815. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  816. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  817. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  818. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  819. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  820. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  821. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  822. SOFTWARE.
  823. */
  824. var InputScanner = __webpack_require__(8).InputScanner;
  825. var Token = __webpack_require__(3).Token;
  826. var TokenStream = __webpack_require__(10).TokenStream;
  827. var WhitespacePattern = __webpack_require__(11).WhitespacePattern;
  828. var TOKEN = {
  829. START: 'TK_START',
  830. RAW: 'TK_RAW',
  831. EOF: 'TK_EOF'
  832. };
  833. var Tokenizer = function(input_string, options) {
  834. this._input = new InputScanner(input_string);
  835. this._options = options || {};
  836. this.__tokens = null;
  837. this._patterns = {};
  838. this._patterns.whitespace = new WhitespacePattern(this._input);
  839. };
  840. Tokenizer.prototype.tokenize = function() {
  841. this._input.restart();
  842. this.__tokens = new TokenStream();
  843. this._reset();
  844. var current;
  845. var previous = new Token(TOKEN.START, '');
  846. var open_token = null;
  847. var open_stack = [];
  848. var comments = new TokenStream();
  849. while (previous.type !== TOKEN.EOF) {
  850. current = this._get_next_token(previous, open_token);
  851. while (this._is_comment(current)) {
  852. comments.add(current);
  853. current = this._get_next_token(previous, open_token);
  854. }
  855. if (!comments.isEmpty()) {
  856. current.comments_before = comments;
  857. comments = new TokenStream();
  858. }
  859. current.parent = open_token;
  860. if (this._is_opening(current)) {
  861. open_stack.push(open_token);
  862. open_token = current;
  863. } else if (open_token && this._is_closing(current, open_token)) {
  864. current.opened = open_token;
  865. open_token.closed = current;
  866. open_token = open_stack.pop();
  867. current.parent = open_token;
  868. }
  869. current.previous = previous;
  870. previous.next = current;
  871. this.__tokens.add(current);
  872. previous = current;
  873. }
  874. return this.__tokens;
  875. };
  876. Tokenizer.prototype._is_first_token = function() {
  877. return this.__tokens.isEmpty();
  878. };
  879. Tokenizer.prototype._reset = function() {};
  880. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  881. this._readWhitespace();
  882. var resulting_string = this._input.read(/.+/g);
  883. if (resulting_string) {
  884. return this._create_token(TOKEN.RAW, resulting_string);
  885. } else {
  886. return this._create_token(TOKEN.EOF, '');
  887. }
  888. };
  889. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  890. return false;
  891. };
  892. Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
  893. return false;
  894. };
  895. Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
  896. return false;
  897. };
  898. Tokenizer.prototype._create_token = function(type, text) {
  899. var token = new Token(type, text,
  900. this._patterns.whitespace.newline_count,
  901. this._patterns.whitespace.whitespace_before_token);
  902. return token;
  903. };
  904. Tokenizer.prototype._readWhitespace = function() {
  905. return this._patterns.whitespace.read();
  906. };
  907. module.exports.Tokenizer = Tokenizer;
  908. module.exports.TOKEN = TOKEN;
  909. /***/ }),
  910. /* 10 */
  911. /***/ (function(module) {
  912. /*jshint node:true */
  913. /*
  914. The MIT License (MIT)
  915. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  916. Permission is hereby granted, free of charge, to any person
  917. obtaining a copy of this software and associated documentation files
  918. (the "Software"), to deal in the Software without restriction,
  919. including without limitation the rights to use, copy, modify, merge,
  920. publish, distribute, sublicense, and/or sell copies of the Software,
  921. and to permit persons to whom the Software is furnished to do so,
  922. subject to the following conditions:
  923. The above copyright notice and this permission notice shall be
  924. included in all copies or substantial portions of the Software.
  925. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  926. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  927. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  928. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  929. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  930. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  931. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  932. SOFTWARE.
  933. */
  934. function TokenStream(parent_token) {
  935. // private
  936. this.__tokens = [];
  937. this.__tokens_length = this.__tokens.length;
  938. this.__position = 0;
  939. this.__parent_token = parent_token;
  940. }
  941. TokenStream.prototype.restart = function() {
  942. this.__position = 0;
  943. };
  944. TokenStream.prototype.isEmpty = function() {
  945. return this.__tokens_length === 0;
  946. };
  947. TokenStream.prototype.hasNext = function() {
  948. return this.__position < this.__tokens_length;
  949. };
  950. TokenStream.prototype.next = function() {
  951. var val = null;
  952. if (this.hasNext()) {
  953. val = this.__tokens[this.__position];
  954. this.__position += 1;
  955. }
  956. return val;
  957. };
  958. TokenStream.prototype.peek = function(index) {
  959. var val = null;
  960. index = index || 0;
  961. index += this.__position;
  962. if (index >= 0 && index < this.__tokens_length) {
  963. val = this.__tokens[index];
  964. }
  965. return val;
  966. };
  967. TokenStream.prototype.add = function(token) {
  968. if (this.__parent_token) {
  969. token.parent = this.__parent_token;
  970. }
  971. this.__tokens.push(token);
  972. this.__tokens_length += 1;
  973. };
  974. module.exports.TokenStream = TokenStream;
  975. /***/ }),
  976. /* 11 */
  977. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  978. /*jshint node:true */
  979. /*
  980. The MIT License (MIT)
  981. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  982. Permission is hereby granted, free of charge, to any person
  983. obtaining a copy of this software and associated documentation files
  984. (the "Software"), to deal in the Software without restriction,
  985. including without limitation the rights to use, copy, modify, merge,
  986. publish, distribute, sublicense, and/or sell copies of the Software,
  987. and to permit persons to whom the Software is furnished to do so,
  988. subject to the following conditions:
  989. The above copyright notice and this permission notice shall be
  990. included in all copies or substantial portions of the Software.
  991. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  992. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  993. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  994. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  995. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  996. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  997. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  998. SOFTWARE.
  999. */
  1000. var Pattern = __webpack_require__(12).Pattern;
  1001. function WhitespacePattern(input_scanner, parent) {
  1002. Pattern.call(this, input_scanner, parent);
  1003. if (parent) {
  1004. this._line_regexp = this._input.get_regexp(parent._line_regexp);
  1005. } else {
  1006. this.__set_whitespace_patterns('', '');
  1007. }
  1008. this.newline_count = 0;
  1009. this.whitespace_before_token = '';
  1010. }
  1011. WhitespacePattern.prototype = new Pattern();
  1012. WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
  1013. whitespace_chars += '\\t ';
  1014. newline_chars += '\\n\\r';
  1015. this._match_pattern = this._input.get_regexp(
  1016. '[' + whitespace_chars + newline_chars + ']+', true);
  1017. this._newline_regexp = this._input.get_regexp(
  1018. '\\r\\n|[' + newline_chars + ']');
  1019. };
  1020. WhitespacePattern.prototype.read = function() {
  1021. this.newline_count = 0;
  1022. this.whitespace_before_token = '';
  1023. var resulting_string = this._input.read(this._match_pattern);
  1024. if (resulting_string === ' ') {
  1025. this.whitespace_before_token = ' ';
  1026. } else if (resulting_string) {
  1027. var matches = this.__split(this._newline_regexp, resulting_string);
  1028. this.newline_count = matches.length - 1;
  1029. this.whitespace_before_token = matches[this.newline_count];
  1030. }
  1031. return resulting_string;
  1032. };
  1033. WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
  1034. var result = this._create();
  1035. result.__set_whitespace_patterns(whitespace_chars, newline_chars);
  1036. result._update();
  1037. return result;
  1038. };
  1039. WhitespacePattern.prototype._create = function() {
  1040. return new WhitespacePattern(this._input, this);
  1041. };
  1042. WhitespacePattern.prototype.__split = function(regexp, input_string) {
  1043. regexp.lastIndex = 0;
  1044. var start_index = 0;
  1045. var result = [];
  1046. var next_match = regexp.exec(input_string);
  1047. while (next_match) {
  1048. result.push(input_string.substring(start_index, next_match.index));
  1049. start_index = next_match.index + next_match[0].length;
  1050. next_match = regexp.exec(input_string);
  1051. }
  1052. if (start_index < input_string.length) {
  1053. result.push(input_string.substring(start_index, input_string.length));
  1054. } else {
  1055. result.push('');
  1056. }
  1057. return result;
  1058. };
  1059. module.exports.WhitespacePattern = WhitespacePattern;
  1060. /***/ }),
  1061. /* 12 */
  1062. /***/ (function(module) {
  1063. /*jshint node:true */
  1064. /*
  1065. The MIT License (MIT)
  1066. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1067. Permission is hereby granted, free of charge, to any person
  1068. obtaining a copy of this software and associated documentation files
  1069. (the "Software"), to deal in the Software without restriction,
  1070. including without limitation the rights to use, copy, modify, merge,
  1071. publish, distribute, sublicense, and/or sell copies of the Software,
  1072. and to permit persons to whom the Software is furnished to do so,
  1073. subject to the following conditions:
  1074. The above copyright notice and this permission notice shall be
  1075. included in all copies or substantial portions of the Software.
  1076. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1077. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1078. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1079. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1080. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1081. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1082. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1083. SOFTWARE.
  1084. */
  1085. function Pattern(input_scanner, parent) {
  1086. this._input = input_scanner;
  1087. this._starting_pattern = null;
  1088. this._match_pattern = null;
  1089. this._until_pattern = null;
  1090. this._until_after = false;
  1091. if (parent) {
  1092. this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
  1093. this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
  1094. this._until_pattern = this._input.get_regexp(parent._until_pattern);
  1095. this._until_after = parent._until_after;
  1096. }
  1097. }
  1098. Pattern.prototype.read = function() {
  1099. var result = this._input.read(this._starting_pattern);
  1100. if (!this._starting_pattern || result) {
  1101. result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
  1102. }
  1103. return result;
  1104. };
  1105. Pattern.prototype.read_match = function() {
  1106. return this._input.match(this._match_pattern);
  1107. };
  1108. Pattern.prototype.until_after = function(pattern) {
  1109. var result = this._create();
  1110. result._until_after = true;
  1111. result._until_pattern = this._input.get_regexp(pattern);
  1112. result._update();
  1113. return result;
  1114. };
  1115. Pattern.prototype.until = function(pattern) {
  1116. var result = this._create();
  1117. result._until_after = false;
  1118. result._until_pattern = this._input.get_regexp(pattern);
  1119. result._update();
  1120. return result;
  1121. };
  1122. Pattern.prototype.starting_with = function(pattern) {
  1123. var result = this._create();
  1124. result._starting_pattern = this._input.get_regexp(pattern, true);
  1125. result._update();
  1126. return result;
  1127. };
  1128. Pattern.prototype.matching = function(pattern) {
  1129. var result = this._create();
  1130. result._match_pattern = this._input.get_regexp(pattern, true);
  1131. result._update();
  1132. return result;
  1133. };
  1134. Pattern.prototype._create = function() {
  1135. return new Pattern(this._input, this);
  1136. };
  1137. Pattern.prototype._update = function() {};
  1138. module.exports.Pattern = Pattern;
  1139. /***/ }),
  1140. /* 13 */
  1141. /***/ (function(module) {
  1142. /*jshint node:true */
  1143. /*
  1144. The MIT License (MIT)
  1145. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1146. Permission is hereby granted, free of charge, to any person
  1147. obtaining a copy of this software and associated documentation files
  1148. (the "Software"), to deal in the Software without restriction,
  1149. including without limitation the rights to use, copy, modify, merge,
  1150. publish, distribute, sublicense, and/or sell copies of the Software,
  1151. and to permit persons to whom the Software is furnished to do so,
  1152. subject to the following conditions:
  1153. The above copyright notice and this permission notice shall be
  1154. included in all copies or substantial portions of the Software.
  1155. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1156. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1157. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1158. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1159. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1160. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1161. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1162. SOFTWARE.
  1163. */
  1164. function Directives(start_block_pattern, end_block_pattern) {
  1165. start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
  1166. end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
  1167. this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
  1168. this.__directive_pattern = / (\w+)[:](\w+)/g;
  1169. this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
  1170. }
  1171. Directives.prototype.get_directives = function(text) {
  1172. if (!text.match(this.__directives_block_pattern)) {
  1173. return null;
  1174. }
  1175. var directives = {};
  1176. this.__directive_pattern.lastIndex = 0;
  1177. var directive_match = this.__directive_pattern.exec(text);
  1178. while (directive_match) {
  1179. directives[directive_match[1]] = directive_match[2];
  1180. directive_match = this.__directive_pattern.exec(text);
  1181. }
  1182. return directives;
  1183. };
  1184. Directives.prototype.readIgnored = function(input) {
  1185. return input.readUntilAfter(this.__directives_end_ignore_pattern);
  1186. };
  1187. module.exports.Directives = Directives;
  1188. /***/ }),
  1189. /* 14 */
  1190. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1191. /*jshint node:true */
  1192. /*
  1193. The MIT License (MIT)
  1194. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1195. Permission is hereby granted, free of charge, to any person
  1196. obtaining a copy of this software and associated documentation files
  1197. (the "Software"), to deal in the Software without restriction,
  1198. including without limitation the rights to use, copy, modify, merge,
  1199. publish, distribute, sublicense, and/or sell copies of the Software,
  1200. and to permit persons to whom the Software is furnished to do so,
  1201. subject to the following conditions:
  1202. The above copyright notice and this permission notice shall be
  1203. included in all copies or substantial portions of the Software.
  1204. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1205. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1206. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1207. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1208. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1209. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1210. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1211. SOFTWARE.
  1212. */
  1213. var Pattern = __webpack_require__(12).Pattern;
  1214. var template_names = {
  1215. django: false,
  1216. erb: false,
  1217. handlebars: false,
  1218. php: false,
  1219. smarty: false
  1220. };
  1221. // This lets templates appear anywhere we would do a readUntil
  1222. // The cost is higher but it is pay to play.
  1223. function TemplatablePattern(input_scanner, parent) {
  1224. Pattern.call(this, input_scanner, parent);
  1225. this.__template_pattern = null;
  1226. this._disabled = Object.assign({}, template_names);
  1227. this._excluded = Object.assign({}, template_names);
  1228. if (parent) {
  1229. this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
  1230. this._excluded = Object.assign(this._excluded, parent._excluded);
  1231. this._disabled = Object.assign(this._disabled, parent._disabled);
  1232. }
  1233. var pattern = new Pattern(input_scanner);
  1234. this.__patterns = {
  1235. handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
  1236. handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
  1237. handlebars: pattern.starting_with(/{{/).until_after(/}}/),
  1238. php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
  1239. erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
  1240. // django coflicts with handlebars a bit.
  1241. django: pattern.starting_with(/{%/).until_after(/%}/),
  1242. django_value: pattern.starting_with(/{{/).until_after(/}}/),
  1243. django_comment: pattern.starting_with(/{#/).until_after(/#}/),
  1244. smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
  1245. smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
  1246. smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
  1247. };
  1248. }
  1249. TemplatablePattern.prototype = new Pattern();
  1250. TemplatablePattern.prototype._create = function() {
  1251. return new TemplatablePattern(this._input, this);
  1252. };
  1253. TemplatablePattern.prototype._update = function() {
  1254. this.__set_templated_pattern();
  1255. };
  1256. TemplatablePattern.prototype.disable = function(language) {
  1257. var result = this._create();
  1258. result._disabled[language] = true;
  1259. result._update();
  1260. return result;
  1261. };
  1262. TemplatablePattern.prototype.read_options = function(options) {
  1263. var result = this._create();
  1264. for (var language in template_names) {
  1265. result._disabled[language] = options.templating.indexOf(language) === -1;
  1266. }
  1267. result._update();
  1268. return result;
  1269. };
  1270. TemplatablePattern.prototype.exclude = function(language) {
  1271. var result = this._create();
  1272. result._excluded[language] = true;
  1273. result._update();
  1274. return result;
  1275. };
  1276. TemplatablePattern.prototype.read = function() {
  1277. var result = '';
  1278. if (this._match_pattern) {
  1279. result = this._input.read(this._starting_pattern);
  1280. } else {
  1281. result = this._input.read(this._starting_pattern, this.__template_pattern);
  1282. }
  1283. var next = this._read_template();
  1284. while (next) {
  1285. if (this._match_pattern) {
  1286. next += this._input.read(this._match_pattern);
  1287. } else {
  1288. next += this._input.readUntil(this.__template_pattern);
  1289. }
  1290. result += next;
  1291. next = this._read_template();
  1292. }
  1293. if (this._until_after) {
  1294. result += this._input.readUntilAfter(this._until_pattern);
  1295. }
  1296. return result;
  1297. };
  1298. TemplatablePattern.prototype.__set_templated_pattern = function() {
  1299. var items = [];
  1300. if (!this._disabled.php) {
  1301. items.push(this.__patterns.php._starting_pattern.source);
  1302. }
  1303. if (!this._disabled.handlebars) {
  1304. items.push(this.__patterns.handlebars._starting_pattern.source);
  1305. }
  1306. if (!this._disabled.erb) {
  1307. items.push(this.__patterns.erb._starting_pattern.source);
  1308. }
  1309. if (!this._disabled.django) {
  1310. items.push(this.__patterns.django._starting_pattern.source);
  1311. // The starting pattern for django is more complex because it has different
  1312. // patterns for value, comment, and other sections
  1313. items.push(this.__patterns.django_value._starting_pattern.source);
  1314. items.push(this.__patterns.django_comment._starting_pattern.source);
  1315. }
  1316. if (!this._disabled.smarty) {
  1317. items.push(this.__patterns.smarty._starting_pattern.source);
  1318. }
  1319. if (this._until_pattern) {
  1320. items.push(this._until_pattern.source);
  1321. }
  1322. this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
  1323. };
  1324. TemplatablePattern.prototype._read_template = function() {
  1325. var resulting_string = '';
  1326. var c = this._input.peek();
  1327. if (c === '<') {
  1328. var peek1 = this._input.peek(1);
  1329. //if we're in a comment, do something special
  1330. // We treat all comments as literals, even more than preformatted tags
  1331. // we just look for the appropriate close tag
  1332. if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
  1333. resulting_string = resulting_string ||
  1334. this.__patterns.php.read();
  1335. }
  1336. if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
  1337. resulting_string = resulting_string ||
  1338. this.__patterns.erb.read();
  1339. }
  1340. } else if (c === '{') {
  1341. if (!this._disabled.handlebars && !this._excluded.handlebars) {
  1342. resulting_string = resulting_string ||
  1343. this.__patterns.handlebars_comment.read();
  1344. resulting_string = resulting_string ||
  1345. this.__patterns.handlebars_unescaped.read();
  1346. resulting_string = resulting_string ||
  1347. this.__patterns.handlebars.read();
  1348. }
  1349. if (!this._disabled.django) {
  1350. // django coflicts with handlebars a bit.
  1351. if (!this._excluded.django && !this._excluded.handlebars) {
  1352. resulting_string = resulting_string ||
  1353. this.__patterns.django_value.read();
  1354. }
  1355. if (!this._excluded.django) {
  1356. resulting_string = resulting_string ||
  1357. this.__patterns.django_comment.read();
  1358. resulting_string = resulting_string ||
  1359. this.__patterns.django.read();
  1360. }
  1361. }
  1362. if (!this._disabled.smarty) {
  1363. // smarty cannot be enabled with django or handlebars enabled
  1364. if (this._disabled.django && this._disabled.handlebars) {
  1365. resulting_string = resulting_string ||
  1366. this.__patterns.smarty_comment.read();
  1367. resulting_string = resulting_string ||
  1368. this.__patterns.smarty_literal.read();
  1369. resulting_string = resulting_string ||
  1370. this.__patterns.smarty.read();
  1371. }
  1372. }
  1373. }
  1374. return resulting_string;
  1375. };
  1376. module.exports.TemplatablePattern = TemplatablePattern;
  1377. /***/ }),
  1378. /* 15 */,
  1379. /* 16 */,
  1380. /* 17 */,
  1381. /* 18 */
  1382. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1383. /*jshint node:true */
  1384. /*
  1385. The MIT License (MIT)
  1386. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1387. Permission is hereby granted, free of charge, to any person
  1388. obtaining a copy of this software and associated documentation files
  1389. (the "Software"), to deal in the Software without restriction,
  1390. including without limitation the rights to use, copy, modify, merge,
  1391. publish, distribute, sublicense, and/or sell copies of the Software,
  1392. and to permit persons to whom the Software is furnished to do so,
  1393. subject to the following conditions:
  1394. The above copyright notice and this permission notice shall be
  1395. included in all copies or substantial portions of the Software.
  1396. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1397. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1398. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1399. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1400. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1401. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1402. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1403. SOFTWARE.
  1404. */
  1405. var Beautifier = __webpack_require__(19).Beautifier,
  1406. Options = __webpack_require__(20).Options;
  1407. function style_html(html_source, options, js_beautify, css_beautify) {
  1408. var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
  1409. return beautifier.beautify();
  1410. }
  1411. module.exports = style_html;
  1412. module.exports.defaultOptions = function() {
  1413. return new Options();
  1414. };
  1415. /***/ }),
  1416. /* 19 */
  1417. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1418. /*jshint node:true */
  1419. /*
  1420. The MIT License (MIT)
  1421. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1422. Permission is hereby granted, free of charge, to any person
  1423. obtaining a copy of this software and associated documentation files
  1424. (the "Software"), to deal in the Software without restriction,
  1425. including without limitation the rights to use, copy, modify, merge,
  1426. publish, distribute, sublicense, and/or sell copies of the Software,
  1427. and to permit persons to whom the Software is furnished to do so,
  1428. subject to the following conditions:
  1429. The above copyright notice and this permission notice shall be
  1430. included in all copies or substantial portions of the Software.
  1431. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1432. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1433. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1434. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1435. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1436. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1437. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1438. SOFTWARE.
  1439. */
  1440. var Options = __webpack_require__(20).Options;
  1441. var Output = __webpack_require__(2).Output;
  1442. var Tokenizer = __webpack_require__(21).Tokenizer;
  1443. var TOKEN = __webpack_require__(21).TOKEN;
  1444. var lineBreak = /\r\n|[\r\n]/;
  1445. var allLineBreaks = /\r\n|[\r\n]/g;
  1446. var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions
  1447. this.indent_level = 0;
  1448. this.alignment_size = 0;
  1449. this.max_preserve_newlines = options.max_preserve_newlines;
  1450. this.preserve_newlines = options.preserve_newlines;
  1451. this._output = new Output(options, base_indent_string);
  1452. };
  1453. Printer.prototype.current_line_has_match = function(pattern) {
  1454. return this._output.current_line.has_match(pattern);
  1455. };
  1456. Printer.prototype.set_space_before_token = function(value, non_breaking) {
  1457. this._output.space_before_token = value;
  1458. this._output.non_breaking_space = non_breaking;
  1459. };
  1460. Printer.prototype.set_wrap_point = function() {
  1461. this._output.set_indent(this.indent_level, this.alignment_size);
  1462. this._output.set_wrap_point();
  1463. };
  1464. Printer.prototype.add_raw_token = function(token) {
  1465. this._output.add_raw_token(token);
  1466. };
  1467. Printer.prototype.print_preserved_newlines = function(raw_token) {
  1468. var newlines = 0;
  1469. if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
  1470. newlines = raw_token.newlines ? 1 : 0;
  1471. }
  1472. if (this.preserve_newlines) {
  1473. newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
  1474. }
  1475. for (var n = 0; n < newlines; n++) {
  1476. this.print_newline(n > 0);
  1477. }
  1478. return newlines !== 0;
  1479. };
  1480. Printer.prototype.traverse_whitespace = function(raw_token) {
  1481. if (raw_token.whitespace_before || raw_token.newlines) {
  1482. if (!this.print_preserved_newlines(raw_token)) {
  1483. this._output.space_before_token = true;
  1484. }
  1485. return true;
  1486. }
  1487. return false;
  1488. };
  1489. Printer.prototype.previous_token_wrapped = function() {
  1490. return this._output.previous_token_wrapped;
  1491. };
  1492. Printer.prototype.print_newline = function(force) {
  1493. this._output.add_new_line(force);
  1494. };
  1495. Printer.prototype.print_token = function(token) {
  1496. if (token.text) {
  1497. this._output.set_indent(this.indent_level, this.alignment_size);
  1498. this._output.add_token(token.text);
  1499. }
  1500. };
  1501. Printer.prototype.indent = function() {
  1502. this.indent_level++;
  1503. };
  1504. Printer.prototype.get_full_indent = function(level) {
  1505. level = this.indent_level + (level || 0);
  1506. if (level < 1) {
  1507. return '';
  1508. }
  1509. return this._output.get_indent_string(level);
  1510. };
  1511. var get_type_attribute = function(start_token) {
  1512. var result = null;
  1513. var raw_token = start_token.next;
  1514. // Search attributes for a type attribute
  1515. while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
  1516. if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
  1517. if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
  1518. raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
  1519. result = raw_token.next.next.text;
  1520. }
  1521. break;
  1522. }
  1523. raw_token = raw_token.next;
  1524. }
  1525. return result;
  1526. };
  1527. var get_custom_beautifier_name = function(tag_check, raw_token) {
  1528. var typeAttribute = null;
  1529. var result = null;
  1530. if (!raw_token.closed) {
  1531. return null;
  1532. }
  1533. if (tag_check === 'script') {
  1534. typeAttribute = 'text/javascript';
  1535. } else if (tag_check === 'style') {
  1536. typeAttribute = 'text/css';
  1537. }
  1538. typeAttribute = get_type_attribute(raw_token) || typeAttribute;
  1539. // For script and style tags that have a type attribute, only enable custom beautifiers for matching values
  1540. // For those without a type attribute use default;
  1541. if (typeAttribute.search('text/css') > -1) {
  1542. result = 'css';
  1543. } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
  1544. result = 'javascript';
  1545. } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
  1546. result = 'html';
  1547. } else if (typeAttribute.search(/test\/null/) > -1) {
  1548. // Test only mime-type for testing the beautifier when null is passed as beautifing function
  1549. result = 'null';
  1550. }
  1551. return result;
  1552. };
  1553. function in_array(what, arr) {
  1554. return arr.indexOf(what) !== -1;
  1555. }
  1556. function TagFrame(parent, parser_token, indent_level) {
  1557. this.parent = parent || null;
  1558. this.tag = parser_token ? parser_token.tag_name : '';
  1559. this.indent_level = indent_level || 0;
  1560. this.parser_token = parser_token || null;
  1561. }
  1562. function TagStack(printer) {
  1563. this._printer = printer;
  1564. this._current_frame = null;
  1565. }
  1566. TagStack.prototype.get_parser_token = function() {
  1567. return this._current_frame ? this._current_frame.parser_token : null;
  1568. };
  1569. TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object
  1570. var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
  1571. this._current_frame = new_frame;
  1572. };
  1573. TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer
  1574. var parser_token = null;
  1575. if (frame) {
  1576. parser_token = frame.parser_token;
  1577. this._printer.indent_level = frame.indent_level;
  1578. this._current_frame = frame.parent;
  1579. }
  1580. return parser_token;
  1581. };
  1582. TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer
  1583. var frame = this._current_frame;
  1584. while (frame) { //till we reach '' (the initial value);
  1585. if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it
  1586. break;
  1587. } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
  1588. frame = null;
  1589. break;
  1590. }
  1591. frame = frame.parent;
  1592. }
  1593. return frame;
  1594. };
  1595. TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer
  1596. var frame = this._get_frame([tag], stop_list);
  1597. return this._try_pop_frame(frame);
  1598. };
  1599. TagStack.prototype.indent_to_tag = function(tag_list) {
  1600. var frame = this._get_frame(tag_list);
  1601. if (frame) {
  1602. this._printer.indent_level = frame.indent_level;
  1603. }
  1604. };
  1605. function Beautifier(source_text, options, js_beautify, css_beautify) {
  1606. //Wrapper function to invoke all the necessary constructors and deal with the output.
  1607. this._source_text = source_text || '';
  1608. options = options || {};
  1609. this._js_beautify = js_beautify;
  1610. this._css_beautify = css_beautify;
  1611. this._tag_stack = null;
  1612. // Allow the setting of language/file-type specific options
  1613. // with inheritance of overall settings
  1614. var optionHtml = new Options(options, 'html');
  1615. this._options = optionHtml;
  1616. this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
  1617. this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
  1618. this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
  1619. this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
  1620. this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
  1621. this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
  1622. }
  1623. Beautifier.prototype.beautify = function() {
  1624. // if disabled, return the input unchanged.
  1625. if (this._options.disabled) {
  1626. return this._source_text;
  1627. }
  1628. var source_text = this._source_text;
  1629. var eol = this._options.eol;
  1630. if (this._options.eol === 'auto') {
  1631. eol = '\n';
  1632. if (source_text && lineBreak.test(source_text)) {
  1633. eol = source_text.match(lineBreak)[0];
  1634. }
  1635. }
  1636. // HACK: newline parsing inconsistent. This brute force normalizes the input.
  1637. source_text = source_text.replace(allLineBreaks, '\n');
  1638. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  1639. var last_token = {
  1640. text: '',
  1641. type: ''
  1642. };
  1643. var last_tag_token = new TagOpenParserToken();
  1644. var printer = new Printer(this._options, baseIndentString);
  1645. var tokens = new Tokenizer(source_text, this._options).tokenize();
  1646. this._tag_stack = new TagStack(printer);
  1647. var parser_token = null;
  1648. var raw_token = tokens.next();
  1649. while (raw_token.type !== TOKEN.EOF) {
  1650. if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
  1651. parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token);
  1652. last_tag_token = parser_token;
  1653. } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
  1654. (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
  1655. parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, tokens);
  1656. } else if (raw_token.type === TOKEN.TAG_CLOSE) {
  1657. parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
  1658. } else if (raw_token.type === TOKEN.TEXT) {
  1659. parser_token = this._handle_text(printer, raw_token, last_tag_token);
  1660. } else {
  1661. // This should never happen, but if it does. Print the raw token
  1662. printer.add_raw_token(raw_token);
  1663. }
  1664. last_token = parser_token;
  1665. raw_token = tokens.next();
  1666. }
  1667. var sweet_code = printer._output.get_code(eol);
  1668. return sweet_code;
  1669. };
  1670. Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
  1671. var parser_token = {
  1672. text: raw_token.text,
  1673. type: raw_token.type
  1674. };
  1675. printer.alignment_size = 0;
  1676. last_tag_token.tag_complete = true;
  1677. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  1678. if (last_tag_token.is_unformatted) {
  1679. printer.add_raw_token(raw_token);
  1680. } else {
  1681. if (last_tag_token.tag_start_char === '<') {
  1682. printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
  1683. if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
  1684. printer.print_newline(false);
  1685. }
  1686. }
  1687. printer.print_token(raw_token);
  1688. }
  1689. if (last_tag_token.indent_content &&
  1690. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  1691. printer.indent();
  1692. // only indent once per opened tag
  1693. last_tag_token.indent_content = false;
  1694. }
  1695. if (!last_tag_token.is_inline_element &&
  1696. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  1697. printer.set_wrap_point();
  1698. }
  1699. return parser_token;
  1700. };
  1701. Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
  1702. var wrapped = last_tag_token.has_wrapped_attrs;
  1703. var parser_token = {
  1704. text: raw_token.text,
  1705. type: raw_token.type
  1706. };
  1707. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  1708. if (last_tag_token.is_unformatted) {
  1709. printer.add_raw_token(raw_token);
  1710. } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
  1711. // For the insides of handlebars allow newlines or a single space between open and contents
  1712. if (printer.print_preserved_newlines(raw_token)) {
  1713. raw_token.newlines = 0;
  1714. printer.add_raw_token(raw_token);
  1715. } else {
  1716. printer.print_token(raw_token);
  1717. }
  1718. } else {
  1719. if (raw_token.type === TOKEN.ATTRIBUTE) {
  1720. printer.set_space_before_token(true);
  1721. last_tag_token.attr_count += 1;
  1722. } else if (raw_token.type === TOKEN.EQUALS) { //no space before =
  1723. printer.set_space_before_token(false);
  1724. } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
  1725. printer.set_space_before_token(false);
  1726. }
  1727. if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
  1728. if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
  1729. printer.traverse_whitespace(raw_token);
  1730. wrapped = wrapped || raw_token.newlines !== 0;
  1731. }
  1732. if (this._is_wrap_attributes_force) {
  1733. var force_attr_wrap = last_tag_token.attr_count > 1;
  1734. if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
  1735. var is_only_attribute = true;
  1736. var peek_index = 0;
  1737. var peek_token;
  1738. do {
  1739. peek_token = tokens.peek(peek_index);
  1740. if (peek_token.type === TOKEN.ATTRIBUTE) {
  1741. is_only_attribute = false;
  1742. break;
  1743. }
  1744. peek_index += 1;
  1745. } while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
  1746. force_attr_wrap = !is_only_attribute;
  1747. }
  1748. if (force_attr_wrap) {
  1749. printer.print_newline(false);
  1750. wrapped = true;
  1751. }
  1752. }
  1753. }
  1754. printer.print_token(raw_token);
  1755. wrapped = wrapped || printer.previous_token_wrapped();
  1756. last_tag_token.has_wrapped_attrs = wrapped;
  1757. }
  1758. return parser_token;
  1759. };
  1760. Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
  1761. var parser_token = {
  1762. text: raw_token.text,
  1763. type: 'TK_CONTENT'
  1764. };
  1765. if (last_tag_token.custom_beautifier_name) { //check if we need to format javascript
  1766. this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
  1767. } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
  1768. printer.add_raw_token(raw_token);
  1769. } else {
  1770. printer.traverse_whitespace(raw_token);
  1771. printer.print_token(raw_token);
  1772. }
  1773. return parser_token;
  1774. };
  1775. Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
  1776. var local = this;
  1777. if (raw_token.text !== '') {
  1778. var text = raw_token.text,
  1779. _beautifier,
  1780. script_indent_level = 1,
  1781. pre = '',
  1782. post = '';
  1783. if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
  1784. _beautifier = this._js_beautify;
  1785. } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
  1786. _beautifier = this._css_beautify;
  1787. } else if (last_tag_token.custom_beautifier_name === 'html') {
  1788. _beautifier = function(html_source, options) {
  1789. var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
  1790. return beautifier.beautify();
  1791. };
  1792. }
  1793. if (this._options.indent_scripts === "keep") {
  1794. script_indent_level = 0;
  1795. } else if (this._options.indent_scripts === "separate") {
  1796. script_indent_level = -printer.indent_level;
  1797. }
  1798. var indentation = printer.get_full_indent(script_indent_level);
  1799. // if there is at least one empty line at the end of this text, strip it
  1800. // we'll be adding one back after the text but before the containing tag.
  1801. text = text.replace(/\n[ \t]*$/, '');
  1802. // Handle the case where content is wrapped in a comment or cdata.
  1803. if (last_tag_token.custom_beautifier_name !== 'html' &&
  1804. text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
  1805. var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
  1806. // if we start to wrap but don't finish, print raw
  1807. if (!matched) {
  1808. printer.add_raw_token(raw_token);
  1809. return;
  1810. }
  1811. pre = indentation + matched[1] + '\n';
  1812. text = matched[4];
  1813. if (matched[5]) {
  1814. post = indentation + matched[5];
  1815. }
  1816. // if there is at least one empty line at the end of this text, strip it
  1817. // we'll be adding one back after the text but before the containing tag.
  1818. text = text.replace(/\n[ \t]*$/, '');
  1819. if (matched[2] || matched[3].indexOf('\n') !== -1) {
  1820. // if the first line of the non-comment text has spaces
  1821. // use that as the basis for indenting in null case.
  1822. matched = matched[3].match(/[ \t]+$/);
  1823. if (matched) {
  1824. raw_token.whitespace_before = matched[0];
  1825. }
  1826. }
  1827. }
  1828. if (text) {
  1829. if (_beautifier) {
  1830. // call the Beautifier if avaliable
  1831. var Child_options = function() {
  1832. this.eol = '\n';
  1833. };
  1834. Child_options.prototype = this._options.raw_options;
  1835. var child_options = new Child_options();
  1836. text = _beautifier(indentation + text, child_options);
  1837. } else {
  1838. // simply indent the string otherwise
  1839. var white = raw_token.whitespace_before;
  1840. if (white) {
  1841. text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
  1842. }
  1843. text = indentation + text.replace(/\n/g, '\n' + indentation);
  1844. }
  1845. }
  1846. if (pre) {
  1847. if (!text) {
  1848. text = pre + post;
  1849. } else {
  1850. text = pre + text + '\n' + post;
  1851. }
  1852. }
  1853. printer.print_newline(false);
  1854. if (text) {
  1855. raw_token.text = text;
  1856. raw_token.whitespace_before = '';
  1857. raw_token.newlines = 0;
  1858. printer.add_raw_token(raw_token);
  1859. printer.print_newline(true);
  1860. }
  1861. }
  1862. };
  1863. Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
  1864. var parser_token = this._get_tag_open_token(raw_token);
  1865. if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
  1866. !last_tag_token.is_empty_element &&
  1867. raw_token.type === TOKEN.TAG_OPEN && raw_token.text.indexOf('</') === 0) {
  1868. // End element tags for unformatted or content_unformatted elements
  1869. // are printed raw to keep any newlines inside them exactly the same.
  1870. printer.add_raw_token(raw_token);
  1871. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
  1872. } else {
  1873. printer.traverse_whitespace(raw_token);
  1874. this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
  1875. if (!parser_token.is_inline_element) {
  1876. printer.set_wrap_point();
  1877. }
  1878. printer.print_token(raw_token);
  1879. }
  1880. //indent attributes an auto, forced, aligned or forced-align line-wrap
  1881. if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
  1882. parser_token.alignment_size = raw_token.text.length + 1;
  1883. }
  1884. if (!parser_token.tag_complete && !parser_token.is_unformatted) {
  1885. printer.alignment_size = parser_token.alignment_size;
  1886. }
  1887. return parser_token;
  1888. };
  1889. var TagOpenParserToken = function(parent, raw_token) {
  1890. this.parent = parent || null;
  1891. this.text = '';
  1892. this.type = 'TK_TAG_OPEN';
  1893. this.tag_name = '';
  1894. this.is_inline_element = false;
  1895. this.is_unformatted = false;
  1896. this.is_content_unformatted = false;
  1897. this.is_empty_element = false;
  1898. this.is_start_tag = false;
  1899. this.is_end_tag = false;
  1900. this.indent_content = false;
  1901. this.multiline_content = false;
  1902. this.custom_beautifier_name = null;
  1903. this.start_tag_token = null;
  1904. this.attr_count = 0;
  1905. this.has_wrapped_attrs = false;
  1906. this.alignment_size = 0;
  1907. this.tag_complete = false;
  1908. this.tag_start_char = '';
  1909. this.tag_check = '';
  1910. if (!raw_token) {
  1911. this.tag_complete = true;
  1912. } else {
  1913. var tag_check_match;
  1914. this.tag_start_char = raw_token.text[0];
  1915. this.text = raw_token.text;
  1916. if (this.tag_start_char === '<') {
  1917. tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
  1918. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  1919. } else {
  1920. tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
  1921. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  1922. // handle "{{#> myPartial}}
  1923. if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
  1924. this.tag_check = raw_token.next.text;
  1925. }
  1926. }
  1927. this.tag_check = this.tag_check.toLowerCase();
  1928. if (raw_token.type === TOKEN.COMMENT) {
  1929. this.tag_complete = true;
  1930. }
  1931. this.is_start_tag = this.tag_check.charAt(0) !== '/';
  1932. this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
  1933. this.is_end_tag = !this.is_start_tag ||
  1934. (raw_token.closed && raw_token.closed.text === '/>');
  1935. // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
  1936. this.is_end_tag = this.is_end_tag ||
  1937. (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(2)))));
  1938. }
  1939. };
  1940. Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
  1941. var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
  1942. parser_token.alignment_size = this._options.wrap_attributes_indent_size;
  1943. parser_token.is_end_tag = parser_token.is_end_tag ||
  1944. in_array(parser_token.tag_check, this._options.void_elements);
  1945. parser_token.is_empty_element = parser_token.tag_complete ||
  1946. (parser_token.is_start_tag && parser_token.is_end_tag);
  1947. parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
  1948. parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
  1949. parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_start_char === '{';
  1950. return parser_token;
  1951. };
  1952. Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
  1953. if (!parser_token.is_empty_element) {
  1954. if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  1955. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors
  1956. } else { // it's a start-tag
  1957. // check if this tag is starting an element that has optional end element
  1958. // and do an ending needed
  1959. if (this._do_optional_end_element(parser_token)) {
  1960. if (!parser_token.is_inline_element) {
  1961. printer.print_newline(false);
  1962. }
  1963. }
  1964. this._tag_stack.record_tag(parser_token); //push it on the tag stack
  1965. if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
  1966. !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
  1967. parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
  1968. }
  1969. }
  1970. }
  1971. if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line
  1972. printer.print_newline(false);
  1973. if (!printer._output.just_added_blankline()) {
  1974. printer.print_newline(true);
  1975. }
  1976. }
  1977. if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /)
  1978. // if you hit an else case, reset the indent level if you are inside an:
  1979. // 'if', 'unless', or 'each' block.
  1980. if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
  1981. this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
  1982. parser_token.indent_content = true;
  1983. // Don't add a newline if opening {{#if}} tag is on the current line
  1984. var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
  1985. if (!foundIfOnCurrentLine) {
  1986. printer.print_newline(false);
  1987. }
  1988. }
  1989. // Don't add a newline before elements that should remain where they are.
  1990. if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
  1991. last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) {
  1992. //Do nothing. Leave comments on same line.
  1993. } else {
  1994. if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
  1995. printer.print_newline(false);
  1996. }
  1997. this._calcluate_parent_multiline(printer, parser_token);
  1998. }
  1999. } else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  2000. var do_end_expand = false;
  2001. // deciding whether a block is multiline should not be this hard
  2002. do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
  2003. do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
  2004. !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
  2005. !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
  2006. last_token.type !== 'TK_CONTENT'
  2007. );
  2008. if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
  2009. do_end_expand = false;
  2010. }
  2011. if (do_end_expand) {
  2012. printer.print_newline(false);
  2013. }
  2014. } else { // it's a start-tag
  2015. parser_token.indent_content = !parser_token.custom_beautifier_name;
  2016. if (parser_token.tag_start_char === '<') {
  2017. if (parser_token.tag_name === 'html') {
  2018. parser_token.indent_content = this._options.indent_inner_html;
  2019. } else if (parser_token.tag_name === 'head') {
  2020. parser_token.indent_content = this._options.indent_head_inner_html;
  2021. } else if (parser_token.tag_name === 'body') {
  2022. parser_token.indent_content = this._options.indent_body_inner_html;
  2023. }
  2024. }
  2025. if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
  2026. (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
  2027. printer.print_newline(false);
  2028. }
  2029. this._calcluate_parent_multiline(printer, parser_token);
  2030. }
  2031. };
  2032. Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
  2033. if (parser_token.parent && printer._output.just_added_newline() &&
  2034. !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
  2035. parser_token.parent.multiline_content = true;
  2036. }
  2037. };
  2038. //To be used for <p> tag special case:
  2039. 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'];
  2040. var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
  2041. Beautifier.prototype._do_optional_end_element = function(parser_token) {
  2042. var result = null;
  2043. // NOTE: cases of "if there is no more content in the parent element"
  2044. // are handled automatically by the beautifier.
  2045. // It assumes parent or ancestor close tag closes all children.
  2046. // https://www.w3.org/TR/html5/syntax.html#optional-tags
  2047. if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
  2048. return;
  2049. }
  2050. if (parser_token.tag_name === 'body') {
  2051. // A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
  2052. result = result || this._tag_stack.try_pop('head');
  2053. //} else if (parser_token.tag_name === 'body') {
  2054. // DONE: A body element’s end tag may be omitted if the body element is not immediately followed by a comment.
  2055. } else if (parser_token.tag_name === 'li') {
  2056. // 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.
  2057. result = result || this._tag_stack.try_pop('li', ['ol', 'ul']);
  2058. } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
  2059. // 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.
  2060. // A dt element’s end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.
  2061. result = result || this._tag_stack.try_pop('dt', ['dl']);
  2062. result = result || this._tag_stack.try_pop('dd', ['dl']);
  2063. } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
  2064. // IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
  2065. // check for 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.
  2066. // To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
  2067. // But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
  2068. var p_parent = parser_token.parent.parent;
  2069. if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
  2070. result = result || this._tag_stack.try_pop('p');
  2071. }
  2072. } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
  2073. // 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.
  2074. // 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.
  2075. result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
  2076. result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
  2077. } else if (parser_token.tag_name === 'optgroup') {
  2078. // 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.
  2079. // 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.
  2080. result = result || this._tag_stack.try_pop('optgroup', ['select']);
  2081. //result = result || this._tag_stack.try_pop('option', ['select']);
  2082. } else if (parser_token.tag_name === 'option') {
  2083. // 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.
  2084. result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
  2085. } else if (parser_token.tag_name === 'colgroup') {
  2086. // 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.
  2087. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  2088. result = result || this._tag_stack.try_pop('caption', ['table']);
  2089. } else if (parser_token.tag_name === 'thead') {
  2090. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  2091. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  2092. result = result || this._tag_stack.try_pop('caption', ['table']);
  2093. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  2094. //} else if (parser_token.tag_name === 'caption') {
  2095. // 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.
  2096. } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
  2097. // A thead element’s end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.
  2098. // 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.
  2099. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  2100. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  2101. result = result || this._tag_stack.try_pop('caption', ['table']);
  2102. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  2103. result = result || this._tag_stack.try_pop('thead', ['table']);
  2104. result = result || this._tag_stack.try_pop('tbody', ['table']);
  2105. //} else if (parser_token.tag_name === 'tfoot') {
  2106. // DONE: A tfoot element’s end tag may be omitted if there is no more content in the parent element.
  2107. } else if (parser_token.tag_name === 'tr') {
  2108. // 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.
  2109. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  2110. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  2111. result = result || this._tag_stack.try_pop('caption', ['table']);
  2112. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  2113. result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
  2114. } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
  2115. // 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.
  2116. // 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.
  2117. result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  2118. result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  2119. }
  2120. // Start element omission not handled currently
  2121. // 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.
  2122. // 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.)
  2123. // 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.)
  2124. // Fix up the parent of the parser token
  2125. parser_token.parent = this._tag_stack.get_parser_token();
  2126. return result;
  2127. };
  2128. module.exports.Beautifier = Beautifier;
  2129. /***/ }),
  2130. /* 20 */
  2131. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2132. /*jshint node:true */
  2133. /*
  2134. The MIT License (MIT)
  2135. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2136. Permission is hereby granted, free of charge, to any person
  2137. obtaining a copy of this software and associated documentation files
  2138. (the "Software"), to deal in the Software without restriction,
  2139. including without limitation the rights to use, copy, modify, merge,
  2140. publish, distribute, sublicense, and/or sell copies of the Software,
  2141. and to permit persons to whom the Software is furnished to do so,
  2142. subject to the following conditions:
  2143. The above copyright notice and this permission notice shall be
  2144. included in all copies or substantial portions of the Software.
  2145. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2146. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2147. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2148. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2149. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2150. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2151. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2152. SOFTWARE.
  2153. */
  2154. var BaseOptions = __webpack_require__(6).Options;
  2155. function Options(options) {
  2156. BaseOptions.call(this, options, 'html');
  2157. if (this.templating.length === 1 && this.templating[0] === 'auto') {
  2158. this.templating = ['django', 'erb', 'handlebars', 'php'];
  2159. }
  2160. this.indent_inner_html = this._get_boolean('indent_inner_html');
  2161. this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
  2162. this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
  2163. this.indent_handlebars = this._get_boolean('indent_handlebars', true);
  2164. this.wrap_attributes = this._get_selection('wrap_attributes',
  2165. ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
  2166. this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
  2167. this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
  2168. // Block vs inline elements
  2169. // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
  2170. // https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
  2171. // https://www.w3.org/TR/html5/dom.html#phrasing-content
  2172. this.inline = this._get_array('inline', [
  2173. 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
  2174. 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
  2175. 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
  2176. 'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
  2177. 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
  2178. 'video', 'wbr', 'text',
  2179. // obsolete inline tags
  2180. 'acronym', 'big', 'strike', 'tt'
  2181. ]);
  2182. this.void_elements = this._get_array('void_elements', [
  2183. // HTLM void elements - aka self-closing tags - aka singletons
  2184. // https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
  2185. 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
  2186. 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
  2187. // NOTE: Optional tags are too complex for a simple list
  2188. // they are hard coded in _do_optional_end_element
  2189. // Doctype and xml elements
  2190. '!doctype', '?xml',
  2191. // obsolete tags
  2192. // basefont: https://www.computerhope.com/jargon/h/html-basefont-tag.htm
  2193. // isndex: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex
  2194. 'basefont', 'isindex'
  2195. ]);
  2196. this.unformatted = this._get_array('unformatted', []);
  2197. this.content_unformatted = this._get_array('content_unformatted', [
  2198. 'pre', 'textarea'
  2199. ]);
  2200. this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
  2201. this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
  2202. }
  2203. Options.prototype = new BaseOptions();
  2204. module.exports.Options = Options;
  2205. /***/ }),
  2206. /* 21 */
  2207. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2208. /*jshint node:true */
  2209. /*
  2210. The MIT License (MIT)
  2211. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2212. Permission is hereby granted, free of charge, to any person
  2213. obtaining a copy of this software and associated documentation files
  2214. (the "Software"), to deal in the Software without restriction,
  2215. including without limitation the rights to use, copy, modify, merge,
  2216. publish, distribute, sublicense, and/or sell copies of the Software,
  2217. and to permit persons to whom the Software is furnished to do so,
  2218. subject to the following conditions:
  2219. The above copyright notice and this permission notice shall be
  2220. included in all copies or substantial portions of the Software.
  2221. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2222. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2223. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2224. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2225. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2226. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2227. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2228. SOFTWARE.
  2229. */
  2230. var BaseTokenizer = __webpack_require__(9).Tokenizer;
  2231. var BASETOKEN = __webpack_require__(9).TOKEN;
  2232. var Directives = __webpack_require__(13).Directives;
  2233. var TemplatablePattern = __webpack_require__(14).TemplatablePattern;
  2234. var Pattern = __webpack_require__(12).Pattern;
  2235. var TOKEN = {
  2236. TAG_OPEN: 'TK_TAG_OPEN',
  2237. TAG_CLOSE: 'TK_TAG_CLOSE',
  2238. ATTRIBUTE: 'TK_ATTRIBUTE',
  2239. EQUALS: 'TK_EQUALS',
  2240. VALUE: 'TK_VALUE',
  2241. COMMENT: 'TK_COMMENT',
  2242. TEXT: 'TK_TEXT',
  2243. UNKNOWN: 'TK_UNKNOWN',
  2244. START: BASETOKEN.START,
  2245. RAW: BASETOKEN.RAW,
  2246. EOF: BASETOKEN.EOF
  2247. };
  2248. var directives_core = new Directives(/<\!--/, /-->/);
  2249. var Tokenizer = function(input_string, options) {
  2250. BaseTokenizer.call(this, input_string, options);
  2251. this._current_tag_name = '';
  2252. // Words end at whitespace or when a tag starts
  2253. // if we are indenting handlebars, they are considered tags
  2254. var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
  2255. var pattern_reader = new Pattern(this._input);
  2256. this.__patterns = {
  2257. word: templatable_reader.until(/[\n\r\t <]/),
  2258. single_quote: templatable_reader.until_after(/'/),
  2259. double_quote: templatable_reader.until_after(/"/),
  2260. attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
  2261. element_name: templatable_reader.until(/[\n\r\t >\/]/),
  2262. handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
  2263. handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
  2264. handlebars_open: pattern_reader.until(/[\n\r\t }]/),
  2265. handlebars_raw_close: pattern_reader.until(/}}/),
  2266. comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
  2267. cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
  2268. // https://en.wikipedia.org/wiki/Conditional_comment
  2269. conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
  2270. processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
  2271. };
  2272. if (this._options.indent_handlebars) {
  2273. this.__patterns.word = this.__patterns.word.exclude('handlebars');
  2274. }
  2275. this._unformatted_content_delimiter = null;
  2276. if (this._options.unformatted_content_delimiter) {
  2277. var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
  2278. this.__patterns.unformatted_content_delimiter =
  2279. pattern_reader.matching(literal_regexp)
  2280. .until_after(literal_regexp);
  2281. }
  2282. };
  2283. Tokenizer.prototype = new BaseTokenizer();
  2284. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  2285. return false; //current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.UNKNOWN;
  2286. };
  2287. Tokenizer.prototype._is_opening = function(current_token) {
  2288. return current_token.type === TOKEN.TAG_OPEN;
  2289. };
  2290. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  2291. return current_token.type === TOKEN.TAG_CLOSE &&
  2292. (open_token && (
  2293. ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
  2294. (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
  2295. };
  2296. Tokenizer.prototype._reset = function() {
  2297. this._current_tag_name = '';
  2298. };
  2299. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2300. var token = null;
  2301. this._readWhitespace();
  2302. var c = this._input.peek();
  2303. if (c === null) {
  2304. return this._create_token(TOKEN.EOF, '');
  2305. }
  2306. token = token || this._read_open_handlebars(c, open_token);
  2307. token = token || this._read_attribute(c, previous_token, open_token);
  2308. token = token || this._read_close(c, open_token);
  2309. token = token || this._read_raw_content(c, previous_token, open_token);
  2310. token = token || this._read_content_word(c);
  2311. token = token || this._read_comment_or_cdata(c);
  2312. token = token || this._read_processing(c);
  2313. token = token || this._read_open(c, open_token);
  2314. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  2315. return token;
  2316. };
  2317. Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
  2318. var token = null;
  2319. var resulting_string = null;
  2320. var directives = null;
  2321. if (c === '<') {
  2322. var peek1 = this._input.peek(1);
  2323. // We treat all comments as literals, even more than preformatted tags
  2324. // we only look for the appropriate closing marker
  2325. if (peek1 === '!') {
  2326. resulting_string = this.__patterns.comment.read();
  2327. // only process directive on html comments
  2328. if (resulting_string) {
  2329. directives = directives_core.get_directives(resulting_string);
  2330. if (directives && directives.ignore === 'start') {
  2331. resulting_string += directives_core.readIgnored(this._input);
  2332. }
  2333. } else {
  2334. resulting_string = this.__patterns.cdata.read();
  2335. }
  2336. }
  2337. if (resulting_string) {
  2338. token = this._create_token(TOKEN.COMMENT, resulting_string);
  2339. token.directives = directives;
  2340. }
  2341. }
  2342. return token;
  2343. };
  2344. Tokenizer.prototype._read_processing = function(c) { // jshint unused:false
  2345. var token = null;
  2346. var resulting_string = null;
  2347. var directives = null;
  2348. if (c === '<') {
  2349. var peek1 = this._input.peek(1);
  2350. if (peek1 === '!' || peek1 === '?') {
  2351. resulting_string = this.__patterns.conditional_comment.read();
  2352. resulting_string = resulting_string || this.__patterns.processing.read();
  2353. }
  2354. if (resulting_string) {
  2355. token = this._create_token(TOKEN.COMMENT, resulting_string);
  2356. token.directives = directives;
  2357. }
  2358. }
  2359. return token;
  2360. };
  2361. Tokenizer.prototype._read_open = function(c, open_token) {
  2362. var resulting_string = null;
  2363. var token = null;
  2364. if (!open_token) {
  2365. if (c === '<') {
  2366. resulting_string = this._input.next();
  2367. if (this._input.peek() === '/') {
  2368. resulting_string += this._input.next();
  2369. }
  2370. resulting_string += this.__patterns.element_name.read();
  2371. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  2372. }
  2373. }
  2374. return token;
  2375. };
  2376. Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
  2377. var resulting_string = null;
  2378. var token = null;
  2379. if (!open_token) {
  2380. if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
  2381. if (this._input.peek(2) === '!') {
  2382. resulting_string = this.__patterns.handlebars_comment.read();
  2383. resulting_string = resulting_string || this.__patterns.handlebars.read();
  2384. token = this._create_token(TOKEN.COMMENT, resulting_string);
  2385. } else {
  2386. resulting_string = this.__patterns.handlebars_open.read();
  2387. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  2388. }
  2389. }
  2390. }
  2391. return token;
  2392. };
  2393. Tokenizer.prototype._read_close = function(c, open_token) {
  2394. var resulting_string = null;
  2395. var token = null;
  2396. if (open_token) {
  2397. if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
  2398. resulting_string = this._input.next();
  2399. if (c === '/') { // for close tag "/>"
  2400. resulting_string += this._input.next();
  2401. }
  2402. token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
  2403. } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
  2404. this._input.next();
  2405. this._input.next();
  2406. token = this._create_token(TOKEN.TAG_CLOSE, '}}');
  2407. }
  2408. }
  2409. return token;
  2410. };
  2411. Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
  2412. var token = null;
  2413. var resulting_string = '';
  2414. if (open_token && open_token.text[0] === '<') {
  2415. if (c === '=') {
  2416. token = this._create_token(TOKEN.EQUALS, this._input.next());
  2417. } else if (c === '"' || c === "'") {
  2418. var content = this._input.next();
  2419. if (c === '"') {
  2420. content += this.__patterns.double_quote.read();
  2421. } else {
  2422. content += this.__patterns.single_quote.read();
  2423. }
  2424. token = this._create_token(TOKEN.VALUE, content);
  2425. } else {
  2426. resulting_string = this.__patterns.attribute.read();
  2427. if (resulting_string) {
  2428. if (previous_token.type === TOKEN.EQUALS) {
  2429. token = this._create_token(TOKEN.VALUE, resulting_string);
  2430. } else {
  2431. token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
  2432. }
  2433. }
  2434. }
  2435. }
  2436. return token;
  2437. };
  2438. Tokenizer.prototype._is_content_unformatted = function(tag_name) {
  2439. // void_elements have no content and so cannot have unformatted content
  2440. // script and style tags should always be read as unformatted content
  2441. // finally content_unformatted and unformatted element contents are unformatted
  2442. return this._options.void_elements.indexOf(tag_name) === -1 &&
  2443. (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
  2444. this._options.unformatted.indexOf(tag_name) !== -1);
  2445. };
  2446. Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
  2447. var resulting_string = '';
  2448. if (open_token && open_token.text[0] === '{') {
  2449. resulting_string = this.__patterns.handlebars_raw_close.read();
  2450. } else if (previous_token.type === TOKEN.TAG_CLOSE &&
  2451. previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
  2452. // ^^ empty tag has no content
  2453. var tag_name = previous_token.opened.text.substr(1).toLowerCase();
  2454. if (tag_name === 'script' || tag_name === 'style') {
  2455. // Script and style tags are allowed to have comments wrapping their content
  2456. // or just have regular content.
  2457. var token = this._read_comment_or_cdata(c);
  2458. if (token) {
  2459. token.type = TOKEN.TEXT;
  2460. return token;
  2461. }
  2462. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  2463. } else if (this._is_content_unformatted(tag_name)) {
  2464. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  2465. }
  2466. }
  2467. if (resulting_string) {
  2468. return this._create_token(TOKEN.TEXT, resulting_string);
  2469. }
  2470. return null;
  2471. };
  2472. Tokenizer.prototype._read_content_word = function(c) {
  2473. var resulting_string = '';
  2474. if (this._options.unformatted_content_delimiter) {
  2475. if (c === this._options.unformatted_content_delimiter[0]) {
  2476. resulting_string = this.__patterns.unformatted_content_delimiter.read();
  2477. }
  2478. }
  2479. if (!resulting_string) {
  2480. resulting_string = this.__patterns.word.read();
  2481. }
  2482. if (resulting_string) {
  2483. return this._create_token(TOKEN.TEXT, resulting_string);
  2484. }
  2485. };
  2486. module.exports.Tokenizer = Tokenizer;
  2487. module.exports.TOKEN = TOKEN;
  2488. /***/ })
  2489. /******/ ]);
  2490. /************************************************************************/
  2491. /******/ // The module cache
  2492. /******/ var __webpack_module_cache__ = {};
  2493. /******/
  2494. /******/ // The require function
  2495. /******/ function __webpack_require__(moduleId) {
  2496. /******/ // Check if module is in cache
  2497. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  2498. /******/ if (cachedModule !== undefined) {
  2499. /******/ return cachedModule.exports;
  2500. /******/ }
  2501. /******/ // Create a new module (and put it into the cache)
  2502. /******/ var module = __webpack_module_cache__[moduleId] = {
  2503. /******/ // no module.id needed
  2504. /******/ // no module.loaded needed
  2505. /******/ exports: {}
  2506. /******/ };
  2507. /******/
  2508. /******/ // Execute the module function
  2509. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  2510. /******/
  2511. /******/ // Return the exports of the module
  2512. /******/ return module.exports;
  2513. /******/ }
  2514. /******/
  2515. /************************************************************************/
  2516. /******/
  2517. /******/ // startup
  2518. /******/ // Load entry module and return exports
  2519. /******/ // This entry module is referenced by other modules so it can't be inlined
  2520. /******/ var __webpack_exports__ = __webpack_require__(18);
  2521. /******/ legacy_beautify_html = __webpack_exports__;
  2522. /******/
  2523. /******/ })()
  2524. ;
  2525. var style_html = legacy_beautify_html;
  2526. /* Footer */
  2527. if (typeof define === "function" && define.amd) {
  2528. // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
  2529. define(["require", "./beautify", "./beautify-css"], function(requireamd) {
  2530. var js_beautify = requireamd("./beautify");
  2531. var css_beautify = requireamd("./beautify-css");
  2532. return {
  2533. html_beautify: function(html_source, options) {
  2534. return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
  2535. }
  2536. };
  2537. });
  2538. } else if (typeof exports !== "undefined") {
  2539. // Add support for CommonJS. Just put this file somewhere on your require.paths
  2540. // and you will be able to `var html_beautify = require("beautify").html_beautify`.
  2541. var js_beautify = require('./beautify.js');
  2542. var css_beautify = require('./beautify-css.js');
  2543. exports.html_beautify = function(html_source, options) {
  2544. return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
  2545. };
  2546. } else if (typeof window !== "undefined") {
  2547. // If we're running a web page and don't have either of the above, add our one global
  2548. window.html_beautify = function(html_source, options) {
  2549. return style_html(html_source, options, window.js_beautify, window.css_beautify);
  2550. };
  2551. } else if (typeof global !== "undefined") {
  2552. // If we don't even have window, try global.
  2553. global.html_beautify = function(html_source, options) {
  2554. return style_html(html_source, options, global.js_beautify, global.css_beautify);
  2555. };
  2556. }
  2557. }());