UNPKG

ts-markdown

Version:

An extensible TypeScript markdown generator that takes JSON and creates a markdown document.

29 lines (28 loc) 879 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.link = exports.linkRenderer = void 0; /** * The renderer for link entries. * * @param entry The link entry. * @param options Document-level render options. * @returns Link markdown content. */ const linkRenderer = (entry, options) => { if ('link' in entry) { const formattedLink = entry.link.href.replace(/\s/g, '%20'); if (!entry.link.text) { return `<${formattedLink}>`; } const titleSegment = entry.link.title !== undefined ? ` "${entry.link.title}"` : ''; return `[${entry.link.text}](${formattedLink}${titleSegment})`; } throw new Error('Entry is not a link entry. Unable to render.'); }; exports.linkRenderer = linkRenderer; function link(settings) { return { link: settings, }; } exports.link = link;