import React, { useMemo, useState } from 'react' const COLLAPSE_AT = 560 function renderMarkdownSafe(text) { const lines = text.split(/\n{2,}/) return lines.map((line, lineIndex) => { const parts = [] let rest = line let key = 0 const linkPattern = /\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g let match = linkPattern.exec(rest) let lastIndex = 0 while (match) { if (match.index > lastIndex) { parts.push({rest.slice(lastIndex, match.index)}) } parts.push( {match[1]} , ) lastIndex = match.index + match[0].length match = linkPattern.exec(rest) } if (lastIndex < rest.length) { parts.push({rest.slice(lastIndex)}) } return (

{parts}

) }) } export default function ArtworkDescription({ artwork }) { const [expanded, setExpanded] = useState(false) const content = (artwork?.description || '').trim() if (content.length === 0) return null const collapsed = content.length > COLLAPSE_AT && !expanded const visibleText = collapsed ? `${content.slice(0, COLLAPSE_AT)}…` : content const rendered = useMemo(() => renderMarkdownSafe(visibleText), [visibleText]) return (

Description

{rendered}
{content.length > COLLAPSE_AT && ( )}
) }