mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
temp
This commit is contained in:
@ -32,6 +32,7 @@ export type MarkdownProps = {
|
|||||||
content: string
|
content: string
|
||||||
className?: string
|
className?: string
|
||||||
customDisallowedElements?: string[]
|
customDisallowedElements?: string[]
|
||||||
|
rehypePlugins?: any// js: PluggableList[]
|
||||||
customComponents?: Record<string, React.ComponentType<any>>
|
customComponents?: Record<string, React.ComponentType<any>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +72,7 @@ export const Markdown = (props: MarkdownProps) => {
|
|||||||
tree.children.forEach(iterate)
|
tree.children.forEach(iterate)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
...(props.rehypePlugins || []),
|
||||||
]}
|
]}
|
||||||
urlTransform={customUrlTransform}
|
urlTransform={customUrlTransform}
|
||||||
disallowedElements={['iframe', 'head', 'html', 'meta', 'link', 'style', 'body', ...(props.customDisallowedElements || [])]}
|
disallowedElements={['iframe', 'head', 'html', 'meta', 'link', 'style', 'body', ...(props.customDisallowedElements || [])]}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import Badge from '@/app/components/base/badge'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import ActionButton from '@/app/components/base/action-button'
|
import ActionButton from '@/app/components/base/action-button'
|
||||||
import { RiCloseLine } from '@remixicon/react'
|
import { RiCloseLine } from '@remixicon/react'
|
||||||
|
import { Variable, rehypeVariable } from './variable-in-markdown'
|
||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.humanInput'
|
const i18nPrefix = 'workflow.nodes.humanInput'
|
||||||
|
|
||||||
@ -38,7 +39,16 @@ const FormContentPreview: FC<Props> = ({
|
|||||||
<ActionButton onClick={onClose}><RiCloseLine className='w-5 text-text-tertiary' /></ActionButton>
|
<ActionButton onClick={onClose}><RiCloseLine className='w-5 text-text-tertiary' /></ActionButton>
|
||||||
</div>
|
</div>
|
||||||
<div className='max-h-[calc(100vh-167px)] overflow-y-auto px-4'>
|
<div className='max-h-[calc(100vh-167px)] overflow-y-auto px-4'>
|
||||||
<Markdown content={content} />
|
<Markdown
|
||||||
|
content={content}
|
||||||
|
customDisallowedElements={['variable']}
|
||||||
|
rehypePlugins={[rehypeVariable]}
|
||||||
|
customComponents={{
|
||||||
|
variable: ({ node, ...props }: any) => (
|
||||||
|
<Variable path={node.properties?.path as string} />
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<div className='mt-3 flex flex-wrap gap-1 py-1'>
|
<div className='mt-3 flex flex-wrap gap-1 py-1'>
|
||||||
{userActions.map((action: any) => (
|
{userActions.map((action: any) => (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@ -0,0 +1,41 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { visit } from 'unist-util-visit'
|
||||||
|
|
||||||
|
export function rehypeVariable() {
|
||||||
|
return (tree: any) => {
|
||||||
|
visit(tree, 'text', (node: any, index: number, parent: any) => {
|
||||||
|
if (!parent || parent.type !== 'element') return
|
||||||
|
const tag = parent.tagName
|
||||||
|
if (tag === 'code' || tag === 'pre') return
|
||||||
|
|
||||||
|
const value: string = node.value
|
||||||
|
const regex = /\{\{#\$(.+?)#\}\}/g
|
||||||
|
let m: RegExpExecArray | null
|
||||||
|
let last = 0
|
||||||
|
const parts: any[] = []
|
||||||
|
|
||||||
|
while ((m = regex.exec(value))) {
|
||||||
|
if (m.index > last)
|
||||||
|
parts.push({ type: 'text', value: value.slice(last, m.index) })
|
||||||
|
|
||||||
|
parts.push({
|
||||||
|
type: 'element',
|
||||||
|
tagName: 'variable',
|
||||||
|
properties: { path: m[1].trim() },
|
||||||
|
children: [], // 也可放文本 children
|
||||||
|
})
|
||||||
|
last = m.index + m[0].length
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parts.length) return
|
||||||
|
if (last < value.length)
|
||||||
|
parts.push({ type: 'text', value: value.slice(last) })
|
||||||
|
|
||||||
|
parent.children.splice(index, 1, ...parts)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Variable: React.FC<{ path: string }> = ({ path }) => {
|
||||||
|
return <span style={{ color: 'red', fontWeight: 700 }}>{path}</span>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user