@readme/markdown 6.75.0-beta.4 → 6.75.0-beta.40

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.
Files changed (65) hide show
  1. package/components/Anchor.jsx +14 -25
  2. package/components/Callout/index.tsx +41 -0
  3. package/components/Code/index.tsx +75 -0
  4. package/components/CodeTabs/{index.jsx → index.tsx} +8 -19
  5. package/components/Embed/index.tsx +68 -0
  6. package/components/Glossary/index.tsx +37 -0
  7. package/components/Glossary/style.scss +69 -0
  8. package/components/HTMLBlock/index.tsx +36 -0
  9. package/components/Image/index.tsx +110 -0
  10. package/components/Table/index.tsx +19 -0
  11. package/components/TableOfContents/index.jsx +4 -4
  12. package/components/{index.js → index.ts} +1 -1
  13. package/dist/components/Callout/index.d.ts +9 -0
  14. package/dist/components/Code/index.d.ts +11 -0
  15. package/dist/components/CodeTabs/index.d.ts +3 -0
  16. package/dist/components/Embed/index.d.ts +13 -0
  17. package/dist/components/Glossary/index.d.ts +10 -0
  18. package/dist/components/HTMLBlock/index.d.ts +7 -0
  19. package/dist/components/Image/index.d.ts +15 -0
  20. package/dist/components/Table/index.d.ts +6 -0
  21. package/dist/components/index.d.ts +12 -0
  22. package/dist/contexts/GlossaryTerms.d.ts +7 -0
  23. package/dist/contexts/index.d.ts +5 -0
  24. package/dist/enums.d.ts +12 -0
  25. package/dist/errors/mdx-syntax-error.d.ts +5 -0
  26. package/dist/example/App.d.ts +4 -0
  27. package/dist/example/Doc.d.ts +3 -0
  28. package/dist/example/Form.d.ts +3 -0
  29. package/dist/example/Header.d.ts +3 -0
  30. package/dist/example/RenderError.d.ts +23 -0
  31. package/dist/example/Root.d.ts +3 -0
  32. package/dist/example/docs.d.ts +2 -0
  33. package/dist/example/index.d.ts +1 -0
  34. package/dist/index.d.ts +35 -0
  35. package/dist/lib/owlmoji.d.ts +4 -0
  36. package/dist/main.js +78869 -2
  37. package/dist/main.node.js +81008 -2
  38. package/dist/processor/compile/callout.d.ts +3 -0
  39. package/dist/processor/compile/code-tabs.d.ts +3 -0
  40. package/dist/processor/compile/compatibility.d.ts +18 -0
  41. package/dist/processor/compile/embed.d.ts +3 -0
  42. package/dist/processor/compile/gemoji.d.ts +3 -0
  43. package/dist/processor/compile/html-block.d.ts +3 -0
  44. package/dist/processor/compile/image.d.ts +3 -0
  45. package/dist/processor/compile/index.d.ts +2 -0
  46. package/dist/processor/compile/table.d.ts +0 -0
  47. package/dist/processor/transform/callouts.d.ts +2 -0
  48. package/dist/processor/transform/code-tabs.d.ts +2 -0
  49. package/dist/processor/transform/embeds.d.ts +2 -0
  50. package/dist/processor/transform/gemoji+.d.ts +3 -0
  51. package/dist/processor/transform/index.d.ts +4 -0
  52. package/dist/processor/transform/readme-components.d.ts +6 -0
  53. package/package.json +41 -22
  54. package/styles/components.scss +1 -1
  55. package/components/Callout/index.jsx +0 -42
  56. package/components/Code/index.jsx +0 -101
  57. package/components/Embed/index.jsx +0 -89
  58. package/components/GlossaryItem/index.jsx +0 -44
  59. package/components/GlossaryItem/style.scss +0 -60
  60. package/components/HTMLBlock/index.jsx +0 -69
  61. package/components/Image/index.jsx +0 -111
  62. package/components/Table/index.jsx +0 -19
  63. package/dist/main.css +0 -399
  64. package/dist/main.js.LICENSE.txt +0 -17
  65. package/dist/main.node.js.LICENSE.txt +0 -50
@@ -0,0 +1,3 @@
1
+ import { Callout } from '../../types';
2
+ declare const callout: (node: Callout, _: any, state: any, info: any) => any;
3
+ export default callout;
@@ -0,0 +1,3 @@
1
+ import { CodeTabs } from '../../types';
2
+ declare const codeTabs: (node: CodeTabs, _: any, state: any, info: any) => any;
3
+ export default codeTabs;
@@ -0,0 +1,18 @@
1
+ import { Html } from 'mdast';
2
+ import { NodeTypes } from '../../enums';
3
+ type CompatNodes = {
4
+ type: NodeTypes.variable;
5
+ text: string;
6
+ } | {
7
+ type: NodeTypes.glossary;
8
+ data: {
9
+ hProperties: {
10
+ term: string;
11
+ };
12
+ };
13
+ } | {
14
+ type: NodeTypes.reusableContent;
15
+ tag: string;
16
+ } | Html;
17
+ declare const compatibility: (node: CompatNodes) => string;
18
+ export default compatibility;
@@ -0,0 +1,3 @@
1
+ import type { Embed } from "types";
2
+ declare const embed: (node: Embed) => string;
3
+ export default embed;
@@ -0,0 +1,3 @@
1
+ import { Gemoji } from '../../types';
2
+ declare const gemoji: (node: Gemoji) => string;
3
+ export default gemoji;
@@ -0,0 +1,3 @@
1
+ import { HTMLBlock } from '../../types';
2
+ declare const htmlBlock: (node: HTMLBlock) => string;
3
+ export default htmlBlock;
@@ -0,0 +1,3 @@
1
+ import type { Image } from "mdast";
2
+ declare const image: (node: Image) => string;
3
+ export default image;
@@ -0,0 +1,2 @@
1
+ declare function compilers(): void;
2
+ export default compilers;
File without changes
@@ -0,0 +1,2 @@
1
+ declare const calloutTransformer: () => (tree: any) => void;
2
+ export default calloutTransformer;
@@ -0,0 +1,2 @@
1
+ declare const codeTabsTransformer: () => (tree: any) => any;
2
+ export default codeTabsTransformer;
@@ -0,0 +1,2 @@
1
+ declare const embedTransformer: () => (tree: any) => void;
2
+ export default embedTransformer;
@@ -0,0 +1,3 @@
1
+ import { Root } from 'mdast';
2
+ declare const gemojiTransformer: () => (tree: Root) => Root;
3
+ export default gemojiTransformer;
@@ -0,0 +1,4 @@
1
+ import readmeComponentsTransformer from './readme-components';
2
+ export { readmeComponentsTransformer };
3
+ declare const _default: (() => (tree: any) => void)[];
4
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { Transform } from 'mdast-util-from-markdown';
2
+ interface Options {
3
+ components: Record<string, string>;
4
+ }
5
+ declare const readmeComponents: (opts: Options) => () => Transform;
6
+ export default readmeComponents;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@readme/markdown",
3
3
  "description": "ReadMe's React-based Markdown parser",
4
4
  "author": "Rafe Goldberg <rafe@readme.io>",
5
- "version": "6.75.0-beta.4",
5
+ "version": "6.75.0-beta.40",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",
@@ -12,43 +12,54 @@
12
12
  "dist"
13
13
  ],
14
14
  "scripts": {
15
- "build": "webpack --mode production",
15
+ "build": "webpack --mode production && npm run build-types",
16
+ "build-types": "npx tsc --declaration --emitDeclarationOnly --declarationDir ./dist --skipLibCheck",
16
17
  "lint": "eslint . --ext .jsx --ext .js --ext .ts --ext .tsx",
17
18
  "release": "npx semantic-release",
18
19
  "release.dry": "npx semantic-release --dry-run",
19
- "test": "true # jest --coverage --runInBand",
20
- "test.watch": "jest --watch --coverage=false",
20
+ "start": "webpack serve --open --mode development --config ./webpack.dev.js",
21
+ "test": "vitest",
22
+ "test.ui": "vitest --ui",
23
+ "test.browser": "jest",
21
24
  "watch": "webpack --watch --progress --mode development"
22
25
  },
23
26
  "dependencies": {
24
27
  "@mdx-js/mdx": "^3.0.0",
25
- "@mdx-js/react": "^3.0.0",
26
- "@readme/emojis": "^5.0.0",
27
- "@readme/syntax-highlighter": "^12.0.2",
28
+ "@readme/emojis": "^5.1.0",
29
+ "@readme/syntax-highlighter": "^13.0.0",
28
30
  "copy-to-clipboard": "^3.3.2",
31
+ "core-js": "^3.36.1",
29
32
  "debug": "^4.3.4",
30
33
  "emoji-regex": "^10.2.1",
34
+ "gemoji": "^8.1.0",
31
35
  "hast-util-sanitize": "^4.0.0",
32
36
  "lodash.escape": "^4.0.1",
33
37
  "lodash.kebabcase": "^4.1.1",
38
+ "mdast-util-find-and-replace": "^3.0.1",
34
39
  "mdast-util-toc": "^5.1.0",
35
40
  "path-browserify": "^1.0.1",
36
41
  "process": "^0.11.10",
37
42
  "prop-types": "^15.8.1",
38
43
  "rehype-sanitize": "^4.0.0",
39
- "remark": "^14.0.2",
44
+ "remark": "^15.0.1",
45
+ "remark-frontmatter": "^5.0.0",
46
+ "remark-gfm": "^4.0.0",
40
47
  "remark-mdx": "^3.0.0",
41
- "remark-parse": "^10.0.2",
48
+ "remark-parse": "^11.0.0",
49
+ "remark-rehype": "^11.1.0",
50
+ "remark-stringify": "^11.0.0",
42
51
  "trim": "^1.0.1",
43
52
  "unified": "^8.4.0",
44
53
  "unist-util-flatmap": "^1.0.0",
45
- "unist-util-visit": "^4.1.1"
54
+ "unist-util-visit": "^5.0.0",
55
+ "util": "^0.12.5"
46
56
  },
47
57
  "peerDependencies": {
48
- "@readme/variable": "^15.1.0",
58
+ "@mdx-js/react": "^3.0.0",
59
+ "@readme/variable": "^16.1.0",
49
60
  "@tippyjs/react": "^4.1.0",
50
- "react": "^16.14.0",
51
- "react-dom": "^16.14.0"
61
+ "react": "16.x || 17.x || 18.x",
62
+ "react-dom": "16.x || 17.x || 18.x"
52
63
  },
53
64
  "devDependencies": {
54
65
  "@babel/core": "^7.21.4",
@@ -57,6 +68,7 @@
57
68
  "@babel/plugin-proposal-export-default-from": "^7.23.3",
58
69
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
59
70
  "@babel/plugin-proposal-optional-chaining": "^7.21.0",
71
+ "@babel/plugin-proposal-private-methods": "^7.18.6",
60
72
  "@babel/plugin-transform-runtime": "^7.21.4",
61
73
  "@babel/preset-env": "^7.21.4",
62
74
  "@babel/preset-react": "^7.18.6",
@@ -64,37 +76,44 @@
64
76
  "@commitlint/cli": "^17.5.1",
65
77
  "@commitlint/config-angular": "^17.4.4",
66
78
  "@commitlint/config-conventional": "^17.4.4",
67
- "@hot-loader/react-dom": "^16.14.0",
68
- "@readme/eslint-config": "^10.5.2",
79
+ "@readme/eslint-config": "^14.0.0",
69
80
  "@semantic-release/changelog": "^6.0.3",
70
81
  "@semantic-release/git": "^10.0.1",
71
- "@testing-library/jest-dom": "^5.16.5",
72
- "@testing-library/react": "^12.1.2",
82
+ "@testing-library/jest-dom": "^6.4.2",
83
+ "@testing-library/react": "^14",
84
+ "@testing-library/user-event": "^14.5.2",
85
+ "@types/jest": "^29.5.12",
86
+ "@types/mdast": "^4.0.3",
87
+ "@types/mdx": "^2.0.12",
88
+ "@types/unist": "^3.0.2",
89
+ "@vitejs/plugin-react": "^4.2.1",
90
+ "@vitest/ui": "^1.6.0",
73
91
  "babel-jest": "^29.5.0",
74
92
  "babel-loader": "^9.1.2",
75
93
  "browserify-fs": "^1.0.0",
76
94
  "codemirror": "^5.54.0",
77
- "core-js": "^2.6.12",
78
95
  "css-loader": "^6.7.3",
79
96
  "eslint": "^8.37.0",
80
97
  "identity-obj-proxy": "^3.0.0",
81
98
  "jest": "^29.5.0",
82
99
  "jest-environment-jsdom": "^29.5.0",
83
100
  "jest-environment-puppeteer": "^8.0.6",
84
- "jest-image-snapshot": "^6.1.0",
101
+ "jest-image-snapshot": "^6.4.0",
85
102
  "jest-puppeteer": "^8.0.6",
86
103
  "mini-css-extract-plugin": "^2.7.5",
87
104
  "node-sass": "^8.0.0",
88
- "prettier": "^2.8.7",
105
+ "prettier": "^3.2.5",
89
106
  "puppeteer": "^19.8.3",
90
- "react-hot-loader": "^4.13.1",
107
+ "react-router-dom": "^6.22.3",
91
108
  "sass-loader": "^13.2.2",
92
109
  "semantic-release": "^22.0.12",
93
110
  "stream-browserify": "^3.0.0",
94
111
  "string.prototype.trimend": "^1.0.6",
95
112
  "terser-webpack-plugin": "^5.3.7",
96
113
  "ts-loader": "^9.4.2",
97
- "typescript": "^5.0.3",
114
+ "typescript": "^5.4.5",
115
+ "unist-util-map": "^4.0.0",
116
+ "vitest": "^1.4.0",
98
117
  "webpack": "^5.56.0",
99
118
  "webpack-cli": "^5.0.1",
100
119
  "webpack-dev-server": "^4.13.2",
@@ -6,4 +6,4 @@
6
6
  @import '../components/Callout/style';
7
7
  @import '../components/Heading/style';
8
8
  @import '../components/Embed/style';
9
- @import '../components/GlossaryItem/style';
9
+ @import '../components/Glossary/style';
@@ -1,42 +0,0 @@
1
- const PropTypes = require('prop-types');
2
- const React = require('react');
3
-
4
- const Callout = props => {
5
- const { attributes, theme, icon } = props;
6
- const [title, ...content] = !props.title ? [null, props.children] : props.children;
7
-
8
- return (
9
- // eslint-disable-next-line react/jsx-props-no-spreading
10
- <blockquote {...attributes} className={`callout callout_${theme}`} theme={icon}>
11
- <h3 className={`callout-heading${title ? '' : ' empty'}`}>
12
- <span className="callout-icon">{icon}</span>
13
- {title}
14
- </h3>
15
- {content}
16
- </blockquote>
17
- );
18
- };
19
-
20
- Callout.propTypes = {
21
- attributes: PropTypes.shape({}),
22
- calloutStyle: PropTypes.string,
23
- children: PropTypes.arrayOf(PropTypes.any).isRequired,
24
- icon: PropTypes.string,
25
- node: PropTypes.shape(),
26
- theme: PropTypes.string,
27
- title: PropTypes.string,
28
- };
29
-
30
- Callout.defaultProps = {
31
- attributes: null,
32
- calloutStyle: 'info',
33
- node: null,
34
- };
35
-
36
- Callout.sanitize = sanitizeSchema => {
37
- sanitizeSchema.attributes['rdme-callout'] = ['icon', 'theme', 'title'];
38
-
39
- return sanitizeSchema;
40
- };
41
-
42
- module.exports = Callout;
@@ -1,101 +0,0 @@
1
- const copy = require('copy-to-clipboard');
2
- const PropTypes = require('prop-types');
3
- const React = require('react');
4
-
5
- // Only load CodeMirror in the browser, for SSR
6
- // apps. Necessary because of people like this:
7
- // https://github.com/codemirror/CodeMirror/issues/3701#issuecomment-164904534
8
- let syntaxHighlighter;
9
- let canonicalLanguage = () => {};
10
- if (typeof window !== 'undefined') {
11
- // eslint-disable-next-line global-require
12
- syntaxHighlighter = require('@readme/syntax-highlighter').default;
13
- // eslint-disable-next-line global-require
14
- ({ canonical: canonicalLanguage } = require('@readme/syntax-highlighter'));
15
- }
16
-
17
- function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
18
- const copyClass = `${rootClass}_copied`;
19
- const button = React.createRef();
20
- /* istanbul ignore next */
21
- const copier = () => {
22
- const code = codeRef.current.textContent;
23
-
24
- if (copy(code)) {
25
- const $el = button.current;
26
- $el.classList.add(copyClass);
27
- setTimeout(() => $el.classList.remove(copyClass), 1500);
28
- }
29
- };
30
- return <button ref={button} aria-label="Copy Code" className={`${rootClass} ${className}`} onClick={copier} />;
31
- }
32
-
33
- CopyCode.propTypes = {
34
- className: PropTypes.string,
35
- codeRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.instanceOf(React.Element) })])
36
- .isRequired,
37
- rootClass: PropTypes.string,
38
- };
39
-
40
- function Code(props) {
41
- const { children, className, copyButtons, lang, meta, theme } = props;
42
-
43
- const langClass = className.search(/lang(?:uage)?-\w+/) >= 0 ? className.match(/\s?lang(?:uage)?-(\w+)/)[1] : '';
44
- const language = canonicalLanguage(lang) || langClass;
45
-
46
- const codeRef = React.createRef();
47
-
48
- const codeOpts = {
49
- inline: !lang,
50
- tokenizeVariables: true,
51
- dark: theme === 'dark',
52
- };
53
-
54
- const codeContent =
55
- syntaxHighlighter && children ? syntaxHighlighter(children[0], language, codeOpts) : children?.[0] || '';
56
-
57
- return (
58
- <React.Fragment>
59
- {copyButtons && <CopyCode className="fa" codeRef={codeRef} />}
60
- <code
61
- ref={codeRef}
62
- className={['rdmd-code', `lang-${language}`, `theme-${theme}`].join(' ')}
63
- data-lang={language}
64
- name={meta}
65
- suppressHydrationWarning={true}
66
- >
67
- {codeContent}
68
- </code>
69
- </React.Fragment>
70
- );
71
- }
72
-
73
- function CreateCode({ copyButtons, theme }) {
74
- // eslint-disable-next-line react/display-name
75
- return props => <Code {...props} copyButtons={copyButtons} theme={theme} />;
76
- }
77
-
78
- Code.propTypes = {
79
- children: PropTypes.arrayOf(PropTypes.string),
80
- className: PropTypes.string,
81
- copyButtons: PropTypes.bool,
82
- lang: PropTypes.string,
83
- meta: PropTypes.string,
84
- theme: PropTypes.string,
85
- };
86
-
87
- Code.defaultProps = {
88
- className: '',
89
- copyButtons: true,
90
- lang: '',
91
- meta: '',
92
- };
93
-
94
- CreateCode.sanitize = sanitizeSchema => {
95
- // This is for code blocks class name
96
- sanitizeSchema.attributes.code = ['className', 'lang', 'meta', 'value'];
97
-
98
- return sanitizeSchema;
99
- };
100
-
101
- module.exports = CreateCode;
@@ -1,89 +0,0 @@
1
- /* eslint-disable react/jsx-props-no-spreading, jsx-a11y/iframe-has-title */
2
- const propTypes = require('prop-types');
3
- const React = require('react');
4
-
5
- const Favicon = ({ src, alt = 'favicon', ...attr }) => <img {...attr} alt={alt} height="14" src={src} width="14" />;
6
- Favicon.propTypes = {
7
- alt: propTypes.string,
8
- src: propTypes.string,
9
- };
10
-
11
- class Embed extends React.Component {
12
- render() {
13
- const { lazy = true, provider, url, title, html, iframe, image, favicon, ...attrs } = this.props;
14
-
15
- if (!url) {
16
- return <div />;
17
- }
18
-
19
- if ('iframe' in this.props) {
20
- return <iframe {...attrs} border="none" src={url} style={{ border: 'none', display: 'flex', margin: 'auto' }} />;
21
- }
22
-
23
- const classes = ['embed', image && 'embed_hasImg'];
24
- return (
25
- <div className={classes.join(' ')}>
26
- {html ? (
27
- <div className="embed-media" dangerouslySetInnerHTML={{ __html: html }}></div>
28
- ) : (
29
- <a className="embed-link" href={url} rel="noopener noreferrer" target="_blank">
30
- {!image || <img alt={title} className="embed-img" loading={lazy ? 'lazy' : ''} src={image} />}
31
- {title ? (
32
- <div className="embed-body">
33
- {!favicon || (
34
- <Favicon
35
- alt={provider}
36
- className="embed-favicon"
37
- loading={lazy ? 'lazy' : ''}
38
- src={favicon}
39
- style={{ float: 'left' }}
40
- />
41
- )}
42
- {provider && (
43
- <small className="embed-provider">
44
- {provider.search(/^@{1}/) < 0 ? (
45
- provider
46
- ) : (
47
- <code style={{ fontFamily: 'var(--md-code-font, monospace)' }}>{url}</code>
48
- )}
49
- </small>
50
- )}
51
- <div className="embed-title">{title}</div>
52
- </div>
53
- ) : (
54
- <div className="embed-body">
55
- <b>View</b>: <span className="embed-body-url">{url}</span>
56
- </div>
57
- )}
58
- </a>
59
- )}
60
- </div>
61
- );
62
- }
63
- }
64
-
65
- Embed.propTypes = {
66
- children: propTypes.oneOfType([propTypes.string, propTypes.array, propTypes.shape({}), propTypes.element]),
67
- favicon: propTypes.string,
68
- height: propTypes.string,
69
- html: propTypes.string,
70
- iframe: propTypes.any,
71
- image: propTypes.string,
72
- lazy: propTypes.bool,
73
- provider: propTypes.string,
74
- title: propTypes.string,
75
- url: propTypes.oneOfType([propTypes.string, propTypes.shape({})]),
76
- width: propTypes.string,
77
- };
78
- Embed.defaultProps = {
79
- height: '300px',
80
- width: '100%',
81
- };
82
-
83
- const CreateEmbed =
84
- ({ lazyImages }) =>
85
- // eslint-disable-next-line react/display-name
86
- props =>
87
- <Embed {...props} lazy={lazyImages} />;
88
-
89
- module.exports = CreateEmbed;
@@ -1,44 +0,0 @@
1
- const Tooltip = require('@tippyjs/react').default;
2
- const PropTypes = require('prop-types');
3
- const React = require('react');
4
-
5
- const GlossaryContext = require('../../contexts/GlossaryTerms');
6
-
7
- // https://github.com/readmeio/api-explorer/blob/0dedafcf71102feedaa4145040d3f57d79d95752/packages/api-explorer/src/lib/replace-vars.js#L8
8
- function GlossaryItem({ term, terms }) {
9
- const foundTerm = terms.find(i => term.toLowerCase() === i.term.toLowerCase());
10
-
11
- if (!foundTerm) return <span>{term}</span>;
12
-
13
- return (
14
- <Tooltip
15
- content={
16
- <div className="GlossaryItem-tooltip-content">
17
- <strong className="GlossaryItem-term">{foundTerm.term}</strong> - {foundTerm.definition}
18
- </div>
19
- }
20
- offset={[-5, 5]}
21
- placement="bottom-start"
22
- >
23
- <span className="GlossaryItem-trigger">{term}</span>
24
- </Tooltip>
25
- );
26
- }
27
-
28
- GlossaryItem.propTypes = {
29
- term: PropTypes.string.isRequired,
30
- terms: PropTypes.arrayOf(
31
- PropTypes.shape({
32
- definition: PropTypes.string.isRequired,
33
- term: PropTypes.string.isRequired,
34
- })
35
- ).isRequired,
36
- };
37
-
38
- // eslint-disable-next-line react/display-name
39
- module.exports = props => (
40
- <GlossaryContext.Consumer>{terms => terms && <GlossaryItem {...props} terms={terms} />}</GlossaryContext.Consumer>
41
- );
42
-
43
- module.exports.GlossaryItem = GlossaryItem;
44
- module.exports.GlossaryContext = GlossaryContext;
@@ -1,60 +0,0 @@
1
- .GlossaryItem {
2
- &-trigger {
3
- border-bottom: 1px solid #737c83;
4
- border-style: dotted;
5
- border-top: none;
6
- border-left: none;
7
- border-right: none;
8
- cursor: pointer;
9
- }
10
-
11
- &-tooltip-content {
12
- --GlossaryItem-bg: var(--color-bg-page, var(--white));
13
- --GlossaryItem-color: var(--color-text-default, var(--gray20));
14
- --GlossaryItem-shadow: var(--box-shadow-menu-light, 0 5px 10px rgba(0, 0, 0, .05),
15
- 0 2px 6px rgba(0, 0, 0, .025),
16
- 0 1px 3px rgba(0, 0, 0, .025));
17
-
18
- /* what the dark-mode mixin does in the readme project */
19
- [data-color-mode='dark'] & {
20
- --GlossaryItem-bg: var(--gray15);
21
- --GlossaryItem-color: var(--color-text-default, var(--white));
22
- --GlossaryItem-shadow: var(--box-shadow-menu-dark, 0 1px 3px rgba(0, 0, 0, 0.025),
23
- 0 2px 6px rgba(0, 0, 0, 0.025),
24
- 0 5px 10px rgba(0, 0, 0, 0.05))
25
- }
26
-
27
- @media (prefers-color-scheme: dark) {
28
- [data-color-mode='auto'] & {
29
- --GlossaryItem-bg: var(--Tooltip-bg, var(--gray0));
30
- --GlossaryItem-color: var(--color-text-default, var(--white));
31
- --GlossaryItem-shadow: var(--box-shadow-menu-dark, 0 1px 3px rgba(0, 0, 0, 0.025),
32
- 0 2px 6px rgba(0, 0, 0, 0.025),
33
- 0 5px 10px rgba(0, 0, 0, 0.05))
34
- }
35
- }
36
-
37
- background-color: var(--GlossaryItem-bg);
38
- border: 1px solid #{var(--color-border-default, rgba(black, 0.1))};
39
- border-radius: var(--border-radius);
40
- box-shadow: var(--GlossaryItem-shadow);
41
- color: var(--GlossaryItem-color);
42
- font-size: 15px;
43
- font-weight: 400;
44
- line-height: 1.5;
45
- padding: 15px;
46
- text-align: left;
47
- width: 350px;
48
- }
49
-
50
- &-term {
51
- font-style: italic;
52
- }
53
- }
54
-
55
- .tippy-box {
56
- // needed for tippy's default animation
57
- &[data-animation='fade'][data-state='hidden'] {
58
- opacity: 0;
59
- }
60
- }
@@ -1,69 +0,0 @@
1
- /* eslint-disable no-eval
2
- */
3
- const escape = require('lodash.escape');
4
- const PropTypes = require('prop-types');
5
- const React = require('react');
6
-
7
- const MATCH_SCRIPT_TAGS = /<script\b[^>]*>([\s\S]*?)<\/script *>\n?/gim;
8
-
9
- const extractScripts = (html = '') => {
10
- const scripts = [];
11
- let match;
12
- while ((match = MATCH_SCRIPT_TAGS.exec(html)) !== null) {
13
- scripts.push(match[1]);
14
- }
15
- const cleaned = html.replace(MATCH_SCRIPT_TAGS, '');
16
- return [cleaned, () => scripts.map(js => window.eval(js))];
17
- };
18
-
19
- class HTMLBlock extends React.PureComponent {
20
- constructor(props) {
21
- super(props);
22
- [this.html, this.exec] = extractScripts(this.props.html);
23
- }
24
-
25
- componentDidMount() {
26
- const { runScripts } = this.props;
27
- if (typeof window !== 'undefined' && (runScripts === '' || runScripts)) this.exec();
28
- }
29
-
30
- render() {
31
- const { html, safeMode } = this.props;
32
-
33
- if (safeMode) {
34
- return (
35
- <pre className="html-unsafe">
36
- <code dangerouslySetInnerHTML={{ __html: escape(html) }} />
37
- </pre>
38
- );
39
- }
40
-
41
- return <div className="rdmd-html" dangerouslySetInnerHTML={{ __html: this.html }} />;
42
- }
43
- }
44
-
45
- HTMLBlock.defaultProps = {
46
- runScripts: false,
47
- safeMode: false,
48
- };
49
-
50
- HTMLBlock.propTypes = {
51
- html: PropTypes.string,
52
- runScripts: PropTypes.any,
53
- safeMode: PropTypes.bool,
54
- };
55
-
56
- const CreateHtmlBlock =
57
- ({ safeMode }) =>
58
- // eslint-disable-next-line react/display-name
59
- props =>
60
- <HTMLBlock {...props} safeMode={safeMode} />;
61
-
62
- CreateHtmlBlock.sanitize = schema => {
63
- schema.tagNames.push('html-block');
64
- schema.attributes['html-block'] = ['html', 'runScripts'];
65
-
66
- return schema;
67
- };
68
-
69
- module.exports = CreateHtmlBlock;