Skip to content

Commit

Permalink
🐛 Fix invalid format for code blocks in streaming bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 12, 2024
1 parent 3f36780 commit db6d258
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.2.71",
"version": "0.2.72",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
25 changes: 19 additions & 6 deletions packages/embeds/js/src/components/bubbles/StreamingBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { streamingMessage } from '@/utils/streamingMessageSignal'
import { For, createEffect, createSignal } from 'solid-js'
import { marked } from 'marked'
import domPurify from 'dompurify'
import { isNotEmpty } from '@typebot.io/lib'

type Props = {
streamingMessageId: string
Expand All @@ -22,12 +23,24 @@ export const StreamingBubble = (props: Props) => {
if (streamingMessage()?.id !== props.streamingMessageId) return []
setContent(
streamingMessage()
?.content.split('\n\n')
.map((line) =>
domPurify.sanitize(marked.parse(line), {
ADD_ATTR: ['target'],
})
) ?? []
?.content.split('```')
.map((block, index) => {
if (index % 2 === 0) {
return block.split('\n\n').map((line) =>
domPurify.sanitize(marked.parse(line), {
ADD_ATTR: ['target'],
})
)
} else {
return [
domPurify.sanitize(marked.parse('```' + block + '```'), {
ADD_ATTR: ['target'],
}),
]
}
})
.flat()
.filter(isNotEmpty) ?? []
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.2.71",
"version": "0.2.72",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.2.71",
"version": "0.2.72",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit db6d258

Please sign in to comment.