123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123 |
- (function() {
- var legacy_beautify_html;
- (function() {
- "use strict";
- var __webpack_modules__ = ([
- ,
- ,
- (function(module) {
- function OutputLine(parent) {
- this.__parent = parent;
- this.__character_count = 0;
-
- this.__indent_count = -1;
- this.__alignment_count = 0;
- this.__wrap_point_index = 0;
- this.__wrap_point_character_count = 0;
- this.__wrap_point_indent_count = -1;
- this.__wrap_point_alignment_count = 0;
- this.__items = [];
- }
- OutputLine.prototype.clone_empty = function() {
- var line = new OutputLine(this.__parent);
- line.set_indent(this.__indent_count, this.__alignment_count);
- return line;
- };
- OutputLine.prototype.item = function(index) {
- if (index < 0) {
- return this.__items[this.__items.length + index];
- } else {
- return this.__items[index];
- }
- };
- OutputLine.prototype.has_match = function(pattern) {
- for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
- if (this.__items[lastCheckedOutput].match(pattern)) {
- return true;
- }
- }
- return false;
- };
- OutputLine.prototype.set_indent = function(indent, alignment) {
- if (this.is_empty()) {
- this.__indent_count = indent || 0;
- this.__alignment_count = alignment || 0;
- this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
- }
- };
- OutputLine.prototype._set_wrap_point = function() {
- if (this.__parent.wrap_line_length) {
- this.__wrap_point_index = this.__items.length;
- this.__wrap_point_character_count = this.__character_count;
- this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
- this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
- }
- };
- OutputLine.prototype._should_wrap = function() {
- return this.__wrap_point_index &&
- this.__character_count > this.__parent.wrap_line_length &&
- this.__wrap_point_character_count > this.__parent.next_line.__character_count;
- };
- OutputLine.prototype._allow_wrap = function() {
- if (this._should_wrap()) {
- this.__parent.add_new_line();
- var next = this.__parent.current_line;
- next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
- next.__items = this.__items.slice(this.__wrap_point_index);
- this.__items = this.__items.slice(0, this.__wrap_point_index);
- next.__character_count += this.__character_count - this.__wrap_point_character_count;
- this.__character_count = this.__wrap_point_character_count;
- if (next.__items[0] === " ") {
- next.__items.splice(0, 1);
- next.__character_count -= 1;
- }
- return true;
- }
- return false;
- };
- OutputLine.prototype.is_empty = function() {
- return this.__items.length === 0;
- };
- OutputLine.prototype.last = function() {
- if (!this.is_empty()) {
- return this.__items[this.__items.length - 1];
- } else {
- return null;
- }
- };
- OutputLine.prototype.push = function(item) {
- this.__items.push(item);
- var last_newline_index = item.lastIndexOf('\n');
- if (last_newline_index !== -1) {
- this.__character_count = item.length - last_newline_index;
- } else {
- this.__character_count += item.length;
- }
- };
- OutputLine.prototype.pop = function() {
- var item = null;
- if (!this.is_empty()) {
- item = this.__items.pop();
- this.__character_count -= item.length;
- }
- return item;
- };
- OutputLine.prototype._remove_indent = function() {
- if (this.__indent_count > 0) {
- this.__indent_count -= 1;
- this.__character_count -= this.__parent.indent_size;
- }
- };
- OutputLine.prototype._remove_wrap_indent = function() {
- if (this.__wrap_point_indent_count > 0) {
- this.__wrap_point_indent_count -= 1;
- }
- };
- OutputLine.prototype.trim = function() {
- while (this.last() === ' ') {
- this.__items.pop();
- this.__character_count -= 1;
- }
- };
- OutputLine.prototype.toString = function() {
- var result = '';
- if (this.is_empty()) {
- if (this.__parent.indent_empty_lines) {
- result = this.__parent.get_indent_string(this.__indent_count);
- }
- } else {
- result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
- result += this.__items.join('');
- }
- return result;
- };
- function IndentStringCache(options, baseIndentString) {
- this.__cache = [''];
- this.__indent_size = options.indent_size;
- this.__indent_string = options.indent_char;
- if (!options.indent_with_tabs) {
- this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
- }
-
- baseIndentString = baseIndentString || '';
- if (options.indent_level > 0) {
- baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
- }
- this.__base_string = baseIndentString;
- this.__base_string_length = baseIndentString.length;
- }
- IndentStringCache.prototype.get_indent_size = function(indent, column) {
- var result = this.__base_string_length;
- column = column || 0;
- if (indent < 0) {
- result = 0;
- }
- result += indent * this.__indent_size;
- result += column;
- return result;
- };
- IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
- var result = this.__base_string;
- column = column || 0;
- if (indent_level < 0) {
- indent_level = 0;
- result = '';
- }
- column += indent_level * this.__indent_size;
- this.__ensure_cache(column);
- result += this.__cache[column];
- return result;
- };
- IndentStringCache.prototype.__ensure_cache = function(column) {
- while (column >= this.__cache.length) {
- this.__add_column();
- }
- };
- IndentStringCache.prototype.__add_column = function() {
- var column = this.__cache.length;
- var indent = 0;
- var result = '';
- if (this.__indent_size && column >= this.__indent_size) {
- indent = Math.floor(column / this.__indent_size);
- column -= indent * this.__indent_size;
- result = new Array(indent + 1).join(this.__indent_string);
- }
- if (column) {
- result += new Array(column + 1).join(' ');
- }
- this.__cache.push(result);
- };
- function Output(options, baseIndentString) {
- this.__indent_cache = new IndentStringCache(options, baseIndentString);
- this.raw = false;
- this._end_with_newline = options.end_with_newline;
- this.indent_size = options.indent_size;
- this.wrap_line_length = options.wrap_line_length;
- this.indent_empty_lines = options.indent_empty_lines;
- this.__lines = [];
- this.previous_line = null;
- this.current_line = null;
- this.next_line = new OutputLine(this);
- this.space_before_token = false;
- this.non_breaking_space = false;
- this.previous_token_wrapped = false;
-
- this.__add_outputline();
- }
- Output.prototype.__add_outputline = function() {
- this.previous_line = this.current_line;
- this.current_line = this.next_line.clone_empty();
- this.__lines.push(this.current_line);
- };
- Output.prototype.get_line_number = function() {
- return this.__lines.length;
- };
- Output.prototype.get_indent_string = function(indent, column) {
- return this.__indent_cache.get_indent_string(indent, column);
- };
- Output.prototype.get_indent_size = function(indent, column) {
- return this.__indent_cache.get_indent_size(indent, column);
- };
- Output.prototype.is_empty = function() {
- return !this.previous_line && this.current_line.is_empty();
- };
- Output.prototype.add_new_line = function(force_newline) {
-
-
- if (this.is_empty() ||
- (!force_newline && this.just_added_newline())) {
- return false;
- }
-
-
- if (!this.raw) {
- this.__add_outputline();
- }
- return true;
- };
- Output.prototype.get_code = function(eol) {
- this.trim(true);
-
-
- var last_item = this.current_line.pop();
- if (last_item) {
- if (last_item[last_item.length - 1] === '\n') {
- last_item = last_item.replace(/\n+$/g, '');
- }
- this.current_line.push(last_item);
- }
- if (this._end_with_newline) {
- this.__add_outputline();
- }
- var sweet_code = this.__lines.join('\n');
- if (eol !== '\n') {
- sweet_code = sweet_code.replace(/[\n]/g, eol);
- }
- return sweet_code;
- };
- Output.prototype.set_wrap_point = function() {
- this.current_line._set_wrap_point();
- };
- Output.prototype.set_indent = function(indent, alignment) {
- indent = indent || 0;
- alignment = alignment || 0;
-
- this.next_line.set_indent(indent, alignment);
-
- if (this.__lines.length > 1) {
- this.current_line.set_indent(indent, alignment);
- return true;
- }
- this.current_line.set_indent();
- return false;
- };
- Output.prototype.add_raw_token = function(token) {
- for (var x = 0; x < token.newlines; x++) {
- this.__add_outputline();
- }
- this.current_line.set_indent(-1);
- this.current_line.push(token.whitespace_before);
- this.current_line.push(token.text);
- this.space_before_token = false;
- this.non_breaking_space = false;
- this.previous_token_wrapped = false;
- };
- Output.prototype.add_token = function(printable_token) {
- this.__add_space_before_token();
- this.current_line.push(printable_token);
- this.space_before_token = false;
- this.non_breaking_space = false;
- this.previous_token_wrapped = this.current_line._allow_wrap();
- };
- Output.prototype.__add_space_before_token = function() {
- if (this.space_before_token && !this.just_added_newline()) {
- if (!this.non_breaking_space) {
- this.set_wrap_point();
- }
- this.current_line.push(' ');
- }
- };
- Output.prototype.remove_indent = function(index) {
- var output_length = this.__lines.length;
- while (index < output_length) {
- this.__lines[index]._remove_indent();
- index++;
- }
- this.current_line._remove_wrap_indent();
- };
- Output.prototype.trim = function(eat_newlines) {
- eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
- this.current_line.trim();
- while (eat_newlines && this.__lines.length > 1 &&
- this.current_line.is_empty()) {
- this.__lines.pop();
- this.current_line = this.__lines[this.__lines.length - 1];
- this.current_line.trim();
- }
- this.previous_line = this.__lines.length > 1 ?
- this.__lines[this.__lines.length - 2] : null;
- };
- Output.prototype.just_added_newline = function() {
- return this.current_line.is_empty();
- };
- Output.prototype.just_added_blankline = function() {
- return this.is_empty() ||
- (this.current_line.is_empty() && this.previous_line.is_empty());
- };
- Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
- var index = this.__lines.length - 2;
- while (index >= 0) {
- var potentialEmptyLine = this.__lines[index];
- if (potentialEmptyLine.is_empty()) {
- break;
- } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
- potentialEmptyLine.item(-1) !== ends_with) {
- this.__lines.splice(index + 1, 0, new OutputLine(this));
- this.previous_line = this.__lines[this.__lines.length - 2];
- break;
- }
- index--;
- }
- };
- module.exports.Output = Output;
- }),
- (function(module) {
- function Token(type, text, newlines, whitespace_before) {
- this.type = type;
- this.text = text;
-
-
-
-
- this.comments_before = null;
-
- this.newlines = newlines || 0;
- this.whitespace_before = whitespace_before || '';
- this.parent = null;
- this.next = null;
- this.previous = null;
- this.opened = null;
- this.closed = null;
- this.directives = null;
- }
- module.exports.Token = Token;
- }),
- ,
- ,
- (function(module) {
- function Options(options, merge_child_field) {
- this.raw_options = _mergeOpts(options, merge_child_field);
-
- this.disabled = this._get_boolean('disabled');
- this.eol = this._get_characters('eol', 'auto');
- this.end_with_newline = this._get_boolean('end_with_newline');
- this.indent_size = this._get_number('indent_size', 4);
- this.indent_char = this._get_characters('indent_char', ' ');
- this.indent_level = this._get_number('indent_level');
- this.preserve_newlines = this._get_boolean('preserve_newlines', true);
- this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
- if (!this.preserve_newlines) {
- this.max_preserve_newlines = 0;
- }
- this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
- if (this.indent_with_tabs) {
- this.indent_char = '\t';
-
-
-
-
-
-
-
- if (this.indent_size === 1) {
- this.indent_size = 4;
- }
- }
-
- this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
- this.indent_empty_lines = this._get_boolean('indent_empty_lines');
-
-
-
- this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
- }
- Options.prototype._get_array = function(name, default_value) {
- var option_value = this.raw_options[name];
- var result = default_value || [];
- if (typeof option_value === 'object') {
- if (option_value !== null && typeof option_value.concat === 'function') {
- result = option_value.concat();
- }
- } else if (typeof option_value === 'string') {
- result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
- }
- return result;
- };
- Options.prototype._get_boolean = function(name, default_value) {
- var option_value = this.raw_options[name];
- var result = option_value === undefined ? !!default_value : !!option_value;
- return result;
- };
- Options.prototype._get_characters = function(name, default_value) {
- var option_value = this.raw_options[name];
- var result = default_value || '';
- if (typeof option_value === 'string') {
- result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
- }
- return result;
- };
- Options.prototype._get_number = function(name, default_value) {
- var option_value = this.raw_options[name];
- default_value = parseInt(default_value, 10);
- if (isNaN(default_value)) {
- default_value = 0;
- }
- var result = parseInt(option_value, 10);
- if (isNaN(result)) {
- result = default_value;
- }
- return result;
- };
- Options.prototype._get_selection = function(name, selection_list, default_value) {
- var result = this._get_selection_list(name, selection_list, default_value);
- if (result.length !== 1) {
- throw new Error(
- "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
- selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
- }
- return result[0];
- };
- Options.prototype._get_selection_list = function(name, selection_list, default_value) {
- if (!selection_list || selection_list.length === 0) {
- throw new Error("Selection list cannot be empty.");
- }
- default_value = default_value || [selection_list[0]];
- if (!this._is_valid_selection(default_value, selection_list)) {
- throw new Error("Invalid Default Value!");
- }
- var result = this._get_array(name, default_value);
- if (!this._is_valid_selection(result, selection_list)) {
- throw new Error(
- "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
- selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
- }
- return result;
- };
- Options.prototype._is_valid_selection = function(result, selection_list) {
- return result.length && selection_list.length &&
- !result.some(function(item) { return selection_list.indexOf(item) === -1; });
- };
- function _mergeOpts(allOptions, childFieldName) {
- var finalOpts = {};
- allOptions = _normalizeOpts(allOptions);
- var name;
- for (name in allOptions) {
- if (name !== childFieldName) {
- finalOpts[name] = allOptions[name];
- }
- }
-
- if (childFieldName && allOptions[childFieldName]) {
- for (name in allOptions[childFieldName]) {
- finalOpts[name] = allOptions[childFieldName][name];
- }
- }
- return finalOpts;
- }
- function _normalizeOpts(options) {
- var convertedOpts = {};
- var key;
- for (key in options) {
- var newKey = key.replace(/-/g, "_");
- convertedOpts[newKey] = options[key];
- }
- return convertedOpts;
- }
- module.exports.Options = Options;
- module.exports.normalizeOpts = _normalizeOpts;
- module.exports.mergeOpts = _mergeOpts;
- }),
- ,
- (function(module) {
- var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
- function InputScanner(input_string) {
- this.__input = input_string || '';
- this.__input_length = this.__input.length;
- this.__position = 0;
- }
- InputScanner.prototype.restart = function() {
- this.__position = 0;
- };
- InputScanner.prototype.back = function() {
- if (this.__position > 0) {
- this.__position -= 1;
- }
- };
- InputScanner.prototype.hasNext = function() {
- return this.__position < this.__input_length;
- };
- InputScanner.prototype.next = function() {
- var val = null;
- if (this.hasNext()) {
- val = this.__input.charAt(this.__position);
- this.__position += 1;
- }
- return val;
- };
- InputScanner.prototype.peek = function(index) {
- var val = null;
- index = index || 0;
- index += this.__position;
- if (index >= 0 && index < this.__input_length) {
- val = this.__input.charAt(index);
- }
- return val;
- };
- InputScanner.prototype.__match = function(pattern, index) {
- pattern.lastIndex = index;
- var pattern_match = pattern.exec(this.__input);
- if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
- if (pattern_match.index !== index) {
- pattern_match = null;
- }
- }
- return pattern_match;
- };
- InputScanner.prototype.test = function(pattern, index) {
- index = index || 0;
- index += this.__position;
- if (index >= 0 && index < this.__input_length) {
- return !!this.__match(pattern, index);
- } else {
- return false;
- }
- };
- InputScanner.prototype.testChar = function(pattern, index) {
-
- var val = this.peek(index);
- pattern.lastIndex = 0;
- return val !== null && pattern.test(val);
- };
- InputScanner.prototype.match = function(pattern) {
- var pattern_match = this.__match(pattern, this.__position);
- if (pattern_match) {
- this.__position += pattern_match[0].length;
- } else {
- pattern_match = null;
- }
- return pattern_match;
- };
- InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
- var val = '';
- var match;
- if (starting_pattern) {
- match = this.match(starting_pattern);
- if (match) {
- val += match[0];
- }
- }
- if (until_pattern && (match || !starting_pattern)) {
- val += this.readUntil(until_pattern, until_after);
- }
- return val;
- };
- InputScanner.prototype.readUntil = function(pattern, until_after) {
- var val = '';
- var match_index = this.__position;
- pattern.lastIndex = this.__position;
- var pattern_match = pattern.exec(this.__input);
- if (pattern_match) {
- match_index = pattern_match.index;
- if (until_after) {
- match_index += pattern_match[0].length;
- }
- } else {
- match_index = this.__input_length;
- }
- val = this.__input.substring(this.__position, match_index);
- this.__position = match_index;
- return val;
- };
- InputScanner.prototype.readUntilAfter = function(pattern) {
- return this.readUntil(pattern, true);
- };
- InputScanner.prototype.get_regexp = function(pattern, match_from) {
- var result = null;
- var flags = 'g';
- if (match_from && regexp_has_sticky) {
- flags = 'y';
- }
-
- if (typeof pattern === "string" && pattern !== '') {
-
- result = new RegExp(pattern, flags);
- } else if (pattern) {
- result = new RegExp(pattern.source, flags);
- }
- return result;
- };
- InputScanner.prototype.get_literal_regexp = function(literal_string) {
- return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
- };
- InputScanner.prototype.peekUntilAfter = function(pattern) {
- var start = this.__position;
- var val = this.readUntilAfter(pattern);
- this.__position = start;
- return val;
- };
- InputScanner.prototype.lookBack = function(testVal) {
- var start = this.__position - 1;
- return start >= testVal.length && this.__input.substring(start - testVal.length, start)
- .toLowerCase() === testVal;
- };
- module.exports.InputScanner = InputScanner;
- }),
- (function(module, __unused_webpack_exports, __webpack_require__) {
- var InputScanner = (__webpack_require__(8).InputScanner);
- var Token = (__webpack_require__(3).Token);
- var TokenStream = (__webpack_require__(10).TokenStream);
- var WhitespacePattern = (__webpack_require__(11).WhitespacePattern);
- var TOKEN = {
- START: 'TK_START',
- RAW: 'TK_RAW',
- EOF: 'TK_EOF'
- };
- var Tokenizer = function(input_string, options) {
- this._input = new InputScanner(input_string);
- this._options = options || {};
- this.__tokens = null;
- this._patterns = {};
- this._patterns.whitespace = new WhitespacePattern(this._input);
- };
- Tokenizer.prototype.tokenize = function() {
- this._input.restart();
- this.__tokens = new TokenStream();
- this._reset();
- var current;
- var previous = new Token(TOKEN.START, '');
- var open_token = null;
- var open_stack = [];
- var comments = new TokenStream();
- while (previous.type !== TOKEN.EOF) {
- current = this._get_next_token(previous, open_token);
- while (this._is_comment(current)) {
- comments.add(current);
- current = this._get_next_token(previous, open_token);
- }
- if (!comments.isEmpty()) {
- current.comments_before = comments;
- comments = new TokenStream();
- }
- current.parent = open_token;
- if (this._is_opening(current)) {
- open_stack.push(open_token);
- open_token = current;
- } else if (open_token && this._is_closing(current, open_token)) {
- current.opened = open_token;
- open_token.closed = current;
- open_token = open_stack.pop();
- current.parent = open_token;
- }
- current.previous = previous;
- previous.next = current;
- this.__tokens.add(current);
- previous = current;
- }
- return this.__tokens;
- };
- Tokenizer.prototype._is_first_token = function() {
- return this.__tokens.isEmpty();
- };
- Tokenizer.prototype._reset = function() {};
- Tokenizer.prototype._get_next_token = function(previous_token, open_token) {
- this._readWhitespace();
- var resulting_string = this._input.read(/.+/g);
- if (resulting_string) {
- return this._create_token(TOKEN.RAW, resulting_string);
- } else {
- return this._create_token(TOKEN.EOF, '');
- }
- };
- Tokenizer.prototype._is_comment = function(current_token) {
- return false;
- };
- Tokenizer.prototype._is_opening = function(current_token) {
- return false;
- };
- Tokenizer.prototype._is_closing = function(current_token, open_token) {
- return false;
- };
- Tokenizer.prototype._create_token = function(type, text) {
- var token = new Token(type, text,
- this._patterns.whitespace.newline_count,
- this._patterns.whitespace.whitespace_before_token);
- return token;
- };
- Tokenizer.prototype._readWhitespace = function() {
- return this._patterns.whitespace.read();
- };
- module.exports.Tokenizer = Tokenizer;
- module.exports.TOKEN = TOKEN;
- }),
- (function(module) {
- function TokenStream(parent_token) {
-
- this.__tokens = [];
- this.__tokens_length = this.__tokens.length;
- this.__position = 0;
- this.__parent_token = parent_token;
- }
- TokenStream.prototype.restart = function() {
- this.__position = 0;
- };
- TokenStream.prototype.isEmpty = function() {
- return this.__tokens_length === 0;
- };
- TokenStream.prototype.hasNext = function() {
- return this.__position < this.__tokens_length;
- };
- TokenStream.prototype.next = function() {
- var val = null;
- if (this.hasNext()) {
- val = this.__tokens[this.__position];
- this.__position += 1;
- }
- return val;
- };
- TokenStream.prototype.peek = function(index) {
- var val = null;
- index = index || 0;
- index += this.__position;
- if (index >= 0 && index < this.__tokens_length) {
- val = this.__tokens[index];
- }
- return val;
- };
- TokenStream.prototype.add = function(token) {
- if (this.__parent_token) {
- token.parent = this.__parent_token;
- }
- this.__tokens.push(token);
- this.__tokens_length += 1;
- };
- module.exports.TokenStream = TokenStream;
- }),
- (function(module, __unused_webpack_exports, __webpack_require__) {
- var Pattern = (__webpack_require__(12).Pattern);
- function WhitespacePattern(input_scanner, parent) {
- Pattern.call(this, input_scanner, parent);
- if (parent) {
- this._line_regexp = this._input.get_regexp(parent._line_regexp);
- } else {
- this.__set_whitespace_patterns('', '');
- }
- this.newline_count = 0;
- this.whitespace_before_token = '';
- }
- WhitespacePattern.prototype = new Pattern();
- WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
- whitespace_chars += '\\t ';
- newline_chars += '\\n\\r';
- this._match_pattern = this._input.get_regexp(
- '[' + whitespace_chars + newline_chars + ']+', true);
- this._newline_regexp = this._input.get_regexp(
- '\\r\\n|[' + newline_chars + ']');
- };
- WhitespacePattern.prototype.read = function() {
- this.newline_count = 0;
- this.whitespace_before_token = '';
- var resulting_string = this._input.read(this._match_pattern);
- if (resulting_string === ' ') {
- this.whitespace_before_token = ' ';
- } else if (resulting_string) {
- var matches = this.__split(this._newline_regexp, resulting_string);
- this.newline_count = matches.length - 1;
- this.whitespace_before_token = matches[this.newline_count];
- }
- return resulting_string;
- };
- WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
- var result = this._create();
- result.__set_whitespace_patterns(whitespace_chars, newline_chars);
- result._update();
- return result;
- };
- WhitespacePattern.prototype._create = function() {
- return new WhitespacePattern(this._input, this);
- };
- WhitespacePattern.prototype.__split = function(regexp, input_string) {
- regexp.lastIndex = 0;
- var start_index = 0;
- var result = [];
- var next_match = regexp.exec(input_string);
- while (next_match) {
- result.push(input_string.substring(start_index, next_match.index));
- start_index = next_match.index + next_match[0].length;
- next_match = regexp.exec(input_string);
- }
- if (start_index < input_string.length) {
- result.push(input_string.substring(start_index, input_string.length));
- } else {
- result.push('');
- }
- return result;
- };
- module.exports.WhitespacePattern = WhitespacePattern;
- }),
- (function(module) {
- function Pattern(input_scanner, parent) {
- this._input = input_scanner;
- this._starting_pattern = null;
- this._match_pattern = null;
- this._until_pattern = null;
- this._until_after = false;
- if (parent) {
- this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
- this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
- this._until_pattern = this._input.get_regexp(parent._until_pattern);
- this._until_after = parent._until_after;
- }
- }
- Pattern.prototype.read = function() {
- var result = this._input.read(this._starting_pattern);
- if (!this._starting_pattern || result) {
- result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
- }
- return result;
- };
- Pattern.prototype.read_match = function() {
- return this._input.match(this._match_pattern);
- };
- Pattern.prototype.until_after = function(pattern) {
- var result = this._create();
- result._until_after = true;
- result._until_pattern = this._input.get_regexp(pattern);
- result._update();
- return result;
- };
- Pattern.prototype.until = function(pattern) {
- var result = this._create();
- result._until_after = false;
- result._until_pattern = this._input.get_regexp(pattern);
- result._update();
- return result;
- };
- Pattern.prototype.starting_with = function(pattern) {
- var result = this._create();
- result._starting_pattern = this._input.get_regexp(pattern, true);
- result._update();
- return result;
- };
- Pattern.prototype.matching = function(pattern) {
- var result = this._create();
- result._match_pattern = this._input.get_regexp(pattern, true);
- result._update();
- return result;
- };
- Pattern.prototype._create = function() {
- return new Pattern(this._input, this);
- };
- Pattern.prototype._update = function() {};
- module.exports.Pattern = Pattern;
- }),
- (function(module) {
- function Directives(start_block_pattern, end_block_pattern) {
- start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
- end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
- this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
- this.__directive_pattern = / (\w+)[:](\w+)/g;
- this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
- }
- Directives.prototype.get_directives = function(text) {
- if (!text.match(this.__directives_block_pattern)) {
- return null;
- }
- var directives = {};
- this.__directive_pattern.lastIndex = 0;
- var directive_match = this.__directive_pattern.exec(text);
- while (directive_match) {
- directives[directive_match[1]] = directive_match[2];
- directive_match = this.__directive_pattern.exec(text);
- }
- return directives;
- };
- Directives.prototype.readIgnored = function(input) {
- return input.readUntilAfter(this.__directives_end_ignore_pattern);
- };
- module.exports.Directives = Directives;
- }),
- (function(module, __unused_webpack_exports, __webpack_require__) {
- var Pattern = (__webpack_require__(12).Pattern);
- var template_names = {
- django: false,
- erb: false,
- handlebars: false,
- php: false,
- smarty: false
- };
- function TemplatablePattern(input_scanner, parent) {
- Pattern.call(this, input_scanner, parent);
- this.__template_pattern = null;
- this._disabled = Object.assign({}, template_names);
- this._excluded = Object.assign({}, template_names);
- if (parent) {
- this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
- this._excluded = Object.assign(this._excluded, parent._excluded);
- this._disabled = Object.assign(this._disabled, parent._disabled);
- }
- var pattern = new Pattern(input_scanner);
- this.__patterns = {
- handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
- handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
- handlebars: pattern.starting_with(/{{/).until_after(/}}/),
- php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
- erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
-
- django: pattern.starting_with(/{%/).until_after(/%}/),
- django_value: pattern.starting_with(/{{/).until_after(/}}/),
- django_comment: pattern.starting_with(/{#/).until_after(/#}/),
- smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
- smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
- smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
- };
- }
- TemplatablePattern.prototype = new Pattern();
- TemplatablePattern.prototype._create = function() {
- return new TemplatablePattern(this._input, this);
- };
- TemplatablePattern.prototype._update = function() {
- this.__set_templated_pattern();
- };
- TemplatablePattern.prototype.disable = function(language) {
- var result = this._create();
- result._disabled[language] = true;
- result._update();
- return result;
- };
- TemplatablePattern.prototype.read_options = function(options) {
- var result = this._create();
- for (var language in template_names) {
- result._disabled[language] = options.templating.indexOf(language) === -1;
- }
- result._update();
- return result;
- };
- TemplatablePattern.prototype.exclude = function(language) {
- var result = this._create();
- result._excluded[language] = true;
- result._update();
- return result;
- };
- TemplatablePattern.prototype.read = function() {
- var result = '';
- if (this._match_pattern) {
- result = this._input.read(this._starting_pattern);
- } else {
- result = this._input.read(this._starting_pattern, this.__template_pattern);
- }
- var next = this._read_template();
- while (next) {
- if (this._match_pattern) {
- next += this._input.read(this._match_pattern);
- } else {
- next += this._input.readUntil(this.__template_pattern);
- }
- result += next;
- next = this._read_template();
- }
- if (this._until_after) {
- result += this._input.readUntilAfter(this._until_pattern);
- }
- return result;
- };
- TemplatablePattern.prototype.__set_templated_pattern = function() {
- var items = [];
- if (!this._disabled.php) {
- items.push(this.__patterns.php._starting_pattern.source);
- }
- if (!this._disabled.handlebars) {
- items.push(this.__patterns.handlebars._starting_pattern.source);
- }
- if (!this._disabled.erb) {
- items.push(this.__patterns.erb._starting_pattern.source);
- }
- if (!this._disabled.django) {
- items.push(this.__patterns.django._starting_pattern.source);
-
-
- items.push(this.__patterns.django_value._starting_pattern.source);
- items.push(this.__patterns.django_comment._starting_pattern.source);
- }
- if (!this._disabled.smarty) {
- items.push(this.__patterns.smarty._starting_pattern.source);
- }
- if (this._until_pattern) {
- items.push(this._until_pattern.source);
- }
- this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
- };
- TemplatablePattern.prototype._read_template = function() {
- var resulting_string = '';
- var c = this._input.peek();
- if (c === '<') {
- var peek1 = this._input.peek(1);
-
-
-
- if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
- resulting_string = resulting_string ||
- this.__patterns.php.read();
- }
- if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
- resulting_string = resulting_string ||
- this.__patterns.erb.read();
- }
- } else if (c === '{') {
- if (!this._disabled.handlebars && !this._excluded.handlebars) {
- resulting_string = resulting_string ||
- this.__patterns.handlebars_comment.read();
- resulting_string = resulting_string ||
- this.__patterns.handlebars_unescaped.read();
- resulting_string = resulting_string ||
- this.__patterns.handlebars.read();
- }
- if (!this._disabled.django) {
-
- if (!this._excluded.django && !this._excluded.handlebars) {
- resulting_string = resulting_string ||
- this.__patterns.django_value.read();
- }
- if (!this._excluded.django) {
- resulting_string = resulting_string ||
- this.__patterns.django_comment.read();
- resulting_string = resulting_string ||
- this.__patterns.django.read();
- }
- }
- if (!this._disabled.smarty) {
-
- if (this._disabled.django && this._disabled.handlebars) {
- resulting_string = resulting_string ||
- this.__patterns.smarty_comment.read();
- resulting_string = resulting_string ||
- this.__patterns.smarty_literal.read();
- resulting_string = resulting_string ||
- this.__patterns.smarty.read();
- }
- }
- }
- return resulting_string;
- };
- module.exports.TemplatablePattern = TemplatablePattern;
- }),
- ,
- ,
- ,
- (function(module, __unused_webpack_exports, __webpack_require__) {
- var Beautifier = (__webpack_require__(19).Beautifier),
- Options = (__webpack_require__(20).Options);
- function style_html(html_source, options, js_beautify, css_beautify) {
- var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
- return beautifier.beautify();
- }
- module.exports = style_html;
- module.exports.defaultOptions = function() {
- return new Options();
- };
- }),
- (function(module, __unused_webpack_exports, __webpack_require__) {
- var Options = (__webpack_require__(20).Options);
- var Output = (__webpack_require__(2).Output);
- var Tokenizer = (__webpack_require__(21).Tokenizer);
- var TOKEN = (__webpack_require__(21).TOKEN);
- var lineBreak = /\r\n|[\r\n]/;
- var allLineBreaks = /\r\n|[\r\n]/g;
- var Printer = function(options, base_indent_string) {
- this.indent_level = 0;
- this.alignment_size = 0;
- this.max_preserve_newlines = options.max_preserve_newlines;
- this.preserve_newlines = options.preserve_newlines;
- this._output = new Output(options, base_indent_string);
- };
- Printer.prototype.current_line_has_match = function(pattern) {
- return this._output.current_line.has_match(pattern);
- };
- Printer.prototype.set_space_before_token = function(value, non_breaking) {
- this._output.space_before_token = value;
- this._output.non_breaking_space = non_breaking;
- };
- Printer.prototype.set_wrap_point = function() {
- this._output.set_indent(this.indent_level, this.alignment_size);
- this._output.set_wrap_point();
- };
- Printer.prototype.add_raw_token = function(token) {
- this._output.add_raw_token(token);
- };
- Printer.prototype.print_preserved_newlines = function(raw_token) {
- var newlines = 0;
- if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
- newlines = raw_token.newlines ? 1 : 0;
- }
- if (this.preserve_newlines) {
- newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
- }
- for (var n = 0; n < newlines; n++) {
- this.print_newline(n > 0);
- }
- return newlines !== 0;
- };
- Printer.prototype.traverse_whitespace = function(raw_token) {
- if (raw_token.whitespace_before || raw_token.newlines) {
- if (!this.print_preserved_newlines(raw_token)) {
- this._output.space_before_token = true;
- }
- return true;
- }
- return false;
- };
- Printer.prototype.previous_token_wrapped = function() {
- return this._output.previous_token_wrapped;
- };
- Printer.prototype.print_newline = function(force) {
- this._output.add_new_line(force);
- };
- Printer.prototype.print_token = function(token) {
- if (token.text) {
- this._output.set_indent(this.indent_level, this.alignment_size);
- this._output.add_token(token.text);
- }
- };
- Printer.prototype.indent = function() {
- this.indent_level++;
- };
- Printer.prototype.get_full_indent = function(level) {
- level = this.indent_level + (level || 0);
- if (level < 1) {
- return '';
- }
- return this._output.get_indent_string(level);
- };
- var get_type_attribute = function(start_token) {
- var result = null;
- var raw_token = start_token.next;
-
- while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
- if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
- if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
- raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
- result = raw_token.next.next.text;
- }
- break;
- }
- raw_token = raw_token.next;
- }
- return result;
- };
- var get_custom_beautifier_name = function(tag_check, raw_token) {
- var typeAttribute = null;
- var result = null;
- if (!raw_token.closed) {
- return null;
- }
- if (tag_check === 'script') {
- typeAttribute = 'text/javascript';
- } else if (tag_check === 'style') {
- typeAttribute = 'text/css';
- }
- typeAttribute = get_type_attribute(raw_token) || typeAttribute;
-
-
- if (typeAttribute.search('text/css') > -1) {
- result = 'css';
- } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
- result = 'javascript';
- } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
- result = 'html';
- } else if (typeAttribute.search(/test\/null/) > -1) {
-
- result = 'null';
- }
- return result;
- };
- function in_array(what, arr) {
- return arr.indexOf(what) !== -1;
- }
- function TagFrame(parent, parser_token, indent_level) {
- this.parent = parent || null;
- this.tag = parser_token ? parser_token.tag_name : '';
- this.indent_level = indent_level || 0;
- this.parser_token = parser_token || null;
- }
- function TagStack(printer) {
- this._printer = printer;
- this._current_frame = null;
- }
- TagStack.prototype.get_parser_token = function() {
- return this._current_frame ? this._current_frame.parser_token : null;
- };
- TagStack.prototype.record_tag = function(parser_token) {
- var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
- this._current_frame = new_frame;
- };
- TagStack.prototype._try_pop_frame = function(frame) {
- var parser_token = null;
- if (frame) {
- parser_token = frame.parser_token;
- this._printer.indent_level = frame.indent_level;
- this._current_frame = frame.parent;
- }
- return parser_token;
- };
- TagStack.prototype._get_frame = function(tag_list, stop_list) {
- var frame = this._current_frame;
- while (frame) {
- if (tag_list.indexOf(frame.tag) !== -1) {
- break;
- } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
- frame = null;
- break;
- }
- frame = frame.parent;
- }
- return frame;
- };
- TagStack.prototype.try_pop = function(tag, stop_list) {
- var frame = this._get_frame([tag], stop_list);
- return this._try_pop_frame(frame);
- };
- TagStack.prototype.indent_to_tag = function(tag_list) {
- var frame = this._get_frame(tag_list);
- if (frame) {
- this._printer.indent_level = frame.indent_level;
- }
- };
- function Beautifier(source_text, options, js_beautify, css_beautify) {
-
- this._source_text = source_text || '';
- options = options || {};
- this._js_beautify = js_beautify;
- this._css_beautify = css_beautify;
- this._tag_stack = null;
-
-
- var optionHtml = new Options(options, 'html');
- this._options = optionHtml;
- this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
- this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
- this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
- this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
- this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
- this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
- }
- Beautifier.prototype.beautify = function() {
-
- if (this._options.disabled) {
- return this._source_text;
- }
- var source_text = this._source_text;
- var eol = this._options.eol;
- if (this._options.eol === 'auto') {
- eol = '\n';
- if (source_text && lineBreak.test(source_text)) {
- eol = source_text.match(lineBreak)[0];
- }
- }
-
- source_text = source_text.replace(allLineBreaks, '\n');
- var baseIndentString = source_text.match(/^[\t ]*/)[0];
- var last_token = {
- text: '',
- type: ''
- };
- var last_tag_token = new TagOpenParserToken();
- var printer = new Printer(this._options, baseIndentString);
- var tokens = new Tokenizer(source_text, this._options).tokenize();
- this._tag_stack = new TagStack(printer);
- var parser_token = null;
- var raw_token = tokens.next();
- while (raw_token.type !== TOKEN.EOF) {
- if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
- parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token);
- last_tag_token = parser_token;
- } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
- (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
- parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, tokens);
- } else if (raw_token.type === TOKEN.TAG_CLOSE) {
- parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
- } else if (raw_token.type === TOKEN.TEXT) {
- parser_token = this._handle_text(printer, raw_token, last_tag_token);
- } else {
-
- printer.add_raw_token(raw_token);
- }
- last_token = parser_token;
- raw_token = tokens.next();
- }
- var sweet_code = printer._output.get_code(eol);
- return sweet_code;
- };
- Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
- var parser_token = {
- text: raw_token.text,
- type: raw_token.type
- };
- printer.alignment_size = 0;
- last_tag_token.tag_complete = true;
- printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
- if (last_tag_token.is_unformatted) {
- printer.add_raw_token(raw_token);
- } else {
- if (last_tag_token.tag_start_char === '<') {
- printer.set_space_before_token(raw_token.text[0] === '/', true);
- if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
- printer.print_newline(false);
- }
- }
- printer.print_token(raw_token);
- }
- if (last_tag_token.indent_content &&
- !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
- printer.indent();
-
- last_tag_token.indent_content = false;
- }
- if (!last_tag_token.is_inline_element &&
- !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
- printer.set_wrap_point();
- }
- return parser_token;
- };
- Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
- var wrapped = last_tag_token.has_wrapped_attrs;
- var parser_token = {
- text: raw_token.text,
- type: raw_token.type
- };
- printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
- if (last_tag_token.is_unformatted) {
- printer.add_raw_token(raw_token);
- } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
-
- if (printer.print_preserved_newlines(raw_token)) {
- raw_token.newlines = 0;
- printer.add_raw_token(raw_token);
- } else {
- printer.print_token(raw_token);
- }
- } else {
- if (raw_token.type === TOKEN.ATTRIBUTE) {
- printer.set_space_before_token(true);
- last_tag_token.attr_count += 1;
- } else if (raw_token.type === TOKEN.EQUALS) {
- printer.set_space_before_token(false);
- } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) {
- printer.set_space_before_token(false);
- }
- if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
- if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
- printer.traverse_whitespace(raw_token);
- wrapped = wrapped || raw_token.newlines !== 0;
- }
- if (this._is_wrap_attributes_force) {
- var force_attr_wrap = last_tag_token.attr_count > 1;
- if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
- var is_only_attribute = true;
- var peek_index = 0;
- var peek_token;
- do {
- peek_token = tokens.peek(peek_index);
- if (peek_token.type === TOKEN.ATTRIBUTE) {
- is_only_attribute = false;
- break;
- }
- peek_index += 1;
- } while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
- force_attr_wrap = !is_only_attribute;
- }
- if (force_attr_wrap) {
- printer.print_newline(false);
- wrapped = true;
- }
- }
- }
- printer.print_token(raw_token);
- wrapped = wrapped || printer.previous_token_wrapped();
- last_tag_token.has_wrapped_attrs = wrapped;
- }
- return parser_token;
- };
- Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
- var parser_token = {
- text: raw_token.text,
- type: 'TK_CONTENT'
- };
- if (last_tag_token.custom_beautifier_name) {
- this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
- } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
- printer.add_raw_token(raw_token);
- } else {
- printer.traverse_whitespace(raw_token);
- printer.print_token(raw_token);
- }
- return parser_token;
- };
- Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
- var local = this;
- if (raw_token.text !== '') {
- var text = raw_token.text,
- _beautifier,
- script_indent_level = 1,
- pre = '',
- post = '';
- if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
- _beautifier = this._js_beautify;
- } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
- _beautifier = this._css_beautify;
- } else if (last_tag_token.custom_beautifier_name === 'html') {
- _beautifier = function(html_source, options) {
- var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
- return beautifier.beautify();
- };
- }
- if (this._options.indent_scripts === "keep") {
- script_indent_level = 0;
- } else if (this._options.indent_scripts === "separate") {
- script_indent_level = -printer.indent_level;
- }
- var indentation = printer.get_full_indent(script_indent_level);
-
-
- text = text.replace(/\n[ \t]*$/, '');
-
- if (last_tag_token.custom_beautifier_name !== 'html' &&
- text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
- var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
-
- if (!matched) {
- printer.add_raw_token(raw_token);
- return;
- }
- pre = indentation + matched[1] + '\n';
- text = matched[4];
- if (matched[5]) {
- post = indentation + matched[5];
- }
-
-
- text = text.replace(/\n[ \t]*$/, '');
- if (matched[2] || matched[3].indexOf('\n') !== -1) {
-
-
- matched = matched[3].match(/[ \t]+$/);
- if (matched) {
- raw_token.whitespace_before = matched[0];
- }
- }
- }
- if (text) {
- if (_beautifier) {
-
- var Child_options = function() {
- this.eol = '\n';
- };
- Child_options.prototype = this._options.raw_options;
- var child_options = new Child_options();
- text = _beautifier(indentation + text, child_options);
- } else {
-
- var white = raw_token.whitespace_before;
- if (white) {
- text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
- }
- text = indentation + text.replace(/\n/g, '\n' + indentation);
- }
- }
- if (pre) {
- if (!text) {
- text = pre + post;
- } else {
- text = pre + text + '\n' + post;
- }
- }
- printer.print_newline(false);
- if (text) {
- raw_token.text = text;
- raw_token.whitespace_before = '';
- raw_token.newlines = 0;
- printer.add_raw_token(raw_token);
- printer.print_newline(true);
- }
- }
- };
- Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
- var parser_token = this._get_tag_open_token(raw_token);
- if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
- !last_tag_token.is_empty_element &&
- raw_token.type === TOKEN.TAG_OPEN && raw_token.text.indexOf('</') === 0) {
-
-
- printer.add_raw_token(raw_token);
- parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
- } else {
- printer.traverse_whitespace(raw_token);
- this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
- if (!parser_token.is_inline_element) {
- printer.set_wrap_point();
- }
- printer.print_token(raw_token);
- }
-
- if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
- parser_token.alignment_size = raw_token.text.length + 1;
- }
- if (!parser_token.tag_complete && !parser_token.is_unformatted) {
- printer.alignment_size = parser_token.alignment_size;
- }
- return parser_token;
- };
- var TagOpenParserToken = function(parent, raw_token) {
- this.parent = parent || null;
- this.text = '';
- this.type = 'TK_TAG_OPEN';
- this.tag_name = '';
- this.is_inline_element = false;
- this.is_unformatted = false;
- this.is_content_unformatted = false;
- this.is_empty_element = false;
- this.is_start_tag = false;
- this.is_end_tag = false;
- this.indent_content = false;
- this.multiline_content = false;
- this.custom_beautifier_name = null;
- this.start_tag_token = null;
- this.attr_count = 0;
- this.has_wrapped_attrs = false;
- this.alignment_size = 0;
- this.tag_complete = false;
- this.tag_start_char = '';
- this.tag_check = '';
- if (!raw_token) {
- this.tag_complete = true;
- } else {
- var tag_check_match;
- this.tag_start_char = raw_token.text[0];
- this.text = raw_token.text;
- if (this.tag_start_char === '<') {
- tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
- this.tag_check = tag_check_match ? tag_check_match[1] : '';
- } else {
- tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
- this.tag_check = tag_check_match ? tag_check_match[1] : '';
-
- if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
- this.tag_check = raw_token.next.text.split(' ')[0];
- }
- }
- this.tag_check = this.tag_check.toLowerCase();
- if (raw_token.type === TOKEN.COMMENT) {
- this.tag_complete = true;
- }
- this.is_start_tag = this.tag_check.charAt(0) !== '/';
- this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
- this.is_end_tag = !this.is_start_tag ||
- (raw_token.closed && raw_token.closed.text === '/>');
-
- this.is_end_tag = this.is_end_tag ||
- (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(2)))));
- }
- };
- Beautifier.prototype._get_tag_open_token = function(raw_token) {
- var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
- parser_token.alignment_size = this._options.wrap_attributes_indent_size;
- parser_token.is_end_tag = parser_token.is_end_tag ||
- in_array(parser_token.tag_check, this._options.void_elements);
- parser_token.is_empty_element = parser_token.tag_complete ||
- (parser_token.is_start_tag && parser_token.is_end_tag);
- parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
- parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
- parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_start_char === '{';
- return parser_token;
- };
- Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
- if (!parser_token.is_empty_element) {
- if (parser_token.is_end_tag) {
- parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
- } else {
-
-
- if (this._do_optional_end_element(parser_token)) {
- if (!parser_token.is_inline_element) {
- printer.print_newline(false);
- }
- }
- this._tag_stack.record_tag(parser_token);
- if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
- !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
- parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
- }
- }
- }
- if (in_array(parser_token.tag_check, this._options.extra_liners)) {
- printer.print_newline(false);
- if (!printer._output.just_added_blankline()) {
- printer.print_newline(true);
- }
- }
- if (parser_token.is_empty_element) {
-
-
- if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
- this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
- parser_token.indent_content = true;
-
- var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
- if (!foundIfOnCurrentLine) {
- printer.print_newline(false);
- }
- }
-
- if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
- last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) {
-
- } else {
- if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
- printer.print_newline(false);
- }
- this._calcluate_parent_multiline(printer, parser_token);
- }
- } else if (parser_token.is_end_tag) {
- var do_end_expand = false;
-
- do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
- do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
- !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
- !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
- last_token.type !== 'TK_CONTENT'
- );
- if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
- do_end_expand = false;
- }
- if (do_end_expand) {
- printer.print_newline(false);
- }
- } else {
- parser_token.indent_content = !parser_token.custom_beautifier_name;
- if (parser_token.tag_start_char === '<') {
- if (parser_token.tag_name === 'html') {
- parser_token.indent_content = this._options.indent_inner_html;
- } else if (parser_token.tag_name === 'head') {
- parser_token.indent_content = this._options.indent_head_inner_html;
- } else if (parser_token.tag_name === 'body') {
- parser_token.indent_content = this._options.indent_body_inner_html;
- }
- }
- if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
- (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
- printer.print_newline(false);
- }
- this._calcluate_parent_multiline(printer, parser_token);
- }
- };
- Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
- if (parser_token.parent && printer._output.just_added_newline() &&
- !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
- parser_token.parent.multiline_content = true;
- }
- };
- 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'];
- var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
- Beautifier.prototype._do_optional_end_element = function(parser_token) {
- var result = null;
-
-
-
-
- if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
- return;
- }
- if (parser_token.tag_name === 'body') {
-
- result = result || this._tag_stack.try_pop('head');
-
-
- } else if (parser_token.tag_name === 'li') {
-
- result = result || this._tag_stack.try_pop('li', ['ol', 'ul']);
- } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
-
-
- result = result || this._tag_stack.try_pop('dt', ['dl']);
- result = result || this._tag_stack.try_pop('dd', ['dl']);
- } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
-
-
-
-
- var p_parent = parser_token.parent.parent;
- if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
- result = result || this._tag_stack.try_pop('p');
- }
- } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
-
-
- result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
- result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
- } else if (parser_token.tag_name === 'optgroup') {
-
-
- result = result || this._tag_stack.try_pop('optgroup', ['select']);
-
- } else if (parser_token.tag_name === 'option') {
-
- result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
- } else if (parser_token.tag_name === 'colgroup') {
-
-
- result = result || this._tag_stack.try_pop('caption', ['table']);
- } else if (parser_token.tag_name === 'thead') {
-
-
- result = result || this._tag_stack.try_pop('caption', ['table']);
- result = result || this._tag_stack.try_pop('colgroup', ['table']);
-
-
- } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
-
-
-
-
- result = result || this._tag_stack.try_pop('caption', ['table']);
- result = result || this._tag_stack.try_pop('colgroup', ['table']);
- result = result || this._tag_stack.try_pop('thead', ['table']);
- result = result || this._tag_stack.try_pop('tbody', ['table']);
-
-
- } else if (parser_token.tag_name === 'tr') {
-
-
-
- result = result || this._tag_stack.try_pop('caption', ['table']);
- result = result || this._tag_stack.try_pop('colgroup', ['table']);
- result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
- } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
-
-
- result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
- result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
- }
-
-
-
-
-
- parser_token.parent = this._tag_stack.get_parser_token();
- return result;
- };
- module.exports.Beautifier = Beautifier;
- }),
- (function(module, __unused_webpack_exports, __webpack_require__) {
- var BaseOptions = (__webpack_require__(6).Options);
- function Options(options) {
- BaseOptions.call(this, options, 'html');
- if (this.templating.length === 1 && this.templating[0] === 'auto') {
- this.templating = ['django', 'erb', 'handlebars', 'php'];
- }
- this.indent_inner_html = this._get_boolean('indent_inner_html');
- this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
- this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
- this.indent_handlebars = this._get_boolean('indent_handlebars', true);
- this.wrap_attributes = this._get_selection('wrap_attributes',
- ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
- this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
- this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
-
-
-
-
- this.inline = this._get_array('inline', [
- 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
- 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
- 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
- 'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', 'select', 'small',
- 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
- 'video', 'wbr', 'text',
-
- 'acronym', 'big', 'strike', 'tt'
- ]);
- this.void_elements = this._get_array('void_elements', [
-
-
- 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
- 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
-
-
-
- '!doctype', '?xml',
-
-
-
- 'basefont', 'isindex'
- ]);
- this.unformatted = this._get_array('unformatted', []);
- this.content_unformatted = this._get_array('content_unformatted', [
- 'pre', 'textarea'
- ]);
- this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
- this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
- }
- Options.prototype = new BaseOptions();
- module.exports.Options = Options;
- }),
- (function(module, __unused_webpack_exports, __webpack_require__) {
- var BaseTokenizer = (__webpack_require__(9).Tokenizer);
- var BASETOKEN = (__webpack_require__(9).TOKEN);
- var Directives = (__webpack_require__(13).Directives);
- var TemplatablePattern = (__webpack_require__(14).TemplatablePattern);
- var Pattern = (__webpack_require__(12).Pattern);
- var TOKEN = {
- TAG_OPEN: 'TK_TAG_OPEN',
- TAG_CLOSE: 'TK_TAG_CLOSE',
- ATTRIBUTE: 'TK_ATTRIBUTE',
- EQUALS: 'TK_EQUALS',
- VALUE: 'TK_VALUE',
- COMMENT: 'TK_COMMENT',
- TEXT: 'TK_TEXT',
- UNKNOWN: 'TK_UNKNOWN',
- START: BASETOKEN.START,
- RAW: BASETOKEN.RAW,
- EOF: BASETOKEN.EOF
- };
- var directives_core = new Directives(/<\!--/, /-->/);
- var Tokenizer = function(input_string, options) {
- BaseTokenizer.call(this, input_string, options);
- this._current_tag_name = '';
- // Words end at whitespace or when a tag starts
- // if we are indenting handlebars, they are considered tags
- var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
- var pattern_reader = new Pattern(this._input);
- this.__patterns = {
- word: templatable_reader.until(/[\n\r\t <]/),
- single_quote: templatable_reader.until_after(/'/),
- double_quote: templatable_reader.until_after(/"/),
- attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
- element_name: templatable_reader.until(/[\n\r\t >\/]/),
- handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
- handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
- handlebars_open: pattern_reader.until(/[\n\r\t }]/),
- handlebars_raw_close: pattern_reader.until(/}}/),
- comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
- cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
-
- conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
- processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
- };
- if (this._options.indent_handlebars) {
- this.__patterns.word = this.__patterns.word.exclude('handlebars');
- }
- this._unformatted_content_delimiter = null;
- if (this._options.unformatted_content_delimiter) {
- var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
- this.__patterns.unformatted_content_delimiter =
- pattern_reader.matching(literal_regexp)
- .until_after(literal_regexp);
- }
- };
- Tokenizer.prototype = new BaseTokenizer();
- Tokenizer.prototype._is_comment = function(current_token) {
- return false;
- };
- Tokenizer.prototype._is_opening = function(current_token) {
- return current_token.type === TOKEN.TAG_OPEN;
- };
- Tokenizer.prototype._is_closing = function(current_token, open_token) {
- return current_token.type === TOKEN.TAG_CLOSE &&
- (open_token && (
- ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
- (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
- };
- Tokenizer.prototype._reset = function() {
- this._current_tag_name = '';
- };
- Tokenizer.prototype._get_next_token = function(previous_token, open_token) {
- var token = null;
- this._readWhitespace();
- var c = this._input.peek();
- if (c === null) {
- return this._create_token(TOKEN.EOF, '');
- }
- token = token || this._read_open_handlebars(c, open_token);
- token = token || this._read_attribute(c, previous_token, open_token);
- token = token || this._read_close(c, open_token);
- token = token || this._read_raw_content(c, previous_token, open_token);
- token = token || this._read_content_word(c);
- token = token || this._read_comment_or_cdata(c);
- token = token || this._read_processing(c);
- token = token || this._read_open(c, open_token);
- token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
- return token;
- };
- Tokenizer.prototype._read_comment_or_cdata = function(c) {
- var token = null;
- var resulting_string = null;
- var directives = null;
- if (c === '<') {
- var peek1 = this._input.peek(1);
-
-
- if (peek1 === '!') {
- resulting_string = this.__patterns.comment.read();
-
- if (resulting_string) {
- directives = directives_core.get_directives(resulting_string);
- if (directives && directives.ignore === 'start') {
- resulting_string += directives_core.readIgnored(this._input);
- }
- } else {
- resulting_string = this.__patterns.cdata.read();
- }
- }
- if (resulting_string) {
- token = this._create_token(TOKEN.COMMENT, resulting_string);
- token.directives = directives;
- }
- }
- return token;
- };
- Tokenizer.prototype._read_processing = function(c) {
- var token = null;
- var resulting_string = null;
- var directives = null;
- if (c === '<') {
- var peek1 = this._input.peek(1);
- if (peek1 === '!' || peek1 === '?') {
- resulting_string = this.__patterns.conditional_comment.read();
- resulting_string = resulting_string || this.__patterns.processing.read();
- }
- if (resulting_string) {
- token = this._create_token(TOKEN.COMMENT, resulting_string);
- token.directives = directives;
- }
- }
- return token;
- };
- Tokenizer.prototype._read_open = function(c, open_token) {
- var resulting_string = null;
- var token = null;
- if (!open_token) {
- if (c === '<') {
- resulting_string = this._input.next();
- if (this._input.peek() === '/') {
- resulting_string += this._input.next();
- }
- resulting_string += this.__patterns.element_name.read();
- token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
- }
- }
- return token;
- };
- Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
- var resulting_string = null;
- var token = null;
- if (!open_token) {
- if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
- if (this._input.peek(2) === '!') {
- resulting_string = this.__patterns.handlebars_comment.read();
- resulting_string = resulting_string || this.__patterns.handlebars.read();
- token = this._create_token(TOKEN.COMMENT, resulting_string);
- } else {
- resulting_string = this.__patterns.handlebars_open.read();
- token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
- }
- }
- }
- return token;
- };
- Tokenizer.prototype._read_close = function(c, open_token) {
- var resulting_string = null;
- var token = null;
- if (open_token) {
- if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
- resulting_string = this._input.next();
- if (c === '/') {
- resulting_string += this._input.next();
- }
- token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
- } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
- this._input.next();
- this._input.next();
- token = this._create_token(TOKEN.TAG_CLOSE, '}}');
- }
- }
- return token;
- };
- Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
- var token = null;
- var resulting_string = '';
- if (open_token && open_token.text[0] === '<') {
- if (c === '=') {
- token = this._create_token(TOKEN.EQUALS, this._input.next());
- } else if (c === '"' || c === "'") {
- var content = this._input.next();
- if (c === '"') {
- content += this.__patterns.double_quote.read();
- } else {
- content += this.__patterns.single_quote.read();
- }
- token = this._create_token(TOKEN.VALUE, content);
- } else {
- resulting_string = this.__patterns.attribute.read();
- if (resulting_string) {
- if (previous_token.type === TOKEN.EQUALS) {
- token = this._create_token(TOKEN.VALUE, resulting_string);
- } else {
- token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
- }
- }
- }
- }
- return token;
- };
- Tokenizer.prototype._is_content_unformatted = function(tag_name) {
-
-
-
- return this._options.void_elements.indexOf(tag_name) === -1 &&
- (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
- this._options.unformatted.indexOf(tag_name) !== -1);
- };
- Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) {
- var resulting_string = '';
- if (open_token && open_token.text[0] === '{') {
- resulting_string = this.__patterns.handlebars_raw_close.read();
- } else if (previous_token.type === TOKEN.TAG_CLOSE &&
- previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
-
- var tag_name = previous_token.opened.text.substr(1).toLowerCase();
- if (tag_name === 'script' || tag_name === 'style') {
-
-
- var token = this._read_comment_or_cdata(c);
- if (token) {
- token.type = TOKEN.TEXT;
- return token;
- }
- resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
- } else if (this._is_content_unformatted(tag_name)) {
- resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
- }
- }
- if (resulting_string) {
- return this._create_token(TOKEN.TEXT, resulting_string);
- }
- return null;
- };
- Tokenizer.prototype._read_content_word = function(c) {
- var resulting_string = '';
- if (this._options.unformatted_content_delimiter) {
- if (c === this._options.unformatted_content_delimiter[0]) {
- resulting_string = this.__patterns.unformatted_content_delimiter.read();
- }
- }
- if (!resulting_string) {
- resulting_string = this.__patterns.word.read();
- }
- if (resulting_string) {
- return this._create_token(TOKEN.TEXT, resulting_string);
- }
- };
- module.exports.Tokenizer = Tokenizer;
- module.exports.TOKEN = TOKEN;
- })
- ]);
-
- var __webpack_module_cache__ = {};
-
-
- function __webpack_require__(moduleId) {
-
- var cachedModule = __webpack_module_cache__[moduleId];
- if (cachedModule !== undefined) {
- return cachedModule.exports;
- }
-
- var module = __webpack_module_cache__[moduleId] = {
-
-
- exports: {}
- };
-
-
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
-
-
- return module.exports;
- }
-
-
-
-
-
- var __webpack_exports__ = __webpack_require__(18);
- legacy_beautify_html = __webpack_exports__;
-
- })()
- ;
- var style_html = legacy_beautify_html;
- if (typeof define === "function" && define.amd) {
-
- define(["require", "./beautify", "./beautify-css"], function(requireamd) {
- var js_beautify = requireamd("./beautify");
- var css_beautify = requireamd("./beautify-css");
- return {
- html_beautify: function(html_source, options) {
- return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
- }
- };
- });
- } else if (typeof exports !== "undefined") {
-
-
- var js_beautify = require('./beautify.js');
- var css_beautify = require('./beautify-css.js');
- exports.html_beautify = function(html_source, options) {
- return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
- };
- } else if (typeof window !== "undefined") {
-
- window.html_beautify = function(html_source, options) {
- return style_html(html_source, options, window.js_beautify, window.css_beautify);
- };
- } else if (typeof global !== "undefined") {
-
- global.html_beautify = function(html_source, options) {
- return style_html(html_source, options, global.js_beautify, global.css_beautify);
- };
- }
- }());
|