MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / renderEntry

Function renderEntry

scripts/fungrim/gen-reference-doc.ts:279–340  ·  view source on GitHub ↗

Render one identity entry into `lines`.

(
  lines: string[],
  ce: ReturnType<typeof createEngine>,
  headDesc: Map<string, string>,
  { e, u }: Resolved
)

Source from the content-addressed store, hash-verified

277
278/** Render one identity entry into `lines`. */
279function renderEntry(
280 lines: string[],
281 ce: ReturnType<typeof createEngine>,
282 headDesc: Map<string, string>,
283 { e, u }: Resolved
284): number {
285 let boxFailures = 0;
286
287 const latex = mathjsonToLatex(ce, e, e.formula);
288 if (latex === null) {
289 boxFailures++;
290 lines.push('```json', JSON.stringify(e.formula), '```');
291 } else {
292 lines.push(`$$${latex}$$`);
293 }
294 lines.push('');
295
296 // OPTION-B hook: render Fungrim's prose description once the corpus carries
297 // it (dormant until a re-translation adds a per-entry `description` field).
298 const desc = (e as any).description;
299 if (typeof desc === 'string' && desc.trim()) {
300 lines.push(desc.trim(), '');
301 }
302
303 const conds: string[] = [];
304 if (e.assumptions) {
305 const a = mathjsonToLatex(ce, e, e.assumptions);
306 if (a) conds.push(`$${a}$`);
307 }
308 for (const alt of ((e as any).assumptionAlternatives ?? []) as unknown[]) {
309 const a = mathjsonToLatex(ce, e, alt);
310 if (a) conds.push(`$${a}$`);
311 }
312 if (conds.length === 1) lines.push(`**Holds when** ${conds[0]}.`);
313 else if (conds.length > 1)
314 lines.push(`**Holds when** ${conds.join(' &nbsp;_or_&nbsp; ')}.`);
315
316 const syms = (e.heads ?? [])
317 .filter((h) => headDesc.has(h))
318 .map((h) => `**${h}** — ${headDesc.get(h)}`);
319 if (syms.length) lines.push(`**Symbols:** ${syms.join('; ')}.`);
320
321 const usageStr = usageSentence(u);
322 if (usageStr) lines.push(usageStr);
323
324 // Curated (non-hex) entries carry an internal provenance note in
325 // `references`, not a citation — suppress it.
326 const refs = isHexId(e.id) ? referencesOf(e) : [];
327 if (refs.length === 1) lines.push(`**Reference:** ${renderReference(refs[0])}`);
328 else if (refs.length > 1) {
329 lines.push('**References:**');
330 for (const r of refs) lines.push(`- ${renderReference(r)}`);
331 }
332
333 lines.push(
334 isHexId(e.id)
335 ? `[\`${e.id}\` · Fungrim entry ↗](${FUNGRIM_ENTRY(e.id)})`
336 : `\`${e.id}\` · _curated identity (not in the upstream Fungrim corpus)_`

Callers 1

generateReferenceDocFunction · 0.85

Calls 9

mathjsonToLatexFunction · 0.85
usageSentenceFunction · 0.85
isHexIdFunction · 0.85
referencesOfFunction · 0.85
renderReferenceFunction · 0.85
FUNGRIM_ENTRYFunction · 0.85
mapMethod · 0.65
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected