const HIDDEN_PREVIEW_TAG_PATTERN = /\[\[preview:([^\]\n]+)\]\]/g;

export function extractHiddenPreviewUrls(text: string) {
  return Array.from(String(text ?? '').matchAll(HIDDEN_PREVIEW_TAG_PATTERN))
    .map((match) => match[1]?.trim())
    .filter((value): value is string => Boolean(value));
}

export function stripHiddenPreviewTags(text: string) {
  return String(text ?? '')
    .replace(HIDDEN_PREVIEW_TAG_PATTERN, '')
    .replace(/\n{3,}/g, '\n\n')
    .trim();
}
