@ndlib/component-library 0.0.100 → 0.0.101
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.
|
@@ -57,6 +57,8 @@ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
|
57
57
|
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
58
58
|
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
59
59
|
nulla pariatur.
|
|
60
|
+
|
|
61
|
+
https://this-should-be-auto-linked.nd.edu
|
|
60
62
|
`;
|
|
61
63
|
export const Default = {
|
|
62
64
|
render: (args) => _jsx(Markdown, Object.assign({}, args)),
|
|
@@ -35,6 +35,8 @@ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
|
35
35
|
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
36
36
|
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
37
37
|
nulla pariatur.
|
|
38
|
+
|
|
39
|
+
https://this-should-be-auto-linked.nd.edu
|
|
38
40
|
`;
|
|
39
41
|
const htmlMarkdown = `
|
|
40
42
|
## HTML Content
|
|
@@ -74,12 +76,15 @@ describe('Markdown', () => {
|
|
|
74
76
|
name: 'Heading 5',
|
|
75
77
|
level: 6,
|
|
76
78
|
})).toBeInTheDocument();
|
|
79
|
+
expect(getByRole('link', {
|
|
80
|
+
name: 'https://this-should-be-auto-linked.nd.edu',
|
|
81
|
+
})).toBeInTheDocument();
|
|
77
82
|
expect(getAllByRole('list')).toHaveLength(3);
|
|
78
83
|
});
|
|
79
84
|
it('renders allowed html when included', () => {
|
|
80
|
-
const { container, getByText,
|
|
85
|
+
const { container, getByText, getAllByRole } = render(_jsx(Markdown, { content: htmlMarkdown, enableHtml: true }));
|
|
81
86
|
expect(getByText('hello world')).toBeDefined();
|
|
82
|
-
expect(
|
|
87
|
+
expect(getAllByRole('link')).toBeDefined();
|
|
83
88
|
expect(() => getByText(' ')).toThrow();
|
|
84
89
|
expect(container.getElementsByTagName('script')).toHaveLength(0);
|
|
85
90
|
expect(container.getElementsByTagName('img')).toHaveLength(0);
|
|
@@ -6,7 +6,6 @@ export declare const DEFAULT_ALLOWED_ATTRIBUTES: {
|
|
|
6
6
|
iframe: string[];
|
|
7
7
|
a: sanitizeHtml.AllowedAttribute[];
|
|
8
8
|
};
|
|
9
|
-
export declare const DEFAULT_ALLOWED_IFRAME_DOMAINS: string[];
|
|
10
9
|
type MarkdownProps = StyledElementProps<HTMLDivElement, {
|
|
11
10
|
content: string;
|
|
12
11
|
enableHtml?: boolean;
|
|
@@ -14,7 +13,6 @@ type MarkdownProps = StyledElementProps<HTMLDivElement, {
|
|
|
14
13
|
headingLevelOffset?: number;
|
|
15
14
|
sanitizeHtmlOptions?: {
|
|
16
15
|
allowedTags?: string[];
|
|
17
|
-
allowedIframeDomains?: string[];
|
|
18
16
|
allowedAttributes?: sanitizeHtml.IOptions['allowedAttributes'];
|
|
19
17
|
};
|
|
20
18
|
customStyles?: Record<string, StylesProp>;
|
|
@@ -18,6 +18,7 @@ import { HEADING_SIZE, Heading } from '../text/Heading';
|
|
|
18
18
|
import { Bold, Italic } from '../text/Inline';
|
|
19
19
|
import { firstChildAltSelector } from '../../../utils/misc';
|
|
20
20
|
import sanitizeHtml from 'sanitize-html';
|
|
21
|
+
import remarkGfm from 'remark-gfm';
|
|
21
22
|
import { BlockQuote } from '../BlockQuote';
|
|
22
23
|
export const DEFAULT_ALLOWED_TAGS = sanitizeHtml.defaults.allowedTags.concat([
|
|
23
24
|
'iframe',
|
|
@@ -27,11 +28,6 @@ export const DEFAULT_ALLOWED_ATTRIBUTES = Object.assign(Object.assign({}, saniti
|
|
|
27
28
|
'data-card-width',
|
|
28
29
|
'data-card-controls',
|
|
29
30
|
]) });
|
|
30
|
-
export const DEFAULT_ALLOWED_IFRAME_DOMAINS = [
|
|
31
|
-
'facebook.com',
|
|
32
|
-
'youtube.com',
|
|
33
|
-
'nd.edu',
|
|
34
|
-
];
|
|
35
31
|
const dynamicTopMarginStyles = {
|
|
36
32
|
[firstChildAltSelector]: {
|
|
37
33
|
mt: 0,
|
|
@@ -43,12 +39,10 @@ export const Markdown = (_a) => {
|
|
|
43
39
|
if (enableHtml) {
|
|
44
40
|
sanitizedContent = sanitizeHtml(content, {
|
|
45
41
|
allowedTags: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedTags) || DEFAULT_ALLOWED_TAGS,
|
|
46
|
-
allowedIframeDomains: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedIframeDomains) ||
|
|
47
|
-
DEFAULT_ALLOWED_IFRAME_DOMAINS,
|
|
48
42
|
allowedAttributes: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedAttributes) || DEFAULT_ALLOWED_ATTRIBUTES,
|
|
49
43
|
});
|
|
50
44
|
}
|
|
51
|
-
return (_jsx("div", Object.assign({}, rest, { children: _jsx(ReactMarkdown, Object.assign({ rehypePlugins: enableHtml ? [rehypeRaw] : [], components: {
|
|
45
|
+
return (_jsx("div", Object.assign({}, rest, { children: _jsx(ReactMarkdown, Object.assign({ rehypePlugins: enableHtml ? [rehypeRaw, remarkGfm] : [remarkGfm], components: {
|
|
52
46
|
h1: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.XL }, props, { level: props.level + headingLevelOffset, standalone: true, sx: Object.assign(Object.assign({}, dynamicTopMarginStyles), customStyles.h1) }))),
|
|
53
47
|
h2: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.LG }, props, { level: props.level + headingLevelOffset, standalone: true, sx: Object.assign(Object.assign({}, dynamicTopMarginStyles), customStyles.h2) }))),
|
|
54
48
|
h3: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, props, { level: props.level + headingLevelOffset, standalone: true, sx: Object.assign(Object.assign({}, dynamicTopMarginStyles), customStyles.h3) }))),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndlib/component-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.101",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"storybook": "^7.0.17",
|
|
78
78
|
"theme-ui": "^0.16.1",
|
|
79
79
|
"typescript": "^5.0.2",
|
|
80
|
-
"vite": "^4.
|
|
80
|
+
"vite": "^4.5.2",
|
|
81
81
|
"vitest": "^0.31.4"
|
|
82
82
|
},
|
|
83
83
|
"prettier": {
|
|
@@ -92,7 +92,8 @@
|
|
|
92
92
|
"react-markdown": "^8.0.7",
|
|
93
93
|
"react-modal": "^3.16.1",
|
|
94
94
|
"rehype-raw": "^6.1.1",
|
|
95
|
-
"
|
|
95
|
+
"remark-gfm": "^4.0.0",
|
|
96
|
+
"sanitize-html": "^2.12.1",
|
|
96
97
|
"schema-dts": "^1.1.2"
|
|
97
98
|
}
|
|
98
99
|
}
|