beautifyhtml.js 25 KB

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