diff --git a/__tests__/renderers/Form/__snapshots__/color.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/color.test.tsx.snap deleted file mode 100644 index 7f161076c..000000000 --- a/__tests__/renderers/Form/__snapshots__/color.test.tsx.snap +++ /dev/null @@ -1,128 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Renderer:color 1`] = ` -
-
-
-

- - - The form - - -

-
-
-
-
- -
-
- - - - - - - -
-
-
- - -
- ); } diff --git a/src/renderers/Form/ConditionBuilder.tsx b/src/renderers/Form/ConditionBuilder.tsx index 5c6191c8d..232a810ac 100644 --- a/src/renderers/Form/ConditionBuilder.tsx +++ b/src/renderers/Form/ConditionBuilder.tsx @@ -1,6 +1,5 @@ import React from 'react'; import {FormItem, FormControlProps, FormBaseControl} from './Item'; -import ColorPicker from '../../components/ColorPicker'; import {Funcs, Fields} from '../../components/condition-builder/types'; import {Config} from '../../components/condition-builder/config'; import ConditionBuilder from '../../components/condition-builder/index'; diff --git a/src/renderers/Form/Image.tsx b/src/renderers/Form/Image.tsx index af957f181..0ba112199 100644 --- a/src/renderers/Form/Image.tsx +++ b/src/renderers/Form/Image.tsx @@ -1,7 +1,7 @@ -import React from 'react'; +import React, {Suspense} from 'react'; import {FormItem, FormControlProps, FormBaseControl} from './Item'; import 'cropperjs/dist/cropper.css'; -import Cropper from 'react-cropper'; +const Cropper = React.lazy(() => import('react-cropper')); import DropZone from 'react-dropzone'; import {FileRejection} from 'react-dropzone'; import 'blueimp-canvastoblob'; @@ -1155,7 +1155,9 @@ export default class ImageControl extends React.Component<
{cropFile ? (
- + ...
}> + +
{ + return import('../components/Markdown').then(item => item.default); +} + +export interface MarkdownProps + extends RendererProps, + Omit {} + +export class Markdown extends React.Component { + render() { + const {className, data, classnames: cx, name, value} = this.props; + const content = + value || (name ? resolveVariableAndFilter(name, data, '| raw') : null); + + return ( +
+ +
+ ); + } +} + +@Renderer({ + test: /(^|\/)markdown$/, + name: 'markdown' +}) +export class MarkdownRenderer extends Markdown {} diff --git a/src/utils/markdown.ts b/src/utils/markdown.ts new file mode 100644 index 000000000..f101c9e82 --- /dev/null +++ b/src/utils/markdown.ts @@ -0,0 +1,35 @@ +/** + * @file markdown 解析 + */ + +import hljs from 'highlight.js'; +import markdownIt from 'markdown-it'; +import {escapeHtml} from 'markdown-it/lib/common/utils'; + +const markdown = markdownIt({ + linkify: true, + highlight(str: string, lang: string) { + if (lang && hljs.getLanguage(lang)) { + try { + return ( + '
' +
+          hljs.highlight(lang, str, true).value +
+          '
' + ); + } catch (__) {} + } + return ( + '
' +
+      escapeHtml(str) +
+      '
' + ); + } +}); + +export default function (content: string) { + return markdown.render(content); +}