fix: markdown support ellipsis (#257)

* fix: markdown add "format" props

* fix: markdown support ellipsis
This commit is contained in:
SemmyWong 2022-03-30 15:46:50 +08:00 committed by GitHub
parent cf1fb16638
commit 16c0ca7412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 7 deletions

View File

@ -22,7 +22,7 @@ const MarkdownEditor = (props: any) => {
<Space style={{ position: 'absolute', bottom: 5, right: 5 }}> <Space style={{ position: 'absolute', bottom: 5, right: 5 }}>
<Button <Button
onClick={(e) => { onClick={(e) => {
props.onCancel && props.onCancel(e); props.onCancel?.(e);
}} }}
> >
{t('Cancel')} {t('Cancel')}
@ -30,7 +30,7 @@ const MarkdownEditor = (props: any) => {
<Button <Button
type={'primary'} type={'primary'}
onClick={() => { onClick={() => {
props.onSubmit && props.onSubmit(value); props.onSubmit?.(value);
}} }}
> >
{t('Save')} {t('Save')}

View File

@ -4,7 +4,7 @@ import { Input as AntdInput } from 'antd';
import React from 'react'; import React from 'react';
import { ReadPretty as InputReadPretty } from '../input'; import { ReadPretty as InputReadPretty } from '../input';
import { MarkdownVoid } from './Markdown.Void'; import { MarkdownVoid } from './Markdown.Void';
import { markdown } from './util'; import { convertToText, markdown } from './util';
export const Markdown: any = connect( export const Markdown: any = connect(
AntdInput.TextArea, AntdInput.TextArea,
@ -19,7 +19,7 @@ export const Markdown: any = connect(
}; };
}), }),
mapReadPretty((props) => { mapReadPretty((props) => {
let text = props.value; let text = convertToText(props.value);
let value = <div className={'nb-markdown'} dangerouslySetInnerHTML={{ __html: markdown(text) }} />; let value = <div className={'nb-markdown'} dangerouslySetInnerHTML={{ __html: markdown(text) }} />;
return <InputReadPretty.TextArea {...props} text={text} value={value} />; return <InputReadPretty.TextArea {...props} text={text} value={value} />;
}), }),

View File

@ -6,3 +6,11 @@ export function markdown(text) {
} }
return marked.parse(text); return marked.parse(text);
} }
export function convertToText(markdownText: string) {
const content = markdown(markdownText);
let temp = document.createElement('div');
temp.innerHTML = content;
const text = temp.innerText;
temp = null;
return text.replace(/[\n\r]/g, '');
}

View File

@ -64,9 +64,13 @@ export const useTableColumnInitializerFields = () => {
.filter((field) => field?.interface && field?.interface !== 'subTable') .filter((field) => field?.interface && field?.interface !== 'subTable')
.map((field) => { .map((field) => {
const componentProps = {}; const componentProps = {};
if (field?.uiSchema['x-component']?.startsWith?.('Input')) { if (
field?.uiSchema['x-component']?.startsWith?.('Input') ||
field?.uiSchema['x-component']?.startsWith?.('Markdown')
) {
componentProps['ellipsis'] = true; componentProps['ellipsis'] = true;
} }
if (field.interface === 'attachment') { if (field.interface === 'attachment') {
componentProps['size'] = 'small'; componentProps['size'] = 'small';
return { return {

View File

@ -7,7 +7,7 @@ import {
SchemaInitializerButtonProps, SchemaInitializerButtonProps,
SchemaInitializerItemComponent, SchemaInitializerItemComponent,
SchemaInitializerItemOptions, SchemaInitializerItemOptions,
SchemaInitializerItemProps SchemaInitializerItemProps,
} from './types'; } from './types';
const defaultWrap = (s: ISchema) => s; const defaultWrap = (s: ISchema) => s;
@ -88,7 +88,6 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => {
} }
}); });
}; };
const menu = <Menu>{renderItems(items)}</Menu>; const menu = <Menu>{renderItems(items)}</Menu>;
if (!designable && props.designable !== true) { if (!designable && props.designable !== true) {