beautifyhtml.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
  2. /*
  3. The MIT License (MIT)
  4. Copyright (c) 2007-2013 Einar Lielmanis 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, <elfz@laacz.lv>
  26. http://jsbeautifier.org/
  27. Usage:
  28. html_beautify($copy.html());
  29. style_html(html_source);
  30. style_html(html_source, options);
  31. The options are:
  32. indent_size (default 4) — indentation size,
  33. indent_char (default space) — character to indent with,
  34. max_char (default 250) - maximum amount of characters per line (0 = disable)
  35. brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
  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.
  37. unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted
  38. indent_scripts (default normal) - "keep"|"separate"|"normal"
  39. e.g.
  40. style_html(html_source, {
  41. 'indent_size': 2,
  42. 'indent_char': ' ',
  43. 'max_char': 78,
  44. 'brace_style': 'expand',
  45. 'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u']
  46. });
  47. 使用方法html_beautify($("#divID").html());
  48. */
  49. (function() {
  50. function style_html(html_source, options, js_beautify, css_beautify) {
  51. //Wrapper function to invoke all the necessary constructors and deal with the output.
  52. var multi_parser,
  53. indent_size,
  54. indent_character,
  55. max_char,
  56. brace_style,
  57. unformatted;
  58. options = options || {};
  59. indent_size = options.indent_size || 4;
  60. indent_character = options.indent_char || ' ';
  61. brace_style = options.brace_style || 'collapse';
  62. max_char = options.max_char === 0 ? Infinity : options.max_char || 250;
  63. unformatted = options.unformatted || ['a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
  64. function Parser() {
  65. this.pos = 0; //Parser position
  66. this.token = '';
  67. this.current_mode = 'CONTENT'; //reflects the current Parser mode: TAG/CONTENT
  68. this.tags = { //An object to hold tags, their position, and their parent-tags, initiated with default values
  69. parent: 'parent1',
  70. parentcount: 1,
  71. parent1: ''
  72. };
  73. this.tag_type = '';
  74. this.token_text = this.last_token = this.last_text = this.token_type = '';
  75. this.Utils = { //Uilities made available to the various functions
  76. whitespace: "\n\r\t ".split(''),
  77. single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed,?php,?,?='.split(','), //all the single tags for HTML
  78. extra_liners: 'head,body,/html'.split(','), //for tags that need a line of whitespace before them
  79. in_array: function (what, arr) {
  80. for (var i=0; i<arr.length; i++) {
  81. if (what === arr[i]) {
  82. return true;
  83. }
  84. }
  85. return false;
  86. }
  87. };
  88. this.get_content = function () { //function to capture regular content between tags
  89. var input_char = '',
  90. content = [],
  91. space = false; //if a space is needed
  92. while (this.input.charAt(this.pos) !== '<') {
  93. if (this.pos >= this.input.length) {
  94. return content.length?content.join(''):['', 'TK_EOF'];
  95. }
  96. input_char = this.input.charAt(this.pos);
  97. this.pos++;
  98. this.line_char_count++;
  99. if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
  100. if (content.length) {
  101. space = true;
  102. }
  103. this.line_char_count--;
  104. continue; //don't want to insert unnecessary space
  105. }
  106. else if (space) {
  107. if (this.line_char_count >= this.max_char) { //insert a line when the max_char is reached
  108. content.push('\n');
  109. for (var i=0; i<this.indent_level; i++) {
  110. content.push(this.indent_string);
  111. }
  112. this.line_char_count = 0;
  113. }
  114. else{
  115. content.push(' ');
  116. this.line_char_count++;
  117. }
  118. space = false;
  119. }
  120. content.push(input_char); //letter at-a-time (or string) inserted to an array
  121. }
  122. return content.length?content.join(''):'';
  123. };
  124. this.get_contents_to = function (name) { //get the full content of a script or style to pass to js_beautify
  125. if (this.pos === this.input.length) {
  126. return ['', 'TK_EOF'];
  127. }
  128. var input_char = '';
  129. var content = '';
  130. var reg_match = new RegExp('</' + name + '\\s*>', 'igm');
  131. reg_match.lastIndex = this.pos;
  132. var reg_array = reg_match.exec(this.input);
  133. var end_script = reg_array?reg_array.index:this.input.length; //absolute end of script
  134. if(this.pos < end_script) { //get everything in between the script tags
  135. content = this.input.substring(this.pos, end_script);
  136. this.pos = end_script;
  137. }
  138. return content;
  139. };
  140. this.record_tag = function (tag){ //function to record a tag and its parent in this.tags Object
  141. if (this.tags[tag + 'count']) { //check for the existence of this tag type
  142. this.tags[tag + 'count']++;
  143. this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
  144. }
  145. else { //otherwise initialize this tag type
  146. this.tags[tag + 'count'] = 1;
  147. this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
  148. }
  149. this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent; //set the parent (i.e. in the case of a div this.tags.div1parent)
  150. this.tags.parent = tag + this.tags[tag + 'count']; //and make this the current parent (i.e. in the case of a div 'div1')
  151. };
  152. this.retrieve_tag = function (tag) { //function to retrieve the opening tag to the corresponding closer
  153. if (this.tags[tag + 'count']) { //if the openener is not in the Object we ignore it
  154. var temp_parent = this.tags.parent; //check to see if it's a closable tag.
  155. while (temp_parent) { //till we reach '' (the initial value);
  156. if (tag + this.tags[tag + 'count'] === temp_parent) { //if this is it use it
  157. break;
  158. }
  159. temp_parent = this.tags[temp_parent + 'parent']; //otherwise keep on climbing up the DOM Tree
  160. }
  161. if (temp_parent) { //if we caught something
  162. this.indent_level = this.tags[tag + this.tags[tag + 'count']]; //set the indent_level accordingly
  163. this.tags.parent = this.tags[temp_parent + 'parent']; //and set the current parent
  164. }
  165. delete this.tags[tag + this.tags[tag + 'count'] + 'parent']; //delete the closed tags parent reference...
  166. delete this.tags[tag + this.tags[tag + 'count']]; //...and the tag itself
  167. if (this.tags[tag + 'count'] === 1) {
  168. delete this.tags[tag + 'count'];
  169. }
  170. else {
  171. this.tags[tag + 'count']--;
  172. }
  173. }
  174. };
  175. this.get_tag = function (peek) { //function to get a full tag and parse its type
  176. var input_char = '',
  177. content = [],
  178. comment = '',
  179. space = false,
  180. tag_start, tag_end,
  181. orig_pos = this.pos,
  182. orig_line_char_count = this.line_char_count;
  183. peek = peek !== undefined ? peek : false;
  184. do {
  185. if (this.pos >= this.input.length) {
  186. if (peek) {
  187. this.pos = orig_pos;
  188. this.line_char_count = orig_line_char_count;
  189. }
  190. return content.length?content.join(''):['', 'TK_EOF'];
  191. }
  192. input_char = this.input.charAt(this.pos);
  193. this.pos++;
  194. this.line_char_count++;
  195. if (this.Utils.in_array(input_char, this.Utils.whitespace)) { //don't want to insert unnecessary space
  196. space = true;
  197. this.line_char_count--;
  198. continue;
  199. }
  200. if (input_char === "'" || input_char === '"') {
  201. if (!content[1] || content[1] !== '!') { //if we're in a comment strings don't get treated specially
  202. input_char += this.get_unformatted(input_char);
  203. space = true;
  204. }
  205. }
  206. if (input_char === '=') { //no space before =
  207. space = false;
  208. }
  209. if (content.length && content[content.length-1] !== '=' && input_char !== '>' && space) {
  210. //no space after = or before >
  211. if (this.line_char_count >= this.max_char) {
  212. this.print_newline(false, content);
  213. this.line_char_count = 0;
  214. }
  215. else {
  216. content.push(' ');
  217. this.line_char_count++;
  218. }
  219. space = false;
  220. }
  221. if (input_char === '<') {
  222. tag_start = this.pos - 1;
  223. }
  224. content.push(input_char); //inserts character at-a-time (or string)
  225. } while (input_char !== '>');
  226. var tag_complete = content.join('');
  227. var tag_index;
  228. if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
  229. tag_index = tag_complete.indexOf(' ');
  230. }
  231. else { //otherwise go with the tag ending
  232. tag_index = tag_complete.indexOf('>');
  233. }
  234. var tag_check = tag_complete.substring(1, tag_index).toLowerCase();
  235. if (tag_complete.charAt(tag_complete.length-2) === '/' ||
  236. this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /)
  237. if ( ! peek) {
  238. this.tag_type = 'SINGLE';
  239. }
  240. }
  241. else if (tag_check === 'script') { //for later script handling
  242. if ( ! peek) {
  243. this.record_tag(tag_check);
  244. this.tag_type = 'SCRIPT';
  245. }
  246. }
  247. else if (tag_check === 'style') { //for future style handling (for now it justs uses get_content)
  248. if ( ! peek) {
  249. this.record_tag(tag_check);
  250. this.tag_type = 'STYLE';
  251. }
  252. }
  253. else if (this.is_unformatted(tag_check, unformatted)) { // do not reformat the "unformatted" tags
  254. comment = this.get_unformatted('</'+tag_check+'>', tag_complete); //...delegate to get_unformatted function
  255. content.push(comment);
  256. // Preserve collapsed whitespace either before or after this tag.
  257. if (tag_start > 0 && this.Utils.in_array(this.input.charAt(tag_start - 1), this.Utils.whitespace)){
  258. content.splice(0, 0, this.input.charAt(tag_start - 1));
  259. }
  260. tag_end = this.pos - 1;
  261. if (this.Utils.in_array(this.input.charAt(tag_end + 1), this.Utils.whitespace)){
  262. content.push(this.input.charAt(tag_end + 1));
  263. }
  264. this.tag_type = 'SINGLE';
  265. }
  266. else if (tag_check.charAt(0) === '!') { //peek for <!-- comment
  267. if (tag_check.indexOf('[if') !== -1) { //peek for <!--[if conditional comment
  268. if (tag_complete.indexOf('!IE') !== -1) { //this type needs a closing --> so...
  269. comment = this.get_unformatted('-->', tag_complete); //...delegate to get_unformatted
  270. content.push(comment);
  271. }
  272. if ( ! peek) {
  273. this.tag_type = 'START';
  274. }
  275. }
  276. else if (tag_check.indexOf('[endif') !== -1) {//peek for <!--[endif end conditional comment
  277. this.tag_type = 'END';
  278. this.unindent();
  279. }
  280. else if (tag_check.indexOf('[cdata[') !== -1) { //if it's a <[cdata[ comment...
  281. comment = this.get_unformatted(']]>', tag_complete); //...delegate to get_unformatted function
  282. content.push(comment);
  283. if ( ! peek) {
  284. this.tag_type = 'SINGLE'; //<![CDATA[ comments are treated like single tags
  285. }
  286. }
  287. else {
  288. comment = this.get_unformatted('-->', tag_complete);
  289. content.push(comment);
  290. this.tag_type = 'SINGLE';
  291. }
  292. }
  293. else if ( ! peek) {
  294. if (tag_check.charAt(0) === '/') { //this tag is a double tag so check for tag-ending
  295. this.retrieve_tag(tag_check.substring(1)); //remove it and all ancestors
  296. this.tag_type = 'END';
  297. }
  298. else { //otherwise it's a start-tag
  299. this.record_tag(tag_check); //push it on the tag stack
  300. this.tag_type = 'START';
  301. }
  302. if (this.Utils.in_array(tag_check, this.Utils.extra_liners)) { //check if this double needs an extra line
  303. this.print_newline(true, this.output);
  304. }
  305. }
  306. if (peek) {
  307. this.pos = orig_pos;
  308. this.line_char_count = orig_line_char_count;
  309. }
  310. return content.join(''); //returns fully formatted tag
  311. };
  312. this.get_unformatted = function (delimiter, orig_tag) { //function to return unformatted content in its entirety
  313. if (orig_tag && orig_tag.toLowerCase().indexOf(delimiter) !== -1) {
  314. return '';
  315. }
  316. var input_char = '';
  317. var content = '';
  318. var space = true;
  319. do {
  320. if (this.pos >= this.input.length) {
  321. return content;
  322. }
  323. input_char = this.input.charAt(this.pos);
  324. this.pos++;
  325. if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
  326. if (!space) {
  327. this.line_char_count--;
  328. continue;
  329. }
  330. if (input_char === '\n' || input_char === '\r') {
  331. content += '\n';
  332. /* Don't change tab indention for unformatted blocks. If using code for html editing, this will greatly affect <pre> tags if they are specified in the 'unformatted array'
  333. for (var i=0; i<this.indent_level; i++) {
  334. content += this.indent_string;
  335. }
  336. space = false; //...and make sure other indentation is erased
  337. */
  338. this.line_char_count = 0;
  339. continue;
  340. }
  341. }
  342. content += input_char;
  343. this.line_char_count++;
  344. space = true;
  345. } while (content.toLowerCase().indexOf(delimiter) === -1);
  346. return content;
  347. };
  348. this.get_token = function () { //initial handler for token-retrieval
  349. var token;
  350. if (this.last_token === 'TK_TAG_SCRIPT' || this.last_token === 'TK_TAG_STYLE') { //check if we need to format javascript
  351. var type = this.last_token.substr(7);
  352. token = this.get_contents_to(type);
  353. if (typeof token !== 'string') {
  354. return token;
  355. }
  356. return [token, 'TK_' + type];
  357. }
  358. if (this.current_mode === 'CONTENT') {
  359. token = this.get_content();
  360. if (typeof token !== 'string') {
  361. return token;
  362. }
  363. else {
  364. return [token, 'TK_CONTENT'];
  365. }
  366. }
  367. if (this.current_mode === 'TAG') {
  368. token = this.get_tag();
  369. if (typeof token !== 'string') {
  370. return token;
  371. }
  372. else {
  373. var tag_name_type = 'TK_TAG_' + this.tag_type;
  374. return [token, tag_name_type];
  375. }
  376. }
  377. };
  378. this.get_full_indent = function (level) {
  379. level = this.indent_level + level || 0;
  380. if (level < 1) {
  381. return '';
  382. }
  383. return Array(level + 1).join(this.indent_string);
  384. };
  385. this.is_unformatted = function(tag_check, unformatted) {
  386. //is this an HTML5 block-level link?
  387. if (!this.Utils.in_array(tag_check, unformatted)){
  388. return false;
  389. }
  390. if (tag_check.toLowerCase() !== 'a' || !this.Utils.in_array('a', unformatted)){
  391. return true;
  392. }
  393. //at this point we have an tag; is its first child something we want to remain
  394. //unformatted?
  395. var next_tag = this.get_tag(true /* peek. */);
  396. // tets next_tag to see if it is just html tag (no external content)
  397. var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/);
  398. // if next_tag comes back but is not an isolated tag, then
  399. // let's treat the 'a' tag as having content
  400. // and respect the unformatted option
  401. if (!tag || this.Utils.in_array(tag, unformatted)){
  402. return true;
  403. } else {
  404. return false;
  405. }
  406. };
  407. this.printer = function (js_source, indent_character, indent_size, max_char, brace_style) { //handles input/output and some other printing functions
  408. this.input = js_source || ''; //gets the input for the Parser
  409. this.output = [];
  410. this.indent_character = indent_character;
  411. this.indent_string = '';
  412. this.indent_size = indent_size;
  413. this.brace_style = brace_style;
  414. this.indent_level = 0;
  415. this.max_char = max_char;
  416. this.line_char_count = 0; //count to see if max_char was exceeded
  417. for (var i=0; i<this.indent_size; i++) {
  418. this.indent_string += this.indent_character;
  419. }
  420. this.print_newline = function (ignore, arr) {
  421. this.line_char_count = 0;
  422. if (!arr || !arr.length) {
  423. return;
  424. }
  425. if (!ignore) { //we might want the extra line
  426. while (this.Utils.in_array(arr[arr.length-1], this.Utils.whitespace)) {
  427. arr.pop();
  428. }
  429. }
  430. arr.push('\n');
  431. for (var i=0; i<this.indent_level; i++) {
  432. arr.push(this.indent_string);
  433. }
  434. };
  435. this.print_token = function (text) {
  436. this.output.push(text);
  437. };
  438. this.indent = function () {
  439. this.indent_level++;
  440. };
  441. this.unindent = function () {
  442. if (this.indent_level > 0) {
  443. this.indent_level--;
  444. }
  445. };
  446. };
  447. return this;
  448. }
  449. /*_____________________--------------------_____________________*/
  450. multi_parser = new Parser(); //wrapping functions Parser
  451. multi_parser.printer(html_source, indent_character, indent_size, max_char, brace_style); //initialize starting values
  452. while (true) {
  453. var t = multi_parser.get_token();
  454. multi_parser.token_text = t[0];
  455. multi_parser.token_type = t[1];
  456. if (multi_parser.token_type === 'TK_EOF') {
  457. break;
  458. }
  459. switch (multi_parser.token_type) {
  460. case 'TK_TAG_START':
  461. multi_parser.print_newline(false, multi_parser.output);
  462. multi_parser.print_token(multi_parser.token_text);
  463. multi_parser.indent();
  464. multi_parser.current_mode = 'CONTENT';
  465. break;
  466. case 'TK_TAG_STYLE':
  467. case 'TK_TAG_SCRIPT':
  468. multi_parser.print_newline(false, multi_parser.output);
  469. multi_parser.print_token(multi_parser.token_text);
  470. multi_parser.current_mode = 'CONTENT';
  471. break;
  472. case 'TK_TAG_END':
  473. //Print new line only if the tag has no content and has child
  474. if (multi_parser.last_token === 'TK_CONTENT' && multi_parser.last_text === '') {
  475. var tag_name = multi_parser.token_text.match(/\w+/)[0];
  476. var tag_extracted_from_last_output = multi_parser.output[multi_parser.output.length -1].match(/<\s*(\w+)/);
  477. if (tag_extracted_from_last_output === null || tag_extracted_from_last_output[1] !== tag_name) {
  478. multi_parser.print_newline(true, multi_parser.output);
  479. }
  480. }
  481. multi_parser.print_token(multi_parser.token_text);
  482. multi_parser.current_mode = 'CONTENT';
  483. break;
  484. case 'TK_TAG_SINGLE':
  485. // Don't add a newline before elements that should remain unformatted.
  486. var tag_check = multi_parser.token_text.match(/^\s*<([a-z]+)/i);
  487. if (!tag_check || !multi_parser.Utils.in_array(tag_check[1], unformatted)){
  488. multi_parser.print_newline(false, multi_parser.output);
  489. }
  490. multi_parser.print_token(multi_parser.token_text);
  491. multi_parser.current_mode = 'CONTENT';
  492. break;
  493. case 'TK_CONTENT':
  494. if (multi_parser.token_text !== '') {
  495. multi_parser.print_token(multi_parser.token_text);
  496. }
  497. multi_parser.current_mode = 'TAG';
  498. break;
  499. case 'TK_STYLE':
  500. case 'TK_SCRIPT':
  501. if (multi_parser.token_text !== '') {
  502. multi_parser.output.push('\n');
  503. var text = multi_parser.token_text,
  504. _beautifier,
  505. script_indent_level = 1;
  506. if (multi_parser.token_type === 'TK_SCRIPT') {
  507. _beautifier = typeof js_beautify === 'function' && js_beautify;
  508. } else if (multi_parser.token_type === 'TK_STYLE') {
  509. _beautifier = typeof css_beautify === 'function' && css_beautify;
  510. }
  511. if (options.indent_scripts === "keep") {
  512. script_indent_level = 0;
  513. } else if (options.indent_scripts === "separate") {
  514. script_indent_level = -multi_parser.indent_level;
  515. }
  516. var indentation = multi_parser.get_full_indent(script_indent_level);
  517. if (_beautifier) {
  518. // call the Beautifier if avaliable
  519. text = _beautifier(text.replace(/^\s*/, indentation), options);
  520. } else {
  521. // simply indent the string otherwise
  522. var white = text.match(/^\s*/)[0];
  523. var _level = white.match(/[^\n\r]*$/)[0].split(multi_parser.indent_string).length - 1;
  524. var reindent = multi_parser.get_full_indent(script_indent_level -_level);
  525. text = text.replace(/^\s*/, indentation)
  526. .replace(/\r\n|\r|\n/g, '\n' + reindent)
  527. .replace(/\s*$/, '');
  528. }
  529. if (text) {
  530. multi_parser.print_token(text);
  531. multi_parser.print_newline(true, multi_parser.output);
  532. }
  533. }
  534. multi_parser.current_mode = 'TAG';
  535. break;
  536. }
  537. multi_parser.last_token = multi_parser.token_type;
  538. multi_parser.last_text = multi_parser.token_text;
  539. }
  540. return multi_parser.output.join('');
  541. }
  542. // If we're running a web page and don't have either of the above, add our one global
  543. window.html_beautify = function(html_source, options) {
  544. return style_html(html_source, options, window.js_beautify, window.css_beautify);
  545. };
  546. }());