@platecms/delta-cast-util-to-html 0.6.0 → 0.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platecms/delta-cast-util-to-html",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Utility to convert CAST directly to HTML using HAST and HAST sanitizing.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -17,9 +17,9 @@
17
17
  "src/**/*"
18
18
  ],
19
19
  "dependencies": {
20
- "@platecms/delta-cast": "0.6.0",
21
- "@platecms/delta-cast-util-to-hast": "0.6.0",
22
- "@platecms/delta-plate-resource-notation": "0.6.0",
20
+ "@platecms/delta-cast": "0.8.0",
21
+ "@platecms/delta-cast-util-to-hast": "0.8.0",
22
+ "@platecms/delta-plate-resource-notation": "0.8.0",
23
23
  "class-transformer": "0.5.1",
24
24
  "hast": "1.0.0",
25
25
  "hast-util-sanitize": "5.0.2",
@@ -28,6 +28,5 @@
28
28
  "reflect-metadata": "0.2.2",
29
29
  "tslib": "2.8.1",
30
30
  "zwitch": "2.0.4"
31
- },
32
- "type": "commonjs"
31
+ }
33
32
  }
@@ -0,0 +1,15 @@
1
+ import { c } from "@platecms/delta-castscript";
2
+ import { toHtml } from "./index";
3
+
4
+ describe("cast-util-to-html", () => {
5
+ it("should convert a Cast Tree to HTML", () => {
6
+ // Arrange
7
+ const cast = c("root", [c("paragraph", "Hello, world!")]);
8
+
9
+ // Act
10
+ const html = toHtml(cast);
11
+
12
+ // Assert
13
+ expect(html).toBe("<p>Hello, world!</p>");
14
+ });
15
+ });
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { Root } from "@platecms/delta-cast";
2
+ import { NodeTransformers, flattenTextOnlyContentValueNode, toHast } from "@platecms/delta-cast-util-to-hast";
3
+ import { sanitize } from "hast-util-sanitize";
4
+ import { toHtml as hastToHtml } from "hast-util-to-html";
5
+
6
+ /*
7
+ * Convert a Cast Tree to HTML by first converting it to a Hast Tree and then to HTML.
8
+ * Sanitizes the Hast Tree to prevent XSS attacks.
9
+ *
10
+ * @param value - Cast Tree
11
+ * @returns HTML string
12
+ */
13
+ export function toHtml(
14
+ value: Root,
15
+ transform: NodeTransformers = {
16
+ contentValue: flattenTextOnlyContentValueNode,
17
+ },
18
+ ): string {
19
+ return hastToHtml(sanitize(toHast(value, transform)));
20
+ }
package/src/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Root } from "@platecms/delta-cast";
2
- import { NodeTransformers } from "@platecms/delta-cast-util-to-hast";
3
- export declare function toHtml(value: Root, transform?: NodeTransformers): string;
package/src/index.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHtml = toHtml;
4
- const delta_cast_util_to_hast_1 = require("@platecms/delta-cast-util-to-hast");
5
- const hast_util_sanitize_1 = require("hast-util-sanitize");
6
- const hast_util_to_html_1 = require("hast-util-to-html");
7
- function toHtml(value, transform = {
8
- contentValue: delta_cast_util_to_hast_1.flattenTextOnlyContentValueNode,
9
- }) {
10
- return (0, hast_util_to_html_1.toHtml)((0, hast_util_sanitize_1.sanitize)((0, delta_cast_util_to_hast_1.toHast)(value, transform)));
11
- }
12
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/cast-util-to-html/src/index.ts"],"names":[],"mappings":";;AAYA,wBAOC;AAlBD,+EAA8G;AAC9G,2DAA8C;AAC9C,yDAAyD;AASzD,SAAgB,MAAM,CACpB,KAAW,EACX,YAA8B;IAC5B,YAAY,EAAE,yDAA+B;CAC9C;IAED,OAAO,IAAA,0BAAU,EAAC,IAAA,6BAAQ,EAAC,IAAA,gCAAM,EAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}