Skip to content

Commit

Permalink
🚸 (dify) Auto convert non-md links to md flavoured links
Browse files Browse the repository at this point in the history
Closes #1405
  • Loading branch information
baptisteArno committed Apr 3, 2024
1 parent 3aee9e7 commit 68ad0f2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/forge/blocks/difyAi/actions/createChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export const createChatMessage = createAction({
if (!mapping.variableId) return

const item = mapping.item ?? 'Answer'
if (item === 'Answer') variables.set(mapping.variableId, answer)
if (item === 'Answer')
variables.set(mapping.variableId, convertNonMarkdownLinks(answer))

if (item === 'Conversation ID')
variables.set(mapping.variableId, conversationId)
Expand All @@ -140,3 +141,8 @@ export const createChatMessage = createAction({
},
},
})

const convertNonMarkdownLinks = (text: string) => {
const nonMarkdownLinks = /(?<![\([])https?:\/\/\S+/g
return text.replace(nonMarkdownLinks, (match) => `[${match}](${match})`)
}

0 comments on commit 68ad0f2

Please sign in to comment.