@idomatic/parser-html 1.0.42 → 1.0.43
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/CHANGELOG.md +13 -0
- package/consts/index.js +2 -1
- package/index.js +1 -2
- package/package.json +1 -2
- package/utils/index.js +6 -15
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.0.43] - 2024-12-22
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Fixed HTML parser import/export bug where `templateRegex` was not properly exported from consts/index.js
|
|
7
|
+
- Resolved module loading issues that prevented proper functionality
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Updated import statement to use correct export name (`TEMPLATE_REGEX as templateRegex`)
|
|
11
|
+
|
|
12
|
+
## [1.0.42] - Previous releases
|
|
13
|
+
- Previous functionality and features
|
package/consts/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const TEMPLATE_REGEX = /<template(?:\s[^>]*)?>([\s\S]*?)<\/template>/i;
|
|
2
|
+
export const TAG_REGEX = /<([a-zA-Z][^\s/>]*)([^>]*?)(\/?)>/g;
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { templateRegex } from "./consts/index.js";
|
|
3
|
+
import { TEMPLATE_REGEX as templateRegex } from "./consts/index.js";
|
|
4
4
|
import { processHtmlContent, processVueTemplate } from "./utils/index.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -18,7 +18,6 @@ export default async function parseHTML(filePath, config, dry = false) {
|
|
|
18
18
|
let updatedContent = originalContent;
|
|
19
19
|
|
|
20
20
|
if (ext === ".vue") {
|
|
21
|
-
// Process Vue <template> tag contents using MagicString-based approach
|
|
22
21
|
const match = originalContent.match(templateRegex);
|
|
23
22
|
if (match) {
|
|
24
23
|
const newTemplate = processVueTemplate(match[1], config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idomatic/parser-html",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"description": "HTML/Vue/Angular parser for idomatic CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"author": "Amar Smajlovic",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"cheerio": "^1.0.0-rc.12",
|
|
21
20
|
"magic-string": "^0.30.17"
|
|
22
21
|
}
|
|
23
22
|
}
|
package/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
|
+
import { TAG_REGEX } from "../consts/index.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Processes a Vue template content by inserting unique IDs while preserving formatting.
|
|
@@ -15,27 +16,18 @@ export function processVueTemplate(templateContent, config) {
|
|
|
15
16
|
const { attributeName, prefix, excludeTags = [] } = config;
|
|
16
17
|
const ms = new MagicString(templateContent);
|
|
17
18
|
|
|
18
|
-
// A generic regex to match opening tags:
|
|
19
|
-
// - It captures the tag name and its attributes.
|
|
20
|
-
// - This regex is simplified, so you might need additional adjustments for complex cases.
|
|
21
|
-
const tagRegex = /<([a-zA-Z][^\s/>]*)([^>]*?)(\/?)>/g;
|
|
22
|
-
|
|
23
19
|
let match;
|
|
24
|
-
while ((match =
|
|
25
|
-
const fullMatch = match[0];
|
|
26
|
-
const tagName = match[1];
|
|
27
|
-
const attributesStr = match[2];
|
|
28
|
-
const selfClosing = match[3] || "";
|
|
20
|
+
while ((match = TAG_REGEX.exec(templateContent)) !== null) {
|
|
21
|
+
const fullMatch = match[0];
|
|
22
|
+
const tagName = match[1];
|
|
23
|
+
const attributesStr = match[2];
|
|
24
|
+
const selfClosing = match[3] || "";
|
|
29
25
|
|
|
30
|
-
// If the tag is in the exclude list, skip processing.
|
|
31
26
|
if (excludeTags.includes(tagName)) continue;
|
|
32
27
|
|
|
33
|
-
// Check if this tag already has the attribute
|
|
34
28
|
const idRegex = new RegExp(`\\s${attributeName}\\s*=`);
|
|
35
29
|
if (idRegex.test(attributesStr)) continue;
|
|
36
30
|
|
|
37
|
-
// Insert the attribute just before the closing of the tag.
|
|
38
|
-
// We subtract the length of any trailing self-closing slash and the ">" character.
|
|
39
31
|
const insertPosition =
|
|
40
32
|
match.index + fullMatch.length - (selfClosing.length + 1);
|
|
41
33
|
ms.appendLeft(
|
|
@@ -51,7 +43,6 @@ export function processHtmlContent(htmlContent, config) {
|
|
|
51
43
|
const { attributeName, prefix, excludeTags = [] } = config;
|
|
52
44
|
const ms = new MagicString(htmlContent);
|
|
53
45
|
|
|
54
|
-
// This regex is similar to the Vue one.
|
|
55
46
|
const tagRegex = /<([a-zA-Z][^\s/>]*)([^>]*?)(\/?)>/g;
|
|
56
47
|
let match;
|
|
57
48
|
while ((match = tagRegex.exec(htmlContent)) !== null) {
|