🐛 (text) Fix text bubble content parsing when starting with variable
Closes #1594
This commit is contained in:
@ -16,6 +16,7 @@ import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/con
|
||||
import { defaultVideoBubbleContent } from '@typebot.io/schemas/features/blocks/bubbles/video/constants'
|
||||
import { convertMarkdownToRichText } from '@typebot.io/lib/markdown/convertMarkdownToRichText'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown'
|
||||
import { isSingleVariable } from '@typebot.io/variables/isSingleVariable'
|
||||
|
||||
type Params = {
|
||||
version: 1 | 2
|
||||
@ -144,7 +145,9 @@ export const parseVariablesInRichText = (
|
||||
: undefined
|
||||
lastTextEndIndex = variableInText.endIndex
|
||||
const isStandaloneElement =
|
||||
isEmpty(textBeforeVariable) && isEmpty(textAfterVariable)
|
||||
isEmpty(textBeforeVariable) &&
|
||||
isEmpty(textAfterVariable) &&
|
||||
variablesInText.length === 1
|
||||
const variableElements = convertMarkdownToRichText(
|
||||
isStandaloneElement
|
||||
? variableInText.value
|
||||
@ -193,8 +196,7 @@ export const parseVariablesInRichText = (
|
||||
const type =
|
||||
element.children.length === 1 &&
|
||||
'text' in element.children[0] &&
|
||||
(element.children[0].text as string).startsWith('{{') &&
|
||||
(element.children[0].text as string).endsWith('}}') &&
|
||||
isSingleVariable(element.children[0].text as string) &&
|
||||
element.type !== 'a'
|
||||
? 'variable'
|
||||
: element.type
|
||||
|
5
packages/variables/isSingleVariable.ts
Normal file
5
packages/variables/isSingleVariable.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export const isSingleVariable = (value: string | undefined): boolean =>
|
||||
!!value &&
|
||||
value.startsWith('{{') &&
|
||||
value.endsWith('}}') &&
|
||||
value.split('{{').length === 2
|
Reference in New Issue
Block a user