@rhseung/ps-cli 1.9.1 → 1.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,6 @@ import {
8
8
  CommandDef,
9
9
  __decorateClass,
10
10
  defineFlags,
11
- findSolutionFile,
12
11
  getEditor,
13
12
  logger,
14
13
  resolveProblemContext
@@ -242,13 +241,7 @@ var OpenCommand = class extends Command {
242
241
  return;
243
242
  }
244
243
  const mode = flags.editor ? "editor" : "browser";
245
- let problemPath = context.archiveDir;
246
- if (flags.editor) {
247
- try {
248
- problemPath = await findSolutionFile(context.archiveDir);
249
- } catch {
250
- }
251
- }
244
+ const problemPath = context.archiveDir;
252
245
  await this.renderView(OpenView, {
253
246
  problemId: context.problemId,
254
247
  problemDir: problemPath,
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  getProblem,
4
4
  scrapeProblem
5
- } from "./chunk-LR64BN3N.js";
5
+ } from "./chunk-YCFY6UCA.js";
6
6
  import {
7
7
  Command,
8
8
  CommandBuilder,
@@ -59,6 +59,117 @@ async function fetchWithRetry(url, context) {
59
59
  // src/services/scraper.ts
60
60
  var BOJ_BASE_URL = "https://www.acmicpc.net";
61
61
  var SOLVED_AC_BASE_URL = "https://solved.ac";
62
+ function tableToMarkdown($, $table) {
63
+ const rows = [];
64
+ let maxCols = 0;
65
+ const thead = $table.find("thead");
66
+ if (thead.length > 0) {
67
+ thead.find("tr").each((_, tr) => {
68
+ const $tr = $(tr);
69
+ const cells = [];
70
+ const cellElements = $tr.find("th, td");
71
+ if (cellElements.length > 0) {
72
+ cellElements.each((_2, cell) => {
73
+ const cellContent = htmlToMarkdown($, $(cell)).trim().replace(/\n/g, " ").replace(/\|/g, "\\|");
74
+ cells.push(cellContent || " ");
75
+ });
76
+ } else {
77
+ const trText = $tr.text().trim();
78
+ if (trText) {
79
+ const textCells = trText.split(/\s+/).filter((v) => v.length > 0);
80
+ textCells.forEach((cellText) => {
81
+ cells.push(cellText.replace(/\|/g, "\\|"));
82
+ });
83
+ }
84
+ }
85
+ if (cells.length > 0) {
86
+ rows.push(cells);
87
+ maxCols = Math.max(maxCols, cells.length);
88
+ }
89
+ });
90
+ }
91
+ const tbody = $table.find("tbody");
92
+ if (tbody.length > 0) {
93
+ tbody.find("tr").each((_, tr) => {
94
+ const $tr = $(tr);
95
+ const cells = [];
96
+ const cellElements = $tr.find("td, th");
97
+ if (cellElements.length > 0) {
98
+ cellElements.each((_2, cell) => {
99
+ const cellContent = htmlToMarkdown($, $(cell)).trim().replace(/\n/g, " ").replace(/\|/g, "\\|");
100
+ cells.push(cellContent || " ");
101
+ });
102
+ } else {
103
+ const trText = $tr.text().trim();
104
+ if (trText) {
105
+ const textCells = trText.split(/\s+/).filter((v) => v.length > 0);
106
+ textCells.forEach((cellText) => {
107
+ cells.push(cellText.replace(/\|/g, "\\|"));
108
+ });
109
+ }
110
+ }
111
+ if (cells.length > 0) {
112
+ rows.push(cells);
113
+ maxCols = Math.max(maxCols, cells.length);
114
+ }
115
+ });
116
+ }
117
+ if (rows.length === 0) {
118
+ $table.find("tr").each((_, tr) => {
119
+ const $tr = $(tr);
120
+ const cells = [];
121
+ const cellElements = $tr.find("th, td");
122
+ if (cellElements.length > 0) {
123
+ cellElements.each((_2, cell) => {
124
+ const cellContent = htmlToMarkdown($, $(cell)).trim().replace(/\n/g, " ").replace(/\|/g, "\\|");
125
+ cells.push(cellContent || " ");
126
+ });
127
+ } else {
128
+ const trText = $tr.text().trim();
129
+ if (trText) {
130
+ const textCells = trText.split(/\s+/).filter((v) => v.length > 0);
131
+ textCells.forEach((cellText) => {
132
+ cells.push(cellText.replace(/\|/g, "\\|"));
133
+ });
134
+ }
135
+ }
136
+ if (cells.length > 0) {
137
+ rows.push(cells);
138
+ maxCols = Math.max(maxCols, cells.length);
139
+ }
140
+ });
141
+ }
142
+ if (rows.length === 0 || maxCols === 0) {
143
+ return "";
144
+ }
145
+ rows.forEach((row) => {
146
+ while (row.length < maxCols) {
147
+ row.push(" ");
148
+ }
149
+ });
150
+ const markdownRows = [];
151
+ const hasHeader = thead.length > 0 || rows.length > 0 && $table.find("tr").first().find("th").length > 0;
152
+ if (hasHeader && rows.length > 0) {
153
+ const headerRow = `| ${rows[0].join(" | ")} |`;
154
+ markdownRows.push(headerRow);
155
+ const separator = `|${"---|".repeat(maxCols)}`;
156
+ markdownRows.push(separator);
157
+ for (let i = 1; i < rows.length; i++) {
158
+ markdownRows.push(`| ${rows[i].join(" | ")} |`);
159
+ }
160
+ } else {
161
+ if (rows.length > 0) {
162
+ const headerRow = `| ${rows[0].join(" | ")} |`;
163
+ markdownRows.push(headerRow);
164
+ const separator = `|${"---|".repeat(maxCols)}`;
165
+ markdownRows.push(separator);
166
+ for (let i = 1; i < rows.length; i++) {
167
+ markdownRows.push(`| ${rows[i].join(" | ")} |`);
168
+ }
169
+ }
170
+ }
171
+ return markdownRows.length > 0 ? markdownRows.join("\n") + "\n\n" : "";
172
+ }
62
173
  function htmlToMarkdown($, element) {
63
174
  if (element.length === 0) return "";
64
175
  let result = "";
@@ -75,6 +186,11 @@ function htmlToMarkdown($, element) {
75
186
  } else if (node.type === "tag") {
76
187
  const tagName = node.name.toLowerCase();
77
188
  const $node = $(node);
189
+ if (tagName === "thead" || tagName === "tbody" || tagName === "tr" || tagName === "th" || tagName === "td") {
190
+ if ($node.parent().is("table") || $node.closest("table").length > 0) {
191
+ return;
192
+ }
193
+ }
78
194
  switch (tagName) {
79
195
  case "sup":
80
196
  result += `^${htmlToMarkdown($, $node)}`;
@@ -139,6 +255,23 @@ ${preContent}
139
255
  case "li":
140
256
  result += htmlToMarkdown($, $node);
141
257
  break;
258
+ case "table": {
259
+ const tableContent = tableToMarkdown($, $node);
260
+ if (tableContent) {
261
+ result += tableContent;
262
+ }
263
+ break;
264
+ }
265
+ case "thead":
266
+ case "tbody":
267
+ case "tr":
268
+ case "th":
269
+ case "td":
270
+ if ($node.closest("table").not($node).length > 0) {
271
+ break;
272
+ }
273
+ result += htmlToMarkdown($, $node);
274
+ break;
142
275
  case "img": {
143
276
  const imgSrc = $node.attr("src") || "";
144
277
  const imgAlt = $node.attr("alt") || "\uC774\uBBF8\uC9C0";
@@ -3,8 +3,8 @@ import {
3
3
  FetchCommand,
4
4
  FetchView,
5
5
  fetch_default
6
- } from "../chunk-INRLWS2O.js";
7
- import "../chunk-LR64BN3N.js";
6
+ } from "../chunk-M4LNYKJF.js";
7
+ import "../chunk-YCFY6UCA.js";
8
8
  import "../chunk-Q5NECGFA.js";
9
9
  export {
10
10
  FetchCommand,
@@ -3,7 +3,7 @@ import {
3
3
  OpenCommand,
4
4
  OpenView,
5
5
  open_default
6
- } from "../chunk-OBO5XU4N.js";
6
+ } from "../chunk-AHVAVNFM.js";
7
7
  import "../chunk-QGMWUOJ3.js";
8
8
  import "../chunk-Q5NECGFA.js";
9
9
  export {
@@ -10,15 +10,15 @@ import {
10
10
  } from "../chunk-457JZK3K.js";
11
11
  import {
12
12
  FetchView
13
- } from "../chunk-INRLWS2O.js";
13
+ } from "../chunk-M4LNYKJF.js";
14
14
  import {
15
15
  fetchWithRetry,
16
16
  getProblem,
17
17
  searchProblems
18
- } from "../chunk-LR64BN3N.js";
18
+ } from "../chunk-YCFY6UCA.js";
19
19
  import {
20
20
  OpenView
21
- } from "../chunk-OBO5XU4N.js";
21
+ } from "../chunk-AHVAVNFM.js";
22
22
  import "../chunk-QGMWUOJ3.js";
23
23
  import "../chunk-YZUGYJA4.js";
24
24
  import {
@@ -5,7 +5,7 @@ import {
5
5
  getUserTagRatings,
6
6
  getUserTop100,
7
7
  scrapeUserStats
8
- } from "../chunk-LR64BN3N.js";
8
+ } from "../chunk-YCFY6UCA.js";
9
9
  import {
10
10
  Command,
11
11
  CommandBuilder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhseung/ps-cli",
3
- "version": "1.9.1",
3
+ "version": "1.9.8",
4
4
  "description": "백준(BOJ) 문제 해결을 위한 통합 CLI 도구",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,9 @@
22
22
  "check": "prettier --write . && eslint --fix",
23
23
  "patch": "npm version patch && bun publish --access=public",
24
24
  "minor": "npm version minor && bun publish --access=public",
25
- "major": "npm version major && bun publish --access=public"
25
+ "major": "npm version major && bun publish --access=public",
26
+ "unlink": "npm unlink -g @rhseung/ps-cli",
27
+ "prepare": "husky || true"
26
28
  },
27
29
  "keywords": [
28
30
  "boj",
@@ -44,6 +46,7 @@
44
46
  "dependencies": {
45
47
  "@inkjs/ui": "^2.0.0",
46
48
  "@pppp606/ink-chart": "^0.2.4",
49
+ "@rhseung/ps-cli": "^1.9.1",
47
50
  "@types/gradient-string": "^1.1.6",
48
51
  "chalk": "^5.3.0",
49
52
  "cheerio": "^1.0.0",
@@ -58,15 +61,16 @@
58
61
  "devDependencies": {
59
62
  "@types/node": "^22.10.2",
60
63
  "@types/react": "^18.3.12",
61
- "tsup": "^8.3.5",
62
- "typescript": "^5.7.2",
63
- "typescript-eslint": "^8.50.1",
64
64
  "eslint-config-prettier": "^10.1.8",
65
65
  "eslint-plugin-import": "^2.32.0",
66
66
  "eslint-plugin-prettier": "^5.5.4",
67
67
  "eslint-plugin-react-hooks": "^7.0.1",
68
68
  "eslint-plugin-react-refresh": "^0.4.26",
69
- "globals": "^16.5.0"
69
+ "globals": "^16.5.0",
70
+ "husky": "^9.1.7",
71
+ "tsup": "^8.3.5",
72
+ "typescript": "^5.7.2",
73
+ "typescript-eslint": "^8.50.1"
70
74
  },
71
75
  "engines": {
72
76
  "node": ">=18.0.0"