Skip to content

The open alternative to Salesforce, designed for AI.

506 B
Raw Blame
import { isUndefined } from '@sniptt/guards';
import { asRecord } from 'src/logic-functions/utils/asRecord';
import { getString } from 'src/logic-functions/utils/getString';

export const extractRichTextMarkdown = (
  rawValue: string,
): string | undefined => {
  try {
    const richTextValue = asRecord(JSON.parse(rawValue));

    if (isUndefined(richTextValue)) {
      return getString(rawValue);
    }

    return getString(richTextValue.markdown);
  } catch {
    return getString(rawValue);
  }
};