@nerimity/html-embed 1.1.13 → 1.1.14
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 +4 -0
- package/example.js +1 -1
- package/package.json +3 -1
- package/src/index.ts +4 -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":"AAiIA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM;;;;;;;;IAEtC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.htmlToJson = htmlToJson;
|
|
7
7
|
const htm_1 = __importDefault(require("htm"));
|
|
8
8
|
const css_1 = __importDefault(require("css"));
|
|
9
|
+
const { validate } = require("csstree-validator");
|
|
9
10
|
const allowedTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'img', 'span', 'strong', 'a', "style", "p", "ul", "li", "ol", "table", "thead", "tbody", "tr", "td", "th", "blockquote", "pre", "br"];
|
|
10
11
|
const allowedAttributes = ["href", "src", "color", "style", "class"];
|
|
11
12
|
const allowedCssProperties = [
|
|
@@ -129,6 +130,9 @@ function htmlToJson(html) {
|
|
|
129
130
|
}
|
|
130
131
|
function checkCSS(cssVal) {
|
|
131
132
|
var _a;
|
|
133
|
+
if (validate(cssVal).length) {
|
|
134
|
+
throw new Error("Invalid css!");
|
|
135
|
+
}
|
|
132
136
|
const openCurlyBracketCount = cssVal.match(/{/gi);
|
|
133
137
|
const closeCurlyBracketCount = cssVal.match(/}/gi);
|
|
134
138
|
if ((openCurlyBracketCount === null || openCurlyBracketCount === void 0 ? void 0 : openCurlyBracketCount.length) !== (closeCurlyBracketCount === null || closeCurlyBracketCount === void 0 ? void 0 : closeCurlyBracketCount.length)) {
|
package/example.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nerimity/html-embed",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/css": "^0.0.37",
|
|
15
|
+
"@types/node": "^22.10.10",
|
|
15
16
|
"typescript": "^5.5.2"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"css": "^3.0.0",
|
|
20
|
+
"csstree-validator": "^4.0.1",
|
|
19
21
|
"htm": "^3.1.0"
|
|
20
22
|
}
|
|
21
23
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import htm from 'htm';
|
|
2
2
|
import css from 'css';
|
|
3
|
+
const {validate} = require("csstree-validator")
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
const allowedTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'img', 'span', 'strong', 'a', "style", "p", "ul", "li", "ol", "table", "thead", "tbody", "tr", "td", "th", "blockquote", "pre", "br"]
|
|
@@ -133,6 +134,9 @@ export function htmlToJson(html: string) {
|
|
|
133
134
|
|
|
134
135
|
|
|
135
136
|
function checkCSS(cssVal: string) {
|
|
137
|
+
if (validate(cssVal).length) {
|
|
138
|
+
throw new Error("Invalid css!")
|
|
139
|
+
}
|
|
136
140
|
const openCurlyBracketCount = cssVal.match(/{/gi)
|
|
137
141
|
const closeCurlyBracketCount = cssVal.match(/}/gi)
|
|
138
142
|
if (openCurlyBracketCount?.length !== closeCurlyBracketCount?.length) {
|