verdnatura-chat/app/containers/markdown/formatText.ts

7 lines
230 B
TypeScript

// Support <http://link|Text>
export const formatText = (text: string): string =>
text.replace(
new RegExp('(?:<|<)((?:https|http):\\/\\/[^\\|]+)\\|(.+?)(?=>|>)(?:>|>)', 'gm'),
(match, url, title) => `[${title}](${url})`
);