1. //
  2. // Unpacker for Dean Edward's p.a.c.k.e.r, a part of javascript beautifier
  3. // written by Einar Lielmanis <einar@jsbeautifier.org>
  4. //
  5. // Coincidentally, it can defeat a couple of other eval-based compressors.
  6. //
  7. // usage:
  8. //
  9. // if (P_A_C_K_E_R.detect(some_string)) {
  10. // var unpacked = P_A_C_K_E_R.unpack(some_string);
  11. // }
  12. //
  13. //
  14. var P_A_C_K_E_R = {
  15. detect: function (str) {
  16. return P_A_C_K_E_R._starts_with(str.toLowerCase().replace(/ +/g, ''), 'eval(function(') ||
  17. P_A_C_K_E_R._starts_with(str.toLowerCase().replace(/ +/g, ''), 'eval((function(') ;
  18. },
  19. unpack: function (str) {
  20. var unpacked_source = '';
  21. if (P_A_C_K_E_R.detect(str)) {
  22. try {
  23. eval('unpacked_source = ' + str.substring(4) + ';')
  24. if (typeof unpacked_source == 'string' && unpacked_source) {
  25. str = unpacked_source;
  26. }
  27. } catch (error) {
  28. // well, it failed. we'll just return the original, instead of crashing on user.
  29. }
  30. }
  31. return str;
  32. },
  33. _starts_with: function (str, what) {
  34. return str.substr(0, what.length) === what;
  35. },
  36. run_tests: function (sanity_test) {
  37. var t = sanity_test || new SanityTest();
  38. t.test_function(P_A_C_K_E_R.detect, "P_A_C_K_E_R.detect");
  39. t.expect('', false);
  40. t.expect('var a = b', false);
  41. t.expect('eval(function(p,a,c,k,e,r', true);
  42. t.expect('eval ( function(p, a, c, k, e, r', true);
  43. t.test_function(P_A_C_K_E_R.unpack, 'P_A_C_K_E_R.unpack');
  44. t.expect("eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'var||a'.split('|'),0,{}))",
  45. 'var a=1');
  46. var starts_with_a = function(what) { return P_A_C_K_E_R._starts_with(what, 'a'); }
  47. t.test_function(starts_with_a, "P_A_C_K_E_R._starts_with(?, a)");
  48. t.expect('abc', true);
  49. t.expect('bcd', false);
  50. t.expect('a', true);
  51. t.expect('', false);
  52. return t;
  53. }
  54. }
  55. /*jslint onevar: false, plusplus: false */
  56. /*
  57. JS Beautifier
  58. ---------------
  59. Written by Einar Lielmanis, <einar@jsbeautifier.org>
  60. http://jsbeautifier.org/
  61. Originally converted to javascript by Vital, <vital76@gmail.com>
  62. You are free to use this in any way you want, in case you find this useful or working for you.
  63. Usage:
  64. js_beautify(js_source_text);
  65. js_beautify(js_source_text, options);
  66. The options are:
  67. indent_size (default 4) — indentation size,
  68. indent_char (default space) — character to indent with,
  69. preserve_newlines (default true) — whether existing line breaks should be preserved,
  70. indent_level (default 0) — initial indentation level, you probably won't need this ever,
  71. space_after_anon_function (default false) — if true, then space is added between "function ()"
  72. (jslint is happy about this); if false, then the common "function()" output is used.
  73. braces_on_own_line (default false) - ANSI / Allman brace style, each opening/closing brace gets its own line.
  74. e.g
  75. js_beautify(js_source_text, {indent_size: 1, indent_char: '\t'});
  76. */
  77. function js_beautify(js_source_text, options) {
  78. var input, output, token_text, last_type, last_text, last_last_text, last_word, flags, flag_store, indent_string;
  79. var whitespace, wordchar, punct, parser_pos, line_starters, digits;
  80. var prefix, token_type, do_block_just_closed;
  81. var wanted_newline, just_added_newline, n_newlines;
  82. // Some interpreters have unexpected results with foo = baz || bar;
  83. options = options ? options : {};
  84. var opt_braces_on_own_line = options.braces_on_own_line ? options.braces_on_own_line : false;
  85. var opt_indent_size = options.indent_size ? options.indent_size : 4;
  86. var opt_indent_char = options.indent_char ? options.indent_char : ' ';
  87. var opt_preserve_newlines = typeof options.preserve_newlines === 'undefined' ? true : options.preserve_newlines;
  88. var opt_indent_level = options.indent_level ? options.indent_level : 0; // starting indentation
  89. var opt_space_after_anon_function = options.space_after_anon_function === 'undefined' ? false : options.space_after_anon_function;
  90. var opt_keep_array_indentation = typeof options.keep_array_indentation === 'undefined' ? false : options.keep_array_indentation;
  91. just_added_newline = false;
  92. // cache the source's length.
  93. var input_length = js_source_text.length;
  94. function trim_output() {
  95. while (output.length && (output[output.length - 1] === ' ' || output[output.length - 1] === indent_string)) {
  96. output.pop();
  97. }
  98. }
  99. function is_array(mode) {
  100. return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]';
  101. }
  102. function print_newline(ignore_repeated) {
  103. flags.eat_next_space = false;
  104. if (opt_keep_array_indentation && is_array(flags.mode)) {
  105. return;
  106. }
  107. ignore_repeated = typeof ignore_repeated === 'undefined' ? true : ignore_repeated;
  108. flags.if_line = false;
  109. trim_output();
  110. if (!output.length) {
  111. return; // no newline on start of file
  112. }
  113. if (output[output.length - 1] !== "\n" || !ignore_repeated) {
  114. just_added_newline = true;
  115. output.push("\n");
  116. }
  117. for (var i = 0; i < flags.indentation_level; i += 1) {
  118. output.push(indent_string);
  119. }
  120. if (flags.var_line && flags.var_line_reindented) {
  121. if (opt_indent_char === ' ') {
  122. output.push(' '); // var_line always pushes 4 spaces, so that the variables would be one under another
  123. } else {
  124. output.push(indent_string); // skip space-stuffing, if indenting with a tab
  125. }
  126. }
  127. }
  128. function print_single_space() {
  129. if (flags.eat_next_space) {
  130. flags.eat_next_space = false;
  131. return;
  132. }
  133. var last_output = ' ';
  134. if (output.length) {
  135. last_output = output[output.length - 1];
  136. }
  137. if (last_output !== ' ' && last_output !== '\n' && last_output !== indent_string) { // prevent occassional duplicate space
  138. output.push(' ');
  139. }
  140. }
  141. function print_token() {
  142. just_added_newline = false;
  143. flags.eat_next_space = false;
  144. output.push(token_text);
  145. }
  146. function indent() {
  147. flags.indentation_level += 1;
  148. }
  149. function remove_indent() {
  150. if (output.length && output[output.length - 1] === indent_string) {
  151. output.pop();
  152. }
  153. }
  154. function set_mode(mode) {
  155. if (flags) {
  156. flag_store.push(flags);
  157. }
  158. flags = {
  159. previous_mode: flags ? flags.mode : 'BLOCK',
  160. mode: mode,
  161. var_line: false,
  162. var_line_tainted: false,
  163. var_line_reindented: false,
  164. in_html_comment: false,
  165. if_line: false,
  166. in_case: false,
  167. eat_next_space: false,
  168. indentation_baseline: -1,
  169. indentation_level: (flags ? flags.indentation_level + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : opt_indent_level)
  170. };
  171. }
  172. function is_array(mode) {
  173. return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]';
  174. }
  175. function is_expression(mode) {
  176. return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]' || mode === '(EXPRESSION)';
  177. }
  178. function restore_mode() {
  179. do_block_just_closed = flags.mode === 'DO_BLOCK';
  180. if (flag_store.length > 0) {
  181. flags = flag_store.pop();
  182. }
  183. }
  184. function in_array(what, arr) {
  185. for (var i = 0; i < arr.length; i += 1) {
  186. if (arr[i] === what) {
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. // Walk backwards from the colon to find a '?' (colon is part of a ternary op)
  193. // or a '{' (colon is part of a class literal). Along the way, keep track of
  194. // the blocks and expressions we pass so we only trigger on those chars in our
  195. // own level, and keep track of the colons so we only trigger on the matching '?'.
  196. function is_ternary_op() {
  197. var level = 0,
  198. colon_count = 0;
  199. for (var i = output.length - 1; i >= 0; i--) {
  200. switch (output[i]) {
  201. case ':':
  202. if (level === 0) {
  203. colon_count++;
  204. }
  205. break;
  206. case '?':
  207. if (level === 0) {
  208. if (colon_count === 0) {
  209. return true;
  210. } else {
  211. colon_count--;
  212. }
  213. }
  214. break;
  215. case '{':
  216. if (level === 0) {
  217. return false;
  218. }
  219. level--;
  220. break;
  221. case '(':
  222. case '[':
  223. level--;
  224. break;
  225. case ')':
  226. case ']':
  227. case '}':
  228. level++;
  229. break;
  230. }
  231. }
  232. }
  233. function get_next_token() {
  234. n_newlines = 0;
  235. if (parser_pos >= input_length) {
  236. return ['', 'TK_EOF'];
  237. }
  238. wanted_newline = false;
  239. var c = input.charAt(parser_pos);
  240. parser_pos += 1;
  241. var keep_whitespace = opt_keep_array_indentation && is_array(flags.mode);
  242. if (keep_whitespace) {
  243. //
  244. // slight mess to allow nice preservation of array indentation and reindent that correctly
  245. // first time when we get to the arrays:
  246. // var a = [
  247. // ....'something'
  248. // we make note of whitespace_count = 4 into flags.indentation_baseline
  249. // so we know that 4 whitespaces in original source match indent_level of reindented source
  250. //
  251. // and afterwards, when we get to
  252. // 'something,
  253. // .......'something else'
  254. // we know that this should be indented to indent_level + (7 - indentation_baseline) spaces
  255. //
  256. var whitespace_count = 0;
  257. while (in_array(c, whitespace)) {
  258. if (c === "\n") {
  259. trim_output();
  260. output.push("\n");
  261. just_added_newline = true;
  262. whitespace_count = 0;
  263. } else {
  264. if (c === '\t') {
  265. whitespace_count += 4;
  266. } else {
  267. whitespace_count += 1;
  268. }
  269. }
  270. if (parser_pos >= input_length) {
  271. return ['', 'TK_EOF'];
  272. }
  273. c = input.charAt(parser_pos);
  274. parser_pos += 1;
  275. }
  276. if (flags.indentation_baseline === -1) {
  277. flags.indentation_baseline = whitespace_count;
  278. }
  279. if (just_added_newline) {
  280. var i;
  281. for (i = 0; i < flags.indentation_level + 1; i += 1) {
  282. output.push(indent_string);
  283. }
  284. if (flags.indentation_baseline !== -1) {
  285. for (i = 0; i < whitespace_count - flags.indentation_baseline; i++) {
  286. output.push(' ');
  287. }
  288. }
  289. }
  290. } else {
  291. while (in_array(c, whitespace)) {
  292. if (c === "\n") {
  293. n_newlines += 1;
  294. }
  295. if (parser_pos >= input_length) {
  296. return ['', 'TK_EOF'];
  297. }
  298. c = input.charAt(parser_pos);
  299. parser_pos += 1;
  300. }
  301. if (opt_preserve_newlines) {
  302. if (n_newlines > 1) {
  303. for (i = 0; i < n_newlines; i += 1) {
  304. print_newline(i === 0);
  305. just_added_newline = true;
  306. }
  307. }
  308. }
  309. wanted_newline = n_newlines > 0;
  310. }
  311. if (in_array(c, wordchar)) {
  312. if (parser_pos < input_length) {
  313. while (in_array(input.charAt(parser_pos), wordchar)) {
  314. c += input.charAt(parser_pos);
  315. parser_pos += 1;
  316. if (parser_pos === input_length) {
  317. break;
  318. }
  319. }
  320. }
  321. // small and surprisingly unugly hack for 1E-10 representation
  322. if (parser_pos !== input_length && c.match(/^[0-9]+[Ee]$/) && (input.charAt(parser_pos) === '-' || input.charAt(parser_pos) === '+')) {
  323. var sign = input.charAt(parser_pos);
  324. parser_pos += 1;
  325. var t = get_next_token(parser_pos);
  326. c += sign + t[0];
  327. return [c, 'TK_WORD'];
  328. }
  329. if (c === 'in') { // hack for 'in' operator
  330. return [c, 'TK_OPERATOR'];
  331. }
  332. if (wanted_newline && last_type !== 'TK_OPERATOR' && !flags.if_line && (opt_preserve_newlines || last_text !== 'var')) {
  333. print_newline();
  334. }
  335. return [c, 'TK_WORD'];
  336. }
  337. if (c === '(' || c === '[') {
  338. return [c, 'TK_START_EXPR'];
  339. }
  340. if (c === ')' || c === ']') {
  341. return [c, 'TK_END_EXPR'];
  342. }
  343. if (c === '{') {
  344. return [c, 'TK_START_BLOCK'];
  345. }
  346. if (c === '}') {
  347. return [c, 'TK_END_BLOCK'];
  348. }
  349. if (c === ';') {
  350. return [c, 'TK_SEMICOLON'];
  351. }
  352. if (c === '/') {
  353. var comment = '';
  354. // peek for comment /* ... */
  355. var inline_comment = true;
  356. if (input.charAt(parser_pos) === '*') {
  357. parser_pos += 1;
  358. if (parser_pos < input_length) {
  359. while (!(input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/') && parser_pos < input_length) {
  360. c = input.charAt(parser_pos);
  361. comment += c;
  362. if (c === '\x0d' || c === '\x0a') {
  363. inline_comment = false;
  364. }
  365. parser_pos += 1;
  366. if (parser_pos >= input_length) {
  367. break;
  368. }
  369. }
  370. }
  371. parser_pos += 2;
  372. if (inline_comment) {
  373. return ['/*' + comment + '*/', 'TK_INLINE_COMMENT'];
  374. } else {
  375. return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
  376. }
  377. }
  378. // peek for comment // ...
  379. if (input.charAt(parser_pos) === '/') {
  380. comment = c;
  381. while (input.charAt(parser_pos) !== "\x0d" && input.charAt(parser_pos) !== "\x0a") {
  382. comment += input.charAt(parser_pos);
  383. parser_pos += 1;
  384. if (parser_pos >= input_length) {
  385. break;
  386. }
  387. }
  388. parser_pos += 1;
  389. if (wanted_newline) {
  390. print_newline();
  391. }
  392. return [comment, 'TK_COMMENT'];
  393. }
  394. }
  395. if (c === "'" || // string
  396. c === '"' || // string
  397. (c === '/' && ((last_type === 'TK_WORD' && in_array(last_text, ['return', 'do'])) || (last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
  398. var sep = c;
  399. var esc = false;
  400. var resulting_string = c;
  401. if (parser_pos < input_length) {
  402. if (sep === '/') {
  403. //
  404. // handle regexp separately...
  405. //
  406. var in_char_class = false;
  407. while (esc || in_char_class || input.charAt(parser_pos) !== sep) {
  408. resulting_string += input.charAt(parser_pos);
  409. if (!esc) {
  410. esc = input.charAt(parser_pos) === '\\';
  411. if (input.charAt(parser_pos) === '[') {
  412. in_char_class = true;
  413. } else if (input.charAt(parser_pos) === ']') {
  414. in_char_class = false;
  415. }
  416. } else {
  417. esc = false;
  418. }
  419. parser_pos += 1;
  420. if (parser_pos >= input_length) {
  421. // incomplete string/rexp when end-of-file reached.
  422. // bail out with what had been received so far.
  423. return [resulting_string, 'TK_STRING'];
  424. }
  425. }
  426. } else {
  427. //
  428. // and handle string also separately
  429. //
  430. while (esc || input.charAt(parser_pos) !== sep) {
  431. resulting_string += input.charAt(parser_pos);
  432. if (!esc) {
  433. esc = input.charAt(parser_pos) === '\\';
  434. } else {
  435. esc = false;
  436. }
  437. parser_pos += 1;
  438. if (parser_pos >= input_length) {
  439. // incomplete string/rexp when end-of-file reached.
  440. // bail out with what had been received so far.
  441. return [resulting_string, 'TK_STRING'];
  442. }
  443. }
  444. }
  445. }
  446. parser_pos += 1;
  447. resulting_string += sep;
  448. if (sep === '/') {
  449. // regexps may have modifiers /regexp/MOD , so fetch those, too
  450. while (parser_pos < input_length && in_array(input.charAt(parser_pos), wordchar)) {
  451. resulting_string += input.charAt(parser_pos);
  452. parser_pos += 1;
  453. }
  454. }
  455. return [resulting_string, 'TK_STRING'];
  456. }
  457. if (c === '#') {
  458. // Spidermonkey-specific sharp variables for circular references
  459. // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
  460. // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
  461. var sharp = '#';
  462. if (parser_pos < input_length && in_array(input.charAt(parser_pos), digits)) {
  463. do {
  464. c = input.charAt(parser_pos);
  465. sharp += c;
  466. parser_pos += 1;
  467. } while (parser_pos < input_length && c !== '#' && c !== '=');
  468. if (c === '#') {
  469. //
  470. } else if (input.charAt(parser_pos) === '[' && input.charAt(parser_pos + 1) === ']') {
  471. sharp += '[]';
  472. parser_pos += 2;
  473. } else if (input.charAt(parser_pos) === '{' && input.charAt(parser_pos + 1) === '}') {
  474. sharp += '{}';
  475. parser_pos += 2;
  476. }
  477. return [sharp, 'TK_WORD'];
  478. }
  479. }
  480. if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '<!--') {
  481. parser_pos += 3;
  482. flags.in_html_comment = true;
  483. return ['<!--', 'TK_COMMENT'];
  484. }
  485. if (c === '-' && flags.in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === '-->') {
  486. flags.in_html_comment = false;
  487. parser_pos += 2;
  488. if (wanted_newline) {
  489. print_newline();
  490. }
  491. return ['-->', 'TK_COMMENT'];
  492. }
  493. if (in_array(c, punct)) {
  494. while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) {
  495. c += input.charAt(parser_pos);
  496. parser_pos += 1;
  497. if (parser_pos >= input_length) {
  498. break;
  499. }
  500. }
  501. if (c === '=') {
  502. return [c, 'TK_EQUALS'];
  503. } else {
  504. return [c, 'TK_OPERATOR'];
  505. }
  506. }
  507. return [c, 'TK_UNKNOWN'];
  508. }
  509. //----------------------------------
  510. indent_string = '';
  511. while (opt_indent_size > 0) {
  512. indent_string += opt_indent_char;
  513. opt_indent_size -= 1;
  514. }
  515. input = js_source_text;
  516. last_word = ''; // last 'TK_WORD' passed
  517. last_type = 'TK_START_EXPR'; // last token type
  518. last_text = ''; // last token text
  519. last_last_text = ''; // pre-last token text
  520. output = [];
  521. do_block_just_closed = false;
  522. whitespace = "\n\r\t ".split('');
  523. wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
  524. digits = '0123456789'.split('');
  525. punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::'.split(' ');
  526. // words which should always start on new line.
  527. line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
  528. // states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'.
  529. // some formatting depends on that.
  530. flag_store = [];
  531. set_mode('BLOCK');
  532. parser_pos = 0;
  533. while (true) {
  534. var t = get_next_token(parser_pos);
  535. token_text = t[0];
  536. token_type = t[1];
  537. if (token_type === 'TK_EOF') {
  538. break;
  539. }
  540. switch (token_type) {
  541. case 'TK_START_EXPR':
  542. if (token_text === '[') {
  543. if (last_type === 'TK_WORD' || last_text === ')') {
  544. // this is array index specifier, break immediately
  545. // a[x], fn()[x]
  546. if (in_array(last_text, line_starters)) {
  547. print_single_space();
  548. }
  549. set_mode('(EXPRESSION)');
  550. print_token();
  551. break;
  552. }
  553. if (flags.mode === '[EXPRESSION]' || flags.mode === '[INDENTED-EXPRESSION]') {
  554. if (last_last_text === ']' && last_text === ',') {
  555. // ], [ goes to new line
  556. if (flags.mode === '[EXPRESSION]') {
  557. flags.mode = '[INDENTED-EXPRESSION]';
  558. if (!opt_keep_array_indentation) {
  559. indent();
  560. }
  561. }
  562. set_mode('[EXPRESSION]');
  563. if (!opt_keep_array_indentation) {
  564. print_newline();
  565. }
  566. } else if (last_text === '[') {
  567. if (flags.mode === '[EXPRESSION]') {
  568. flags.mode = '[INDENTED-EXPRESSION]';
  569. if (!opt_keep_array_indentation) {
  570. indent();
  571. }
  572. }
  573. set_mode('[EXPRESSION]');
  574. if (!opt_keep_array_indentation) {
  575. print_newline();
  576. }
  577. } else {
  578. set_mode('[EXPRESSION]');
  579. }
  580. } else {
  581. set_mode('[EXPRESSION]');
  582. }
  583. } else {
  584. set_mode('(EXPRESSION)');
  585. }
  586. if (last_text === ';' || last_type === 'TK_START_BLOCK') {
  587. print_newline();
  588. } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_text === '.') {
  589. // do nothing on (( and )( and ][ and ]( and .(
  590. } else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
  591. print_single_space();
  592. } else if (last_word === 'function') {
  593. // function() vs function ()
  594. if (opt_space_after_anon_function) {
  595. print_single_space();
  596. }
  597. } else if (in_array(last_text, line_starters) || last_text === 'catch') {
  598. print_single_space();
  599. }
  600. print_token();
  601. break;
  602. case 'TK_END_EXPR':
  603. if (token_text === ']') {
  604. if (opt_keep_array_indentation) {
  605. if (last_text === '}') {
  606. // trim_output();
  607. // print_newline(true);
  608. remove_indent();
  609. print_token();
  610. restore_mode();
  611. break;
  612. }
  613. } else {
  614. if (flags.mode === '[INDENTED-EXPRESSION]') {
  615. if (last_text === ']') {
  616. restore_mode();
  617. print_newline();
  618. print_token();
  619. break;
  620. }
  621. }
  622. }
  623. }
  624. restore_mode();
  625. print_token();
  626. break;
  627. case 'TK_START_BLOCK':
  628. if (last_word === 'do') {
  629. set_mode('DO_BLOCK');
  630. } else {
  631. set_mode('BLOCK');
  632. }
  633. if (opt_braces_on_own_line) {
  634. if (last_type !== 'TK_OPERATOR') {
  635. if (last_text == 'return') {
  636. print_single_space();
  637. } else {
  638. print_newline(true);
  639. }
  640. }
  641. print_token();
  642. indent();
  643. } else {
  644. if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
  645. if (last_type === 'TK_START_BLOCK') {
  646. print_newline();
  647. } else {
  648. print_single_space();
  649. }
  650. } else {
  651. // if TK_OPERATOR or TK_START_EXPR
  652. if (is_array(flags.previous_mode) && last_text === ',') {
  653. print_newline(); // [a, b, c, {
  654. }
  655. }
  656. indent();
  657. print_token();
  658. }
  659. break;
  660. case 'TK_END_BLOCK':
  661. restore_mode();
  662. if (opt_braces_on_own_line) {
  663. print_newline();
  664. print_token();
  665. } else {
  666. if (last_type === 'TK_START_BLOCK') {
  667. // nothing
  668. if (just_added_newline) {
  669. remove_indent();
  670. } else {
  671. // {}
  672. trim_output();
  673. }
  674. } else {
  675. print_newline();
  676. }
  677. print_token();
  678. }
  679. break;
  680. case 'TK_WORD':
  681. // no, it's not you. even I have problems understanding how this works
  682. // and what does what.
  683. if (do_block_just_closed) {
  684. // do {} ## while ()
  685. print_single_space();
  686. print_token();
  687. print_single_space();
  688. do_block_just_closed = false;
  689. break;
  690. }
  691. if (token_text === 'function') {
  692. if ((just_added_newline || last_text === ';') && last_text !== '{') {
  693. // make sure there is a nice clean space of at least one blank line
  694. // before a new function definition
  695. n_newlines = just_added_newline ? n_newlines : 0;
  696. for (var i = 0; i < 2 - n_newlines; i++) {
  697. print_newline(false);
  698. }
  699. }
  700. }
  701. if (token_text === 'case' || token_text === 'default') {
  702. if (last_text === ':') {
  703. // switch cases following one another
  704. remove_indent();
  705. } else {
  706. // case statement starts in the same line where switch
  707. flags.indentation_level--;
  708. print_newline();
  709. flags.indentation_level++;
  710. }
  711. print_token();
  712. flags.in_case = true;
  713. break;
  714. }
  715. prefix = 'NONE';
  716. if (last_type === 'TK_END_BLOCK') {
  717. if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
  718. prefix = 'NEWLINE';
  719. } else {
  720. if (opt_braces_on_own_line) {
  721. prefix = 'NEWLINE';
  722. } else {
  723. prefix = 'SPACE';
  724. print_single_space();
  725. }
  726. }
  727. } else if (last_type === 'TK_SEMICOLON' && (flags.mode === 'BLOCK' || flags.mode === 'DO_BLOCK')) {
  728. prefix = 'NEWLINE';
  729. } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
  730. prefix = 'SPACE';
  731. } else if (last_type === 'TK_STRING') {
  732. prefix = 'NEWLINE';
  733. } else if (last_type === 'TK_WORD') {
  734. prefix = 'SPACE';
  735. } else if (last_type === 'TK_START_BLOCK') {
  736. prefix = 'NEWLINE';
  737. } else if (last_type === 'TK_END_EXPR') {
  738. print_single_space();
  739. prefix = 'NEWLINE';
  740. }
  741. if (last_type !== 'TK_END_BLOCK' && in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
  742. print_newline();
  743. } else if (in_array(token_text, line_starters) || prefix === 'NEWLINE') {
  744. if (last_text === 'else') {
  745. // no need to force newline on else break
  746. print_single_space();
  747. } else if ((last_type === 'TK_START_EXPR' || last_text === '=' || last_text === ',') && token_text === 'function') {
  748. // no need to force newline on 'function': (function
  749. // DONOTHING
  750. } else if (last_text === 'return' || last_text === 'throw') {
  751. // no newline between 'return nnn'
  752. print_single_space();
  753. } else if (last_type !== 'TK_END_EXPR') {
  754. if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && last_text !== ':') {
  755. // no need to force newline on 'var': for (var x = 0...)
  756. if (token_text === 'if' && last_word === 'else' && last_text !== '{') {
  757. // no newline for } else if {
  758. print_single_space();
  759. } else {
  760. print_newline();
  761. }
  762. }
  763. } else {
  764. if (in_array(token_text, line_starters) && last_text !== ')') {
  765. print_newline();
  766. }
  767. }
  768. } else if (is_array(flags.mode) && last_text === ',' && last_last_text === '}') {
  769. print_newline(); // }, in lists get a newline treatment
  770. } else if (prefix === 'SPACE') {
  771. print_single_space();
  772. }
  773. print_token();
  774. last_word = token_text;
  775. if (token_text === 'var') {
  776. flags.var_line = true;
  777. flags.var_line_reindented = false;
  778. flags.var_line_tainted = false;
  779. }
  780. if (token_text === 'if' || token_text === 'else') {
  781. flags.if_line = true;
  782. }
  783. break;
  784. case 'TK_SEMICOLON':
  785. print_token();
  786. flags.var_line = false;
  787. flags.var_line_reindented = false;
  788. break;
  789. case 'TK_STRING':
  790. if (last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_SEMICOLON') {
  791. print_newline();
  792. } else if (last_type === 'TK_WORD') {
  793. print_single_space();
  794. }
  795. print_token();
  796. break;
  797. case 'TK_EQUALS':
  798. if (flags.var_line) {
  799. // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
  800. flags.var_line_tainted = true;
  801. }
  802. print_single_space();
  803. print_token();
  804. print_single_space();
  805. break;
  806. case 'TK_OPERATOR':
  807. var space_before = true;
  808. var space_after = true;
  809. if (flags.var_line && token_text === ',' && (is_expression(flags.mode))) {
  810. // do not break on comma, for(var a = 1, b = 2)
  811. flags.var_line_tainted = false;
  812. }
  813. if (flags.var_line) {
  814. if (token_text === ',') {
  815. if (flags.var_line_tainted) {
  816. print_token();
  817. flags.var_line_reindented = true;
  818. flags.var_line_tainted = false;
  819. print_newline();
  820. break;
  821. } else {
  822. flags.var_line_tainted = false;
  823. }
  824. // } else if (token_text === ':') {
  825. // hmm, when does this happen? tests don't catch this
  826. // flags.var_line = false;
  827. }
  828. }
  829. if (last_text === 'return' || last_text === 'throw') {
  830. // "return" had a special handling in TK_WORD. Now we need to return the favor
  831. print_single_space();
  832. print_token();
  833. break;
  834. }
  835. if (token_text === ':' && flags.in_case) {
  836. print_token(); // colon really asks for separate treatment
  837. print_newline();
  838. flags.in_case = false;
  839. break;
  840. }
  841. if (token_text === '::') {
  842. // no spaces around exotic namespacing syntax operator
  843. print_token();
  844. break;
  845. }
  846. if (token_text === ',') {
  847. if (flags.var_line) {
  848. if (flags.var_line_tainted) {
  849. print_token();
  850. print_newline();
  851. flags.var_line_tainted = false;
  852. } else {
  853. print_token();
  854. print_single_space();
  855. }
  856. } else if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") {
  857. print_token();
  858. if (flags.mode === 'OBJECT' && last_text === '}') {
  859. print_newline();
  860. } else {
  861. print_single_space();
  862. }
  863. } else {
  864. if (flags.mode === 'OBJECT') {
  865. print_token();
  866. print_newline();
  867. } else {
  868. // EXPR or DO_BLOCK
  869. print_token();
  870. print_single_space();
  871. }
  872. }
  873. break;
  874. // } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS']) || in_array(last_text, line_starters) || in_array(last_text, ['==', '!=', '+=', '-=', '*=', '/=', '+', '-'])))) {
  875. } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(last_text, line_starters)))) {
  876. // unary operators (and binary +/- pretending to be unary) special cases
  877. space_before = false;
  878. space_after = false;
  879. if (last_text === ';' && is_expression(flags.mode)) {
  880. // for (;; ++i)
  881. // ^^^
  882. space_before = true;
  883. }
  884. if (last_type === 'TK_WORD' && in_array(last_text, line_starters)) {
  885. space_before = true;
  886. }
  887. if (flags.mode === 'BLOCK' && (last_text === '{' || last_text === ';')) {
  888. // { foo; --i }
  889. // foo(); --bar;
  890. print_newline();
  891. }
  892. } else if (token_text === '.') {
  893. // decimal digits or object.property
  894. space_before = false;
  895. } else if (token_text === ':') {
  896. if (!is_ternary_op()) {
  897. flags.mode = 'OBJECT';
  898. space_before = false;
  899. }
  900. }
  901. if (space_before) {
  902. print_single_space();
  903. }
  904. print_token();
  905. if (space_after) {
  906. print_single_space();
  907. }
  908. if (token_text === '!') {
  909. // flags.eat_next_space = true;
  910. }
  911. break;
  912. case 'TK_BLOCK_COMMENT':
  913. var lines = token_text.split(/\x0a|\x0d\x0a/);
  914. if (/^\/\*\*/.test(token_text)) {
  915. // javadoc: reformat and reindent
  916. print_newline();
  917. output.push(lines[0]);
  918. for (i = 1; i < lines.length; i++) {
  919. print_newline();
  920. output.push(' ');
  921. output.push(lines[i].replace(/^\s\s*|\s\s*$/, ''));
  922. }
  923. } else {
  924. // simple block comment: leave intact
  925. if (lines.length > 1) {
  926. // multiline comment block starts with a new line
  927. print_newline();
  928. trim_output();
  929. } else {
  930. // single-line /* comment */ stays where it is
  931. print_single_space();
  932. }
  933. for (i = 0; i < lines.length; i++) {
  934. output.push(lines[i]);
  935. output.push('\n');
  936. }
  937. }
  938. print_newline();
  939. break;
  940. case 'TK_INLINE_COMMENT':
  941. print_single_space();
  942. print_token();
  943. if (is_expression(flags.mode)) {
  944. print_single_space();
  945. } else {
  946. print_newline();
  947. }
  948. break;
  949. case 'TK_COMMENT':
  950. // print_newline();
  951. if (wanted_newline) {
  952. print_newline();
  953. } else {
  954. print_single_space();
  955. }
  956. print_token();
  957. print_newline();
  958. break;
  959. case 'TK_UNKNOWN':
  960. print_token();
  961. break;
  962. }
  963. last_last_text = last_text;
  964. last_type = token_type;
  965. last_text = token_text;
  966. }
  967. return output.join('').replace(/[\n ]+$/, '');
  968. }
  969. //*******************************************
  970. sArgs = [
  971. ['&A\tAbout This Plugin'],
  972. ['',''],
  973. ['\t--Replace selection--',''],
  974. ['',''],
  975. ['&1\tIndent size: 1 Tab', {indent_size: 1,indent_char: '\t'} , 'Replace'],
  976. ['&2\tIndent size: 2 Spaces', {indent_size: 2,indent_char: ' '}, 'Replace'],
  977. ['&3\tIndent size: 4 Spaces', {indent_size: 4,indent_char: ' '}, 'Replace'],
  978. ['',''],
  979. ['\t--Output in Output Bar--',''],
  980. ['',''],
  981. ['&4\tIndent size: 1 Tab', {indent_size: 1,indent_char: '\t'} , 'OutputBar'],
  982. ['&5\tIndent size: 2 Spaces', {indent_size: 2,indent_char: ' '}, 'OutputBar'],
  983. ['&6\tIndent size: 4 Spaces', {indent_size: 4,indent_char: ' '}, 'OutputBar'],
  984. ['',''],
  985. ['\t--Output in new file--',''],
  986. ['',''],
  987. ['&7\tIndent size: 1 Tab', {indent_size: 1,indent_char: '\t'} , 'NewFile'],
  988. ['&8\tIndent size: 2 Spaces', {indent_size: 2,indent_char: ' '}, 'NewFile'],
  989. ['&9\tIndent size: 4 Spaces', {indent_size: 4,indent_char: ' '}, 'NewFile']
  990. ];
  991. menu = CreatePopupMenu();
  992. for (i = 0; i != sArgs.length; i++) {
  993. if (sArgs[i][0] != '') {
  994. menu.Add(sArgs[i][0], i + 1);
  995. }
  996. else {
  997. menu.Add('', 0, eeMenuSeparator);
  998. }
  999. }
  1000. result = menu.Track(0);
  1001. if (result != 0) {
  1002. if (result == 1) {
  1003. alert('宏作者:阿良\nMacro Author: Arliang\nマクロのさくしゃ:りょう\nhttp://arliang.cnblogs.com/\n2011.08.13 22:41:55');
  1004. Quit();
  1005. }
  1006. var js_source = document.selection.Text;
  1007. if (!js_source) {
  1008. document.selection.SelectAll();
  1009. js_source = document.selection.Text;
  1010. }
  1011. if (js_source) {
  1012. js_source = P_A_C_K_E_R.unpack(js_source);
  1013. var tabsize = 4;
  1014. var tabchar = ' ';
  1015. if (tabsize == 1) {
  1016. tabchar = '\t';
  1017. }
  1018. /******
  1019. alert(result);
  1020. Quit();
  1021. //*****/
  1022. var beautified = js_beautify(js_source, sArgs[result - 1][1]);
  1023. if (beautified && beautified != js_source) {
  1024. if (sArgs[result - 1].length > 2) {
  1025. switch (sArgs[result - 1][2].toLowerCase()) {
  1026. case 'replace':
  1027. document.write(beautified);
  1028. break;
  1029. case 'newfile':
  1030. editor.NewFile();
  1031. document.write(beautified);
  1032. break;
  1033. case 'outputbar':
  1034. OutputBar.Clear();
  1035. OutputBar.writeln(beautified);
  1036. OutputBar.Visible = true;
  1037. OutputBar.SetFocus();
  1038. break;
  1039. }
  1040. document.ConfigName = "JavaScript";
  1041. }
  1042. }
  1043. }
  1044. }

var window = {};

/*
Copyright (C) 2013 Sencha Inc.
Copyright (C) 2012 Sencha Inc.
Copyright (C) 2011 Sencha Inc. Author: Ariya Hidayat. Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/ /*jslint continue: true, indent: 4 */
/*global exports:true, module:true, window:true */ (function () { 'use strict'; function cssbeautify(style, opt) { var options, index = 0, length = style.length, blocks, formatted = '',
ch, ch2, str, state, State, depth, quote, comment,
openbracesuffix = true,
autosemicolon = false,
trimRight; options = arguments.length > 1 ? opt : {};
if (typeof options.indent === 'undefined') {
options.indent = ' ';
}
if (typeof options.openbrace === 'string') {
openbracesuffix = (options.openbrace === 'end-of-line');
}
if (typeof options.autosemicolon === 'boolean') {
autosemicolon = options.autosemicolon;
} function isWhitespace(c) {
return (c === ' ') || (c === '\n') || (c === '\t') || (c === '\r') || (c === '\f');
} function isQuote(c) {
return (c === '\'') || (c === '"');
} // FIXME: handle Unicode characters
function isName(c) {
return (ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') ||
'-_*.:#[]'.indexOf(c) >= 0;
} function appendIndent() {
var i;
for (i = depth; i > 0; i -= 1) {
formatted += options.indent;
}
} function openBlock() {
formatted = trimRight(formatted);
if (openbracesuffix) {
formatted += ' {';
} else {
formatted += '\n';
appendIndent();
formatted += '{';
}
if (ch2 !== '\n') {
formatted += '\n';
}
depth += 1;
} function closeBlock() {
var last;
depth -= 1;
formatted = trimRight(formatted); if (formatted.length > 0 && autosemicolon) {
last = formatted.charAt(formatted.length - 1);
if (last !== ';' && last !== '{') {
formatted += ';';
}
} formatted += '\n';
appendIndent();
formatted += '}';
blocks.push(formatted);
formatted = '';
} if (String.prototype.trimRight) {
trimRight = function (s) {
return s.trimRight();
};
} else {
// old Internet Explorer
trimRight = function (s) {
return s.replace(/\s+$/, '');
};
} State = {
Start: 0,
AtRule: 1,
Block: 2,
Selector: 3,
Ruleset: 4,
Property: 5,
Separator: 6,
Expression: 7,
URL: 8
}; depth = 0;
state = State.Start;
comment = false;
blocks = []; // We want to deal with LF (\n) only
style = style.replace(/\r\n/g, '\n'); while (index < length) {
ch = style.charAt(index);
ch2 = style.charAt(index + 1);
index += 1; // Inside a string literal?
if (isQuote(quote)) {
formatted += ch;
if (ch === quote) {
quote = null;
}
if (ch === '\\' && ch2 === quote) {
// Don't treat escaped character as the closing quote
formatted += ch2;
index += 1;
}
continue;
} // Starting a string literal?
if (isQuote(ch)) {
formatted += ch;
quote = ch;
continue;
} // Comment
if (comment) {
formatted += ch;
if (ch === '*' && ch2 === '/') {
comment = false;
formatted += ch2;
index += 1;
}
continue;
}
if (ch === '/' && ch2 === '*') {
comment = true;
formatted += ch;
formatted += ch2;
index += 1;
continue;
} if (state === State.Start) { if (blocks.length === 0) {
if (isWhitespace(ch) && formatted.length === 0) {
continue;
}
} // Copy white spaces and control characters
if (ch <= ' ' || ch.charCodeAt(0) >= 128) {
state = State.Start;
formatted += ch;
continue;
} // Selector or at-rule
if (isName(ch) || (ch === '@')) { // Clear trailing whitespaces and linefeeds.
str = trimRight(formatted); if (str.length === 0) {
// If we have empty string after removing all the trailing
// spaces, that means we are right after a block.
// Ensure a blank line as the separator.
if (blocks.length > 0) {
formatted = '\n\n';
}
} else {
// After finishing a ruleset or directive statement,
// there should be one blank line.
if (str.charAt(str.length - 1) === '}' ||
str.charAt(str.length - 1) === ';') { formatted = str + '\n\n';
} else {
// After block comment, keep all the linefeeds but
// start from the first column (remove whitespaces prefix).
while (true) {
ch2 = formatted.charAt(formatted.length - 1);
if (ch2 !== ' ' && ch2.charCodeAt(0) !== 9) {
break;
}
formatted = formatted.substr(0, formatted.length - 1);
}
}
}
formatted += ch;
state = (ch === '@') ? State.AtRule : State.Selector;
continue;
}
} if (state === State.AtRule) { // ';' terminates a statement.
if (ch === ';') {
formatted += ch;
state = State.Start;
continue;
} // '{' starts a block
if (ch === '{') {
str = trimRight(formatted);
openBlock();
state = (str === '@font-face') ? State.Ruleset : State.Block;
continue;
} formatted += ch;
continue;
} if (state === State.Block) { // Selector
if (isName(ch)) { // Clear trailing whitespaces and linefeeds.
str = trimRight(formatted); if (str.length === 0) {
// If we have empty string after removing all the trailing
// spaces, that means we are right after a block.
// Ensure a blank line as the separator.
if (blocks.length > 0) {
formatted = '\n\n';
}
} else {
// Insert blank line if necessary.
if (str.charAt(str.length - 1) === '}') {
formatted = str + '\n\n';
} else {
// After block comment, keep all the linefeeds but
// start from the first column (remove whitespaces prefix).
while (true) {
ch2 = formatted.charAt(formatted.length - 1);
if (ch2 !== ' ' && ch2.charCodeAt(0) !== 9) {
break;
}
formatted = formatted.substr(0, formatted.length - 1);
}
}
} appendIndent();
formatted += ch;
state = State.Selector;
continue;
} // '}' resets the state.
if (ch === '}') {
closeBlock();
state = State.Start;
continue;
} formatted += ch;
continue;
} if (state === State.Selector) { // '{' starts the ruleset.
if (ch === '{') {
openBlock();
state = State.Ruleset;
continue;
} // '}' resets the state.
if (ch === '}') {
closeBlock();
state = State.Start;
continue;
} formatted += ch;
continue;
} if (state === State.Ruleset) { // '}' finishes the ruleset.
if (ch === '}') {
closeBlock();
state = State.Start;
if (depth > 0) {
state = State.Block;
}
continue;
} // Make sure there is no blank line or trailing spaces inbetween
if (ch === '\n') {
formatted = trimRight(formatted);
formatted += '\n';
continue;
} // property name
if (!isWhitespace(ch)) {
formatted = trimRight(formatted);
formatted += '\n';
appendIndent();
formatted += ch;
state = State.Property;
continue;
}
formatted += ch;
continue;
} if (state === State.Property) { // ':' concludes the property.
if (ch === ':') {
formatted = trimRight(formatted);
formatted += ': ';
state = State.Expression;
if (isWhitespace(ch2)) {
state = State.Separator;
}
continue;
} // '}' finishes the ruleset.
if (ch === '}') {
closeBlock();
state = State.Start;
if (depth > 0) {
state = State.Block;
}
continue;
} formatted += ch;
continue;
} if (state === State.Separator) { // Non-whitespace starts the expression.
if (!isWhitespace(ch)) {
formatted += ch;
state = State.Expression;
continue;
} // Anticipate string literal.
if (isQuote(ch2)) {
state = State.Expression;
} continue;
} if (state === State.Expression) { // '}' finishes the ruleset.
if (ch === '}') {
closeBlock();
state = State.Start;
if (depth > 0) {
state = State.Block;
}
continue;
} // ';' completes the declaration.
if (ch === ';') {
formatted = trimRight(formatted);
formatted += ';\n';
state = State.Ruleset;
continue;
} formatted += ch; if (ch === '(') {
if (formatted.charAt(formatted.length - 2) === 'l' &&
formatted.charAt(formatted.length - 3) === 'r' &&
formatted.charAt(formatted.length - 4) === 'u') { // URL starts with '(' and closes with ')'.
state = State.URL;
continue;
}
} continue;
} if (state === State.URL) { // ')' finishes the URL (only if it is not escaped).
if (ch === ')' && formatted.charAt(formatted.length - 1 !== '\\')) {
formatted += ch;
state = State.Expression;
continue;
}
} // The default action is to copy the character (to prevent
// infinite loop).
formatted += ch;
} formatted = blocks.join('') + formatted; return formatted;
}
if (typeof exports !== 'undefined') {
// Node.js module.
module.exports = exports = cssbeautify;
} else if (typeof window === 'object') {
// Browser loading.
window.cssbeautify = cssbeautify;
} }()); sArgs = [
['&A\tAbout This Plugin'],
['',''],
['\t--Replace selection--',''],
['',''],
['&1\tIndent size: 1 Tab' , {indent: '\t'} , 'Replace'],
['&2\tIndent size: 2 Spaces', {indent: " "} , 'Replace'],
['&3\tIndent size: 4 Spaces', {indent: " "}, 'Replace'],
['',''],
['\t--Output in Output Bar--',''],
['',''],
['&4\tIndent size: 1 Tab' , {indent: "\t"} , 'OutputBar'],
['&5\tIndent size: 2 Spaces', {indent: " "} , 'OutputBar'],
['&6\tIndent size: 4 Spaces', {indent: " "}, 'OutputBar'],
['',''],
['\t--Output in new file--',''],
['',''],
['&7\tIndent size: 1 Tab' , {indent: "\t"} , 'NewFile'],
['&8\tIndent size: 2 Spaces', {indent: " "} , 'NewFile'],
['&9\tIndent size: 4 Spaces', {indent: " "}, 'NewFile']
]; menu = CreatePopupMenu(); for (i = 0; i != sArgs.length; i++) {
if (sArgs[i][0] != '') {
menu.Add(sArgs[i][0], i + 1);
}
else {
menu.Add('', 0, eeMenuSeparator);
}
}
result = menu.Track(0); if (result != 0) {
if (result == 1) {
alert('宏作者:阿良\nMacro Author: Arliang\nマクロのさくしゃ:りょう\nhttp://arliang.cnblogs.com/\n2014-07-21 18:21:00');
Quit();
}
var source = document.selection.Text;
if (!source) {
document.selection.SelectAll();
source = document.selection.Text;
} if (source) {
var beautified = window.cssbeautify(source, sArgs[result - 1][1]); if (beautified && beautified != source) {
if (sArgs[result - 1].length > 2) {
switch (sArgs[result - 1][2].toLowerCase()) {
case 'replace':
document.write(beautified);
break; case 'newfile':
editor.NewFile();
document.write(beautified);
break; case 'outputbar':
OutputBar.Clear();
OutputBar.writeln(beautified);
OutputBar.Visible = true;
OutputBar.SetFocus();
break;
}
document.ConfigName = "CSS";
}
}
}
}

js_beautifier && css_beautifier for emeditor的更多相关文章

  1. 用EmEditor实现PDF转Word后的对齐排版

    Redraw = false//禁止重绘(类似于VBA中的: Application.screenupdating=FALSE),以提高运行效率 //去除所有空行和只由空白字符构成的行 documen ...

  2. Emeditor批量修改文件编码格式(UTF-8)

    采用宏的形式进行,直接在Emeidor导入宏即可使用: emeditor导入宏:[宏]->[自定义]->[新建]->找到EncodingChange.jsee文件即可. 链接:htt ...

  3. EmEditor处理大文本文件

    前段时间新闻网由于用户不当操作.导致三年的报纸栏目内容全部清空.紧急情况下只能求助于SQL数据恢复.但备份的数据文件有500M左右. 首先用的文本编辑器是Notepad++,打开之后软件几乎完全卡死. ...

  4. 黄聪:Emeditor 编辑器常用的正则表达式

    Emeditor 目前来说是我个人感觉非常不错的一款记事本软件, 其中查找替换功能由于支持正则表达式而显得非常强大. <tr[^>]*> 匹配:<tr xxxxxxxxxxxx ...

  5. Emeditor所有快捷键操作

    新建文本    Ctrl+N         创建一个新的文本文件. 打开         Ctrl+O    打开一个已存在的文件. 保存         Ctrl+S     保存当前文件. 重新 ...

  6. 将EmEditor加入到鼠标右键菜单

    在清理系统的时候,无意中将EmEditor的鼠标右键功能给清理掉了,在EmEditor的配置中又没有找到如何加入到鼠标右键菜单的方法,只好使用导入注册表功能了,以下的代码,拷贝到记事本中,保存为EmE ...

  7. emeditor只显示特定类型的文件

    emeditor过滤文件类型,右侧资源管理器中只显示特定类型的文件,如只显示java,xml,txt,properties等文件,而不显示doc,jpg,xls等emeditor不能打开的文件. 右击 ...

  8. emeditor 配置教程

    1.众多的图形界面配置功能 通过查看EmEditor的安装目录,可以发现,EmEditor有几个配置文件,理论上应该可以通过修改配置文件来达到配置EmEditor的目 的.然而,打开配置文件一看,如果 ...

  9. 让Emeditor支持markdown编辑博客

    让Emeditor支持markdown编辑博客 1. 关于高亮显示 2.生成HTML文件并预览 用惯了Emeditor,最近又开始学习用markdown写博客,怎么让Emeditor支持markdow ...

随机推荐

  1. dubbo源码分析1——负载均衡

    dubbo中涉及到的负载均衡算法只要有四种:Random LoadBalance(随机均衡算法).RoundRobin LoadBalance(权重轮循均衡算法).LeastAction LoadBa ...

  2. lintcode-511-交换链表当中两个节点

    511-交换链表当中两个节点 给你一个链表以及两个权值v1和v2,交换链表中权值为v1和v2的这两个节点.保证链表中节点权值各不相同,如果没有找到对应节点,那么什么也不用做. 注意事项 你需要交换两个 ...

  3. 【第二周】Java实现英语文章词频统计(改进1)

    本周根据杨老师的spec对英语文章词频统计进行了改进 1.需求分析: 对英文文章中的英文单词进行词频统计并按照有大到小的顺序输出, 2.算法思想: (1)构建一个类用于存放英文单词及其出现的次数 cl ...

  4. 个人项目----词频统计WEB(部分功能)

    需求分析 1.使用web上传txt文件,对上传的txt进行词频统计. 2.将统计后的结果输出到web页面,力求界面优美. 3.在界面上展示所给url的文章词频统计,力求界面优美. 3.将每个单词同四. ...

  5. ant build.xml 解释!

    Ant的概念  Make命令是一个项目管理工具,而Ant所实现功能与此类似.像make,gnumake和nmake这些编译工具都有一定的缺陷,但是Ant却克服了这些工具的缺陷.最初Ant开发者在开发跨 ...

  6. Kettle 使用Json输入

    import java.math.BigDecimal; private static final String JD="jd"; private static final Str ...

  7. 【Linux】- 对find,xargs,grep和管道的一些理解

    问题 相信大家都知道在目录中搜索含有固定字符串文件的命令: find . -name '*.py' |xargs grep test 刚开始的时候,我不熟悉xargs命令,所以直接使用的命令是: fi ...

  8. Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错,

    Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错, 这里总结一些可能的原因和解决方案,给需要的朋友: 说道undefined reference err ...

  9. socket与TCP/UDP编程~

    ket接口是TCP/IP网络的API,Socket接口定义了许多函数或例程,程序员可以用它们来开发TCP/IP网络上的应用程序.要学Internet上的TCP/IP网络编程,必须理解Socket接口. ...

  10. 【bzoj3697】采药人的路径 树的点分治

    题目描述 给出一棵 $n$ 个点的树,每条边的边权为1或0.求有多少点对 $(i,j)$ ,使得:$i$ 到 $j$ 的简单路径上存在点 $k$ (异于 $i$ 和 $j$ ),使得 $i$ 到 $k ...