Turn a reference (URL or citation string) into a markdown link.
(ref: string)
| 250 | |
| 251 | /** Turn a reference (URL or citation string) into a markdown link. */ |
| 252 | function 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 | |
| 266 | function referencesOf(e: Entry): string[] { |
| 267 | const r = e.references; |
no test coverage detected