Skip to content

An AI-powered search engine with a generative UI

597 B
Raw Blame
import { replaceDraftBlocks } from '@/lib/draft/draft'

import { linkedCardsFenceToMarkdown } from './linked-cards-markdown'

/**
 * Remove ```spec fenced blocks from text content, keeping linked Card items as
 * a markdown list, and unwrap ````draft blocks to their content.
 * Used when copying message text to clipboard.
 */
export function stripSpecBlocks(text: string): string {
  return replaceDraftBlocks(text, ({ content }) => content)
    .replace(/```spec[\s\S]*?```/g, block => {
      return linkedCardsFenceToMarkdown(block) ?? ''
    })
    .replace(/\n{3,}/g, '\n\n')
    .trim()
}