fix: can use markdown in field description

This commit is contained in:
chenos 2021-01-23 14:15:41 +08:00
parent f1c0503916
commit e36415330f
3 changed files with 7 additions and 5 deletions

View File

@ -25,7 +25,7 @@ marked.setOptions({
const renderer = new marked.Renderer();
renderer.link = ( href, title, text ) => `<a target="_blank" href="${ href }" title="${ title||'' }">${ text }</a>`;
function markdown(text: string) {
export function markdown(text: string) {
return marked(text, {
renderer,
});

View File

@ -1,13 +1,15 @@
import React from 'react';
import { Tooltip } from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { markdown } from '../Field';
export default {
text(...args: any[]) {
return React.createElement('span', {}, ...args)
},
html(html: string) {
return <div dangerouslySetInnerHTML={{__html: html}}></div>
const text = decodeURIComponent(html);
return <div dangerouslySetInnerHTML={{__html: markdown(text)}}></div>
},
tooltip(title: string, offset = 3) {
return (

View File

@ -49,8 +49,8 @@ const transforms = {
const dataSource = field.get('dataSource').filter(item => item.key !== 'developerMode');
field.set('dataSource', dataSource);
}
if (field.get('component.type') === 'filter') {
const { values } = ctx.action.params;
if (field.get('component.type') === 'filter' && get(values, 'associatedKey')) {
const options = Field.parseApiJson(ctx.state.developerMode ? {
filter: {
collection_name: get(values, 'associatedKey'),
@ -70,7 +70,7 @@ const transforms = {
prop.type = 'string'
}
if (field.get('component.tooltip')) {
prop.description = `{{html('${field.get('component.tooltip')}')}}`;
prop.description = `{{html('${encodeURIComponent(field.get('component.tooltip'))}')}}`;
}
if (field.get('name') === 'dataSource') {