mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
'use client'
|
|
import type { FC } from 'react'
|
|
import * as React from 'react'
|
|
|
|
import s from './style.module.css'
|
|
|
|
type IVarHighlightProps = {
|
|
name: string
|
|
className?: string
|
|
}
|
|
|
|
const VarHighlight: FC<IVarHighlightProps> = ({
|
|
name,
|
|
className = '',
|
|
}) => {
|
|
return (
|
|
<div
|
|
key={name}
|
|
className={`${s.item} ${className} mb-2 inline-flex h-5 items-center justify-center rounded-md px-1 text-xs font-medium text-primary-600`}
|
|
>
|
|
<span className="opacity-60">{'{{'}</span>
|
|
<span>{name}</span>
|
|
<span className="opacity-60">{'}}'}</span>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// DEPRECATED: This function is vulnerable to XSS attacks and should not be used
|
|
// Use the VarHighlight React component instead
|
|
export const varHighlightHTML = ({ name, className = '' }: IVarHighlightProps) => {
|
|
const escapedName = name
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''')
|
|
|
|
const html = `<div class="${s.item} ${className} inline-flex mb-2 items-center justify-center px-1 rounded-md h-5 text-xs font-medium text-primary-600">
|
|
<span class='opacity-60'>{{</span>
|
|
<span>${escapedName}</span>
|
|
<span class='opacity-60'>}}</span>
|
|
</div>`
|
|
return html
|
|
}
|
|
|
|
export default React.memo(VarHighlight)
|