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

Function renderReference

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

Turn a reference (URL or citation string) into a markdown link.

(ref: string)

Source from the content-addressed store, hash-verified

250
251/** Turn a reference (URL or citation string) into a markdown link. */
252function renderReference(ref: string): string {
253 const urlMatch = ref.match(/https?:\/\/[^\s)]+/);
254 if (urlMatch && ref.trim() === urlMatch[0]) {
255 try {
256 const host = new URL(urlMatch[0]).host.replace(/^www\./, '');
257 return `[${host}](${urlMatch[0]})`;
258 } catch {
259 return urlMatch[0];
260 }
261 }
262 if (urlMatch) return ref.replace(urlMatch[0], `[${urlMatch[0]}](${urlMatch[0]})`);
263 return ref;
264}
265
266function referencesOf(e: Entry): string[] {
267 const r = e.references;

Callers 1

renderEntryFunction · 0.85

Calls 2

matchMethod · 0.65
replaceMethod · 0.65

Tested by

no test coverage detected