🚸 Rewrite the markdown deserializer to improve br… (#1198)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated markdown handling and serialization libraries for improved performance and accuracy in text formatting. - **New Features** - Enhanced rich text and markdown conversion capabilities, providing users with more reliable and seamless text formatting options. - **Documentation** - Added detailed documentation for markdown to rich text conversion and vice versa, ensuring easier understanding and implementation for developers. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@ -18,7 +18,6 @@
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"@typebot.io/variables": "workspace:*",
|
||||
"@udecode/plate-common": "21.1.5",
|
||||
"@udecode/plate-serializer-md": "24.4.0",
|
||||
"ai": "2.2.31",
|
||||
"chrono-node": "2.7.0",
|
||||
"date-fns": "2.30.0",
|
||||
|
@ -11,13 +11,10 @@ import {
|
||||
getVariablesToParseInfoInText,
|
||||
parseVariables,
|
||||
} from '@typebot.io/variables/parseVariables'
|
||||
import { TDescendant, createPlateEditor } from '@udecode/plate-common'
|
||||
import {
|
||||
createDeserializeMdPlugin,
|
||||
deserializeMd,
|
||||
} from '@udecode/plate-serializer-md'
|
||||
import { TDescendant } from '@udecode/plate-common'
|
||||
import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants'
|
||||
import { defaultVideoBubbleContent } from '@typebot.io/schemas/features/blocks/bubbles/video/constants'
|
||||
import { convertMarkdownToRichText } from '@typebot.io/lib/markdown/convertMarkdownToRichText'
|
||||
|
||||
type Params = {
|
||||
version: 1 | 2
|
||||
@ -207,28 +204,3 @@ const applyElementStyleToDescendants = (
|
||||
),
|
||||
}
|
||||
})
|
||||
|
||||
const convertMarkdownToRichText = (text: string): TDescendant[] => {
|
||||
const spacesBefore = text.match(/^[\s]+/)
|
||||
const spacesAfter = text.match(/[\s]+$/)
|
||||
const plugins = [createDeserializeMdPlugin()]
|
||||
return [
|
||||
...(spacesBefore?.at(0)
|
||||
? [
|
||||
{
|
||||
type: 'p',
|
||||
text: spacesBefore.at(0),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...deserializeMd(createPlateEditor({ plugins }) as unknown as any, text),
|
||||
...(spacesAfter?.at(0)
|
||||
? [
|
||||
{
|
||||
type: 'p',
|
||||
text: spacesAfter.at(0),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/con
|
||||
import { InputBlockType } from '@typebot.io/schemas/features/blocks/inputs/constants'
|
||||
import { defaultPictureChoiceOptions } from '@typebot.io/schemas/features/blocks/inputs/pictureChoice/constants'
|
||||
import { defaultChoiceInputOptions } from '@typebot.io/schemas/features/blocks/inputs/choice/constants'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/serializer/convertRichTextToMarkdown'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown'
|
||||
|
||||
export const convertInputToWhatsAppMessages = (
|
||||
input: NonNullable<ContinueChatResponse['input']>,
|
||||
|
@ -3,7 +3,7 @@ import { WhatsAppSendingMessage } from '@typebot.io/schemas/features/whatsapp'
|
||||
import { isSvgSrc } from '@typebot.io/lib/utils'
|
||||
import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants'
|
||||
import { VideoBubbleContentType } from '@typebot.io/schemas/features/blocks/bubbles/video/constants'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/serializer/convertRichTextToMarkdown'
|
||||
import { convertRichTextToMarkdown } from '@typebot.io/lib/markdown/convertRichTextToMarkdown'
|
||||
|
||||
const mp4HttpsUrlRegex = /^https:\/\/.*\.mp4$/
|
||||
|
||||
|
Reference in New Issue
Block a user