beautifyhtml.js 28 KB

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