Skip to content

fix: replace old-style <br> tags to fix Mermaid rendering issues #13792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/app/components/base/mermaid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import mermaid from 'mermaid'
import { usePrevious } from 'ahooks'
import { useTranslation } from 'react-i18next'
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'
import { cleanUpSvgCode } from './utils'
import LoadingAnim from '@/app/components/base/chat/chat/loading-anim'
import cn from '@/utils/classnames'
import ImagePreview from '@/app/components/base/image-uploader/image-preview'
Expand Down Expand Up @@ -44,7 +45,7 @@ const Flowchart = React.forwardRef((props: {
try {
if (typeof window !== 'undefined' && mermaidAPI) {
const svgGraph = await mermaidAPI.render('flowchart', PrimitiveCode)
const base64Svg: any = await svgToBase64(svgGraph.svg)
const base64Svg: any = await svgToBase64(cleanUpSvgCode(svgGraph.svg))
setSvgCode(base64Svg)
setIsLoading(false)
}
Expand Down
8 changes: 8 additions & 0 deletions web/app/components/base/mermaid/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { cleanUpSvgCode } from './utils'

describe('cleanUpSvgCode', () => {
it('replaces old-style <br> tags with the new style', () => {
const result = cleanUpSvgCode('<br>test<br>')
expect(result).toEqual('<br/>test<br/>')
})
})
3 changes: 3 additions & 0 deletions web/app/components/base/mermaid/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function cleanUpSvgCode(svgCode: string): string {
return svgCode.replaceAll('<br>', '<br/>')
}
Loading