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

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;
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.31",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",
@@ -86,7 +86,7 @@
86
86
  "@types/mdast": "^4.0.3",
87
87
  "@types/mdx": "^2.0.12",
88
88
  "@vitejs/plugin-react": "^4.2.1",
89
- "@vitest/ui": "^1.5.0",
89
+ "@vitest/ui": "^1.6.0",
90
90
  "babel-jest": "^29.5.0",
91
91
  "babel-loader": "^9.1.2",
92
92
  "browserify-fs": "^1.0.0",
@@ -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;