@auto-wiz/dom 1.0.0 → 1.0.2
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.
- package/dist/steps/stepExecution.js +65 -0
- package/package.json +4 -4
|
@@ -190,6 +190,26 @@ export async function executeExtractStep(step) {
|
|
|
190
190
|
else if (prop === "innerText") {
|
|
191
191
|
extractedData = element.textContent?.trim() || "";
|
|
192
192
|
}
|
|
193
|
+
else if (prop === "outerHTML") {
|
|
194
|
+
// XML 구조를 보기 좋게 포맷팅하기 전에 base64 이미지 제거
|
|
195
|
+
const cloned = element.cloneNode(true);
|
|
196
|
+
const processImage = (img) => {
|
|
197
|
+
const src = img.getAttribute("src");
|
|
198
|
+
if (src && src.startsWith("data:image")) {
|
|
199
|
+
img.removeAttribute("src");
|
|
200
|
+
img.setAttribute("data-image-removed", "true");
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
if (cloned.tagName.toLowerCase() === "img") {
|
|
204
|
+
processImage(cloned);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
const images = cloned.querySelectorAll("img");
|
|
208
|
+
images.forEach((img) => processImage(img));
|
|
209
|
+
}
|
|
210
|
+
const rawHtml = cloned.outerHTML;
|
|
211
|
+
extractedData = formatXml(rawHtml);
|
|
212
|
+
}
|
|
193
213
|
else {
|
|
194
214
|
extractedData = element.textContent?.trim() || "";
|
|
195
215
|
}
|
|
@@ -283,3 +303,48 @@ export async function executeStep(step) {
|
|
|
283
303
|
};
|
|
284
304
|
}
|
|
285
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Simple XML formatter for pretty printing
|
|
308
|
+
*/
|
|
309
|
+
function formatXml(xml) {
|
|
310
|
+
let formatted = "";
|
|
311
|
+
let indent = 0;
|
|
312
|
+
const tab = " ";
|
|
313
|
+
// 태그 사이의 공백 제거 및 줄바꿈 정규화
|
|
314
|
+
// 주석이나 CDATA 등은 고려하지 않은 단순 구현
|
|
315
|
+
xml = xml.replace(/>\s+</g, "><").trim();
|
|
316
|
+
// 태그 단위로 분리 - <tag>, </tag>, <tag ... />, text content
|
|
317
|
+
// 정규식 개선: 태그와 텍스트를 더 정확하게 분리
|
|
318
|
+
// <[^>]+> : 태그
|
|
319
|
+
// [^<]+ : 텍스트
|
|
320
|
+
const tags = xml.match(/<[^>]+>|[^<]+/g) || [];
|
|
321
|
+
tags.forEach(tag => {
|
|
322
|
+
// 닫는 태그 </... >
|
|
323
|
+
if (tag.match(/^<\//)) {
|
|
324
|
+
indent = Math.max(0, indent - 1);
|
|
325
|
+
formatted += "\n" + tab.repeat(indent) + tag;
|
|
326
|
+
}
|
|
327
|
+
// Self-closing 태그 <... /> 또는 <! ... > (Example: <!DOCTYPE>)
|
|
328
|
+
else if (tag.match(/^<.*\/>$/) || tag.match(/^<!/)) {
|
|
329
|
+
if (formatted.length > 0)
|
|
330
|
+
formatted += "\n";
|
|
331
|
+
formatted += tab.repeat(indent) + tag;
|
|
332
|
+
}
|
|
333
|
+
// 여는 태그 <... >
|
|
334
|
+
else if (tag.match(/^<.*>$/)) {
|
|
335
|
+
if (formatted.length > 0)
|
|
336
|
+
formatted += "\n";
|
|
337
|
+
formatted += tab.repeat(indent) + tag;
|
|
338
|
+
indent++;
|
|
339
|
+
}
|
|
340
|
+
// 텍스트 컨텐츠
|
|
341
|
+
else {
|
|
342
|
+
// 텍스트는 줄바꿈 없이 이어붙이되, 내용이 있는 경우만
|
|
343
|
+
const text = tag.trim();
|
|
344
|
+
if (text.length > 0) {
|
|
345
|
+
formatted += text;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return formatted.trim();
|
|
350
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auto-wiz/dom",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "JaeSang",
|
|
6
6
|
"repository": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
+
"type": "module",
|
|
13
14
|
"files": [
|
|
14
15
|
"dist"
|
|
15
16
|
],
|
|
@@ -18,12 +19,11 @@
|
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
20
21
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/index.js"
|
|
22
|
-
"require": "./dist/index.js"
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@auto-wiz/core": "1.0.
|
|
26
|
+
"@auto-wiz/core": "1.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "^5.0.0"
|