@nerimity/html-embed 1.1.9 → 1.1.11
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/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/example.js +3 -1
- package/package.json +21 -21
- package/src/index.ts +10 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8HA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM;;;;;;;;IAEtC"}
|
package/dist/index.js
CHANGED
|
@@ -111,6 +111,11 @@ function h(tag, props, ...children) {
|
|
|
111
111
|
throw new Error(unsafeCssProperty.split(":")[0].trim() + " property is not allowed!");
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
if (props === null || props === void 0 ? void 0 : props.href) {
|
|
115
|
+
if (!props.href.startsWith("http://") && !props.href.startsWith("https://")) {
|
|
116
|
+
throw new Error("href must start with http:// or https://");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
114
119
|
if (tag.toLowerCase() === "style" && children[0]) {
|
|
115
120
|
checkCSS(children[0]);
|
|
116
121
|
}
|
|
@@ -122,6 +127,11 @@ function htmlToJson(html) {
|
|
|
122
127
|
}
|
|
123
128
|
function checkCSS(cssVal) {
|
|
124
129
|
var _a;
|
|
130
|
+
const openCurlyBracketCount = cssVal.match(/{/gi);
|
|
131
|
+
const closeCurlyBracketCount = cssVal.match(/}/gi);
|
|
132
|
+
if ((openCurlyBracketCount === null || openCurlyBracketCount === void 0 ? void 0 : openCurlyBracketCount.length) !== (closeCurlyBracketCount === null || closeCurlyBracketCount === void 0 ? void 0 : closeCurlyBracketCount.length)) {
|
|
133
|
+
throw new Error("Extra curly or missing curly brackets found in css!");
|
|
134
|
+
}
|
|
125
135
|
const rules = (_a = css_1.default.parse(cssVal).stylesheet) === null || _a === void 0 ? void 0 : _a.rules;
|
|
126
136
|
if (!rules)
|
|
127
137
|
return;
|
package/example.js
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nerimity/html-embed",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@nerimity/html-embed",
|
|
3
|
+
"version": "1.1.11",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"author": "",
|
|
8
|
+
"license": "ISC",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/css": "^0.0.37",
|
|
11
|
+
"typescript": "^5.5.2"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"css": "^3.0.0",
|
|
15
|
+
"htm": "^3.1.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"example": "tsc & node example.js"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -108,6 +108,11 @@ function h(tag: string, props: any, ...children: any[]) {
|
|
|
108
108
|
throw new Error(unsafeCssProperty.split(":")[0].trim() +" property is not allowed!")
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
if (props?.href) {
|
|
112
|
+
if (!props.href.startsWith("http://") && !props.href.startsWith("https://")) {
|
|
113
|
+
throw new Error("href must start with http:// or https://")
|
|
114
|
+
}
|
|
115
|
+
}
|
|
111
116
|
if (tag.toLowerCase() === "style" && children[0]) {
|
|
112
117
|
checkCSS(children[0]);
|
|
113
118
|
}
|
|
@@ -126,6 +131,11 @@ export function htmlToJson(html: string) {
|
|
|
126
131
|
|
|
127
132
|
|
|
128
133
|
function checkCSS(cssVal: string) {
|
|
134
|
+
const openCurlyBracketCount = cssVal.match(/{/gi)
|
|
135
|
+
const closeCurlyBracketCount = cssVal.match(/}/gi)
|
|
136
|
+
if (openCurlyBracketCount?.length !== closeCurlyBracketCount?.length) {
|
|
137
|
+
throw new Error("Extra curly or missing curly brackets found in css!")
|
|
138
|
+
}
|
|
129
139
|
const rules = css.parse(cssVal).stylesheet?.rules;
|
|
130
140
|
if (!rules) return;
|
|
131
141
|
for (let i = 0; i < rules.length; i++) {
|