@vertigis/react-ui 21.7.4 → 21.9.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.
@@ -48,6 +48,11 @@ export interface MarkdownProps extends BoxProps {
48
48
  * applied to the output. Defaults to `false`.
49
49
  */
50
50
  useBasicHtml?: boolean;
51
+ /**
52
+ * Adds support for the extensions found in GitHub Flavored Markdown.
53
+ * Defaults to `true`.
54
+ */
55
+ useGitHubFlavoredMarkdown?: boolean;
51
56
  }
52
57
  /**
53
58
  * A component that renders markdown as React nodes.
@@ -5,6 +5,7 @@ import { useMemo } from "react";
5
5
  import ReactMarkdown, {} from "react-markdown";
6
6
  import rehypeRaw from "rehype-raw";
7
7
  import rehypeSanitize from "rehype-sanitize";
8
+ import remarkGfm from "remark-gfm";
8
9
  import Box from "../Box/index.js";
9
10
  import Link, {} from "../Link/index.js";
10
11
  import Typography, {} from "../Typography/index.js";
@@ -75,7 +76,7 @@ const disallowedInlineElements = [
75
76
  * However, it is still recommended to set `escapeHtml` to true with untrusted
76
77
  * content.
77
78
  */
78
- const Markdown = ({ markdown, inline, escapeHtml, sanitize, linkTarget = "_blank", children, className, useBasicHtml, ...otherProps }) => {
79
+ const Markdown = ({ markdown, inline, escapeHtml, sanitize, linkTarget = "_blank", children, className, useBasicHtml, useGitHubFlavoredMarkdown = true, ...otherProps }) => {
79
80
  const theme = useTheme();
80
81
  const disallowedElements = useMemo(() => (inline ? disallowedInlineElements : []), [inline]);
81
82
  const components = useMemo(() => useBasicHtml
@@ -132,6 +133,6 @@ const Markdown = ({ markdown, inline, escapeHtml, sanitize, linkTarget = "_blank
132
133
  }, variant: "body1" }));
133
134
  },
134
135
  }, [linkTarget, theme, useBasicHtml]);
135
- return (_jsx(Box, { component: inline ? "span" : "div", className: clsx("GcxMarkdown", className), ...otherProps, children: _jsx(ReactMarkdown, { components: components, disallowedElements: disallowedElements, rehypePlugins: escapeHtml ? [] : [rehypeRaw, rehypeSanitize], children: children && typeof children === "string" ? children : markdown }) }));
136
+ return (_jsx(Box, { component: inline ? "span" : "div", className: clsx("GcxMarkdown", className), ...otherProps, children: _jsx(ReactMarkdown, { components: components, disallowedElements: disallowedElements, rehypePlugins: escapeHtml ? [] : [rehypeRaw, rehypeSanitize], remarkPlugins: useGitHubFlavoredMarkdown ? [remarkGfm] : [], children: children && typeof children === "string" ? children : markdown }) }));
136
137
  };
137
138
  export default Markdown;
@@ -0,0 +1,48 @@
1
+ import type { FC } from "react";
2
+ import type { BoxProps } from "../Box/index.js";
3
+ /**
4
+ * Properties for the `Markdown` component.
5
+ */
6
+ export interface MarkdownProps extends BoxProps {
7
+ /**
8
+ * The markdown text to render.
9
+ */
10
+ markdown: string;
11
+ /**
12
+ * Override the default sanitization behaviour with a caller-supplied
13
+ * sanitization function that ensures that the resulting HTML is safe to
14
+ * insert into the DOM.
15
+ */
16
+ sanitize?: (unsafeHtml: string) => string;
17
+ /**
18
+ * If specified, produces HTML that is valid for contexts where only inline
19
+ * content is allowed (e.g. inside `<h1>` or `<span>` tags). HTML tags for
20
+ * block-level elements will be removed, but any text content will be
21
+ * preserved.
22
+ */
23
+ inline?: boolean;
24
+ /**
25
+ * If true, any HTML in the markdown will be escaped rather than passed
26
+ * through directly to the output as normal (since Markdown is a superset of
27
+ * HTML). This is useful in situations where you wish to only support pure
28
+ * Markdown syntax without also supporting HTML syntax. The default is
29
+ * `false`.
30
+ *
31
+ * IMPORTANT: The resulting HTML still needs to be sanitized whether or not
32
+ * this option is set.
33
+ */
34
+ escapeHtml?: boolean;
35
+ /**
36
+ * An optional value to apply to external hyperlinks via the `target`
37
+ * attribute.
38
+ *
39
+ * If this is omitted, links may still open in a separate target if the host
40
+ * page specifies a `target` via the `<base>` element in its `<head>`.
41
+ */
42
+ linkTarget?: string;
43
+ }
44
+ /**
45
+ * A component that renders markdown as HTML.
46
+ */
47
+ declare const Markdown: FC<MarkdownProps>;
48
+ export default Markdown;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import clsx from "clsx";
3
+ import Box from "../Box/index.js";
4
+ import { sanitizeHtml } from "../utils/html.js";
5
+ import { markdownToHtml } from "../utils/markdown.js";
6
+ /**
7
+ * A component that renders markdown as HTML.
8
+ */
9
+ const Markdown = ({ markdown, inline, escapeHtml, sanitize = sanitizeHtml, linkTarget, className, ...otherProps }) => (_jsx(Box, { component: inline ? "span" : "div", className: clsx("GcxMarkdown", className), dangerouslySetInnerHTML: {
10
+ __html: sanitize(markdownToHtml(markdown, { inline, escapeHtml, linkTarget })),
11
+ }, ...otherProps }));
12
+ export default Markdown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertigis/react-ui",
3
- "version": "21.7.4",
3
+ "version": "21.9.0",
4
4
  "description": "Utilities and React components used in VertiGIS applications.",
5
5
  "keywords": [
6
6
  "vertigis",
@@ -30,6 +30,7 @@
30
30
  "react-markdown": "^10.1.0",
31
31
  "rehype-raw": "^7.0.0",
32
32
  "rehype-sanitize": "^6.0.0",
33
+ "remark-gfm": "^4.0.1",
33
34
  "tslib": "^2.6.2",
34
35
  "xss": "^1.0.15"
35
36
  },