import { pre, render } from './markdown.js'; import type { HyperschemaLinkJsExample } from './types.js'; /** * Renders a JavaScript example as a Markdown `
` block. * * When `renderFull` is false (default), only the collapsed summary is emitted. * When `renderFull` is true, the full code example is included inside the * details block, optionally with the `open` attribute. */ export function renderExample( example: HyperschemaLinkJsExample, options?: { renderFull?: boolean; isExpanded?: boolean }, ): string { if (!example.request?.code) { return ''; } if (!options?.renderFull) { return `
Example: ${example.title}
`; } const content = render( example.description, pre({ language: 'javascript' }, example.request.code), ); const openAttr = options.isExpanded ? ' open' : ''; return `\nExample: ${example.title}\n\n${content}\n
`; }