HTML-JavaScript.html.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. function eachWithIdx(iterable, f) {
  2. var i = iterable.iterator();
  3. var idx = 0;
  4. while (i.hasNext()) f(i.next(), idx++);
  5. }
  6. function mapEach(iterable, f) {
  7. var vs = [];
  8. eachWithIdx(iterable, function (i) {
  9. vs.push(f(i));
  10. });
  11. return vs;
  12. }
  13. function escape(str) {
  14. str = str.replaceAll("\t|\b|\\f", "");
  15. str = com.intellij.openapi.util.text.StringUtil.escapeXml(str);
  16. str = str.replaceAll("\\r|\\n|\\r\\n", "<br/>");
  17. return str;
  18. }
  19. var NEWLINE = "\n";
  20. function output() {
  21. for (var i = 0; i < arguments.length; i++) {
  22. OUT.append(arguments[i]);
  23. }
  24. }
  25. function outputRow(items, tag) {
  26. output("<tr>");
  27. for (var i = 0; i < items.length; i++)
  28. output("<", tag, ">", escape(items[i]), "</", tag, ">");
  29. output("</tr>", NEWLINE);
  30. }
  31. output("<!DOCTYPE html>", NEWLINE,
  32. "<html>", NEWLINE,
  33. "<head>", NEWLINE,
  34. "<title></title>", NEWLINE,
  35. "</head>", NEWLINE,
  36. "<body>", NEWLINE,
  37. "<table border=\"1\" style=\"border-collapse:collapse\">", NEWLINE);
  38. if (TRANSPOSED) {
  39. var values = mapEach(COLUMNS, function (col) {
  40. return [col.name()];
  41. });
  42. eachWithIdx(ROWS, function (row) {
  43. eachWithIdx(COLUMNS, function (col, i) {
  44. values[i].push(FORMATTER.format(row, col));
  45. });
  46. });
  47. eachWithIdx(COLUMNS, function (_, i) {
  48. outputRow(values[i], "td");
  49. });
  50. } else {
  51. outputRow(mapEach(COLUMNS, function (col) {
  52. return col.name();
  53. }), "th");
  54. eachWithIdx(ROWS, function (row) {
  55. outputRow(mapEach(COLUMNS, function (col) {
  56. return FORMATTER.format(row, col);
  57. }), "td")
  58. });
  59. }
  60. output("</table>", NEWLINE,
  61. "</body>", NEWLINE,
  62. "</html>", NEWLINE);