@readme/markdown 6.75.0-beta.30 → 6.75.0-beta.32

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.
@@ -0,0 +1,3 @@
1
+ import { HTMLBlock } from '../../types';
2
+ declare const htmlBlock: (node: HTMLBlock) => string;
3
+ export default htmlBlock;
@@ -1,2 +1,4 @@
1
+ import readmeComponentsTransformer from './readme-components';
2
+ export { readmeComponentsTransformer };
1
3
  declare const _default: (() => (tree: any) => void)[];
2
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.30",
5
+ "version": "6.75.0-beta.32",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",
@@ -51,7 +51,7 @@
51
51
  "trim": "^1.0.1",
52
52
  "unified": "^8.4.0",
53
53
  "unist-util-flatmap": "^1.0.0",
54
- "unist-util-visit": "^4.1.1",
54
+ "unist-util-visit": "^5.0.0",
55
55
  "util": "^0.12.5"
56
56
  },
57
57
  "peerDependencies": {
@@ -85,8 +85,9 @@
85
85
  "@types/jest": "^29.5.12",
86
86
  "@types/mdast": "^4.0.3",
87
87
  "@types/mdx": "^2.0.12",
88
+ "@types/unist": "^3.0.2",
88
89
  "@vitejs/plugin-react": "^4.2.1",
89
- "@vitest/ui": "^1.5.0",
90
+ "@vitest/ui": "^1.6.0",
90
91
  "babel-jest": "^29.5.0",
91
92
  "babel-loader": "^9.1.2",
92
93
  "browserify-fs": "^1.0.0",
@@ -111,6 +112,7 @@
111
112
  "terser-webpack-plugin": "^5.3.7",
112
113
  "ts-loader": "^9.4.2",
113
114
  "typescript": "^5.4.5",
115
+ "unist-util-map": "^4.0.0",
114
116
  "vitest": "^1.4.0",
115
117
  "webpack": "^5.56.0",
116
118
  "webpack-cli": "^5.0.1",
@@ -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;