D-ID Client SDK - v3.0.0-0
    Preparing search index...

    Function parseMessageParts

    • Splits a message's text into the typed parts a UI can render.

      The SDK already runs it over every message it builds and keeps the result on Message.parts, so this is for content that comes from somewhere else — a transcript you render outside the SDK, or text you assembled before handing it to a renderer. initialMessages no longer need it: pass parts: [] and the SDK runs this for you. It recognizes markdown images (![alt](url)), the video thumbnail form ([![alt](thumb)](video)), markdown links ([label](url)) and HTML anchors (<a href="url">label</a>); an image whose URL looks like a video becomes a video part instead, and a GIF is tagged with a mimeType, both under the rules MessagePart sets out. Everything the parser does not recognize is preserved verbatim as a text part, in its original order, and nothing is dropped or reordered; each recognized part replaces the markup it was written as, so the parts are not a concatenation of the input.

      Parameters

      • content: string

        The message text to split, as it appears in Message.content.

      Returns MessagePart[]

      The parts in the order they appear in content: a single text part when there is no markup to find, and an empty array for an empty string.

      import { parseMessageParts } from '@d-id/client-sdk';

      parseMessageParts('Here it is: ![a cat](https://example.com/cat.png) — enjoy!');
      // [
      // { type: 'text', text: 'Here it is: ' },
      // { type: 'image', src: 'https://example.com/cat.png', alt: 'a cat' },
      // { type: 'text', text: ' — enjoy!' },
      // ]