@constructor-io/constructorio-ui-pia 2.6.2 → 2.6.3

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.
@@ -13,10 +13,16 @@ function sanitizeHtml(html) {
13
13
  return dompurify_1.default.sanitize(html, purifyConfig);
14
14
  }
15
15
  exports.sanitizeHtml = sanitizeHtml;
16
- function renderMarkdown(content) {
16
+ function renderMarkdown(content, options) {
17
+ var _a;
17
18
  if (!content)
18
19
  return '';
19
20
  const html = marked_1.marked.parse(content, { async: false, breaks: true });
21
+ if (options === null || options === void 0 ? void 0 : options.sanitize) {
22
+ const purifier = (0, dompurify_1.default)(window);
23
+ const config = Object.assign(Object.assign({}, purifyConfig), { FORBID_TAGS: [...((_a = purifyConfig.FORBID_TAGS) !== null && _a !== void 0 ? _a : [])] });
24
+ return options.sanitize(purifier, html, { config });
25
+ }
20
26
  return dompurify_1.default.sanitize(html, purifyConfig);
21
27
  }
22
28
  exports.renderMarkdown = renderMarkdown;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '2.6.2';
3
+ exports.default = '2.6.3';
@@ -8,9 +8,14 @@ export function sanitizeHtml(html) {
8
8
  return '';
9
9
  return DOMPurify.sanitize(html, purifyConfig);
10
10
  }
11
- export function renderMarkdown(content) {
11
+ export function renderMarkdown(content, options) {
12
12
  if (!content)
13
13
  return '';
14
14
  const html = marked.parse(content, { async: false, breaks: true });
15
+ if (options?.sanitize) {
16
+ const purifier = DOMPurify(window);
17
+ const config = { ...purifyConfig, FORBID_TAGS: [...(purifyConfig.FORBID_TAGS ?? [])] };
18
+ return options.sanitize(purifier, html, { config });
19
+ }
15
20
  return DOMPurify.sanitize(html, purifyConfig);
16
21
  }
@@ -1 +1 @@
1
- export default '2.6.2';
1
+ export default '2.6.3';
@@ -2,5 +2,6 @@ import CioPia from './components/CioPia';
2
2
  export { default as CioPia } from './components/CioPia';
3
3
  export type { CioPiaProps } from './components/CioPia';
4
4
  export { sanitizeHtml, renderMarkdown } from './utils/contentTransformers';
5
+ export type { RenderMarkdownOptions, SanitizeOptions } from './utils/contentTransformers';
5
6
  export * from './types';
6
7
  export default CioPia;
@@ -1,2 +1,27 @@
1
+ import DOMPurify from 'dompurify';
2
+ export interface SanitizeOptions {
3
+ config: DOMPurify.Config;
4
+ }
5
+ /** Options for {@link renderMarkdown}. */
6
+ export interface RenderMarkdownOptions {
7
+ /**
8
+ * Override the default DOMPurify sanitization step.
9
+ * Called with an isolated DOMPurify instance, the parsed HTML string,
10
+ * and an options object containing the default config. Must return the sanitized HTML string.
11
+ *
12
+ * @example
13
+ * sanitize: (purifier, html, { config }) => {
14
+ * purifier.addHook('uponSanitizeAttribute', (node, event) => {
15
+ * if (node.tagName === 'A' && event.attrName === 'href') {
16
+ * if (/^javascript:window\.openChat\(\)$/.test(event.attrValue)) {
17
+ * event.forceKeepAttr = true;
18
+ * }
19
+ * }
20
+ * });
21
+ * return purifier.sanitize(html, config);
22
+ * }
23
+ */
24
+ sanitize?: (purifier: typeof DOMPurify, html: string, options: SanitizeOptions) => string;
25
+ }
1
26
  export declare function sanitizeHtml(html: string): string;
2
- export declare function renderMarkdown(content: string): string;
27
+ export declare function renderMarkdown(content: string, options?: RenderMarkdownOptions): string;
@@ -1,2 +1,2 @@
1
- declare const _default: "2.6.2";
1
+ declare const _default: "2.6.3";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-pia",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "Constructor.io AI Product Insights Agent UI library for web applications",
5
5
  "author": "Constructor.io Corporation",
6
6
  "license": "MIT",