25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

condenseMd.js 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. fs = require('fs')
  2. function setupMd(filename, anchor) {
  3. fs.readFile(filename, 'utf8', function (err,text) {
  4. if (err) {
  5. return console.log(err);
  6. }
  7. var lines = text.split("\n"),
  8. cur_line = 0,
  9. line = "",
  10. table_name = "",
  11. col_num = 0,
  12. cols = [],
  13. rows = [],
  14. arr = [];
  15. function read_line() {
  16. return lines[cur_line++];
  17. }
  18. while (true) {
  19. var cols = [];
  20. var rows = [];
  21. while (line.indexOf(anchor) == -1 && cur_line != lines.length) {
  22. line = read_line();
  23. }
  24. if (cur_line == lines.length) {
  25. break;
  26. }
  27. table_name = line.split(anchor)[1];
  28. read_line()
  29. read_line()
  30. while (true) {
  31. line = read_line()
  32. if (line.length < 2 || cur_line == lines.length) {
  33. break
  34. }
  35. if (line.startsWith("|")) {
  36. arr.push(line + table_name)
  37. }
  38. }
  39. }
  40. console.log(anchor + " entries")
  41. console.log("API | Description | Auth | HTTPS | Link | Section")
  42. console.log("|---|---|---|---|---|---|")
  43. for (i = 0; i < arr.length; i++) {
  44. console.log(arr[i])
  45. }
  46. });
  47. }
  48. if (process.argv.length < 3) {
  49. console.log("No .md file passed!");
  50. return;
  51. }
  52. if (process.argv.length < 4) {
  53. anchorText = "###";
  54. } else {
  55. anchorText = process.argv[3];
  56. }
  57. setupMd(process.argv[2].toString(), anchorText);