HTML-JavaScript.html.js 1.6 KB

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