MCPcopy
hub / github.com/npmx-dev/npmx.dev / renderFrontmatterTable

Function renderFrontmatterTable

server/utils/readme.ts:450–462  ·  view source on GitHub ↗

* Render YAML frontmatter as a GitHub-style key-value table.

(data: Record<string, unknown>)

Source from the content-addressed store, hash-verified

448 * Render YAML frontmatter as a GitHub-style key-value table.
449 */
450function renderFrontmatterTable(data: Record<string, unknown>): string {
451 const entries = Object.entries(data)
452 if (entries.length === 0) return ''
453
454 const rows = entries
455 .map(([key, value]) => {
456 const displayValue =
457 typeof value === 'object' && value !== null ? JSON.stringify(value) : String(value ?? '')
458 return `<tr><th>${escapeHtml(key)}</th><td>${escapeHtml(displayValue)}</td></tr>`
459 })
460 .join('\n')
461 return `<table><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>\n${rows}\n</tbody></table>\n`
462}
463
464// Extract and preserve allowed attributes from HTML heading tags
465function extractHeadingAttrs(attrsString: string): string {

Callers 1

renderReadmeHtmlFunction · 0.85

Calls 1

escapeHtmlFunction · 0.90

Tested by

no test coverage detected