@idomatic/parser-html 1.0.0
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/index.js +22 -0
- package/package.json +22 -0
package/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import cheerio from "cheerio";
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
4
|
+
|
|
5
|
+
export default async function parseHTML(filePath, config) {
|
|
6
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
7
|
+
const $ = cheerio.load(content, { xmlMode: false });
|
|
8
|
+
|
|
9
|
+
$("*").each((_, el) => {
|
|
10
|
+
const tag = el.tagName;
|
|
11
|
+
|
|
12
|
+
if (config.skipTags.includes(tag)) return;
|
|
13
|
+
|
|
14
|
+
const hasId = $(el).attr("id");
|
|
15
|
+
|
|
16
|
+
if (!hasId) {
|
|
17
|
+
$(el).attr("id", `${config.prefix}${randomUUID()}`);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
fs.writeFileSync(filePath, $.html());
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@idomatic/parser-html",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "HTML/Vue/Angular parser for idomatic CLI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"default": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"idomatic",
|
|
12
|
+
"parser",
|
|
13
|
+
"html",
|
|
14
|
+
"vue",
|
|
15
|
+
"angular"
|
|
16
|
+
],
|
|
17
|
+
"author": "Amar Smajlovic",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"cheerio": "^1.0.0-rc.12"
|
|
21
|
+
}
|
|
22
|
+
}
|