UNPKG

doxdox-renderer-markdown

Version:
46 lines (36 loc) 1.28 kB
import { markdownTable } from 'markdown-table'; const renderMethod = (method) => `## ${method.fullName} ${method.description} ${method.params.length ? `### Parameters ${markdownTable([ ['Name', 'Types', 'Description'], ...method.params.map(({ name, types, description }) => [ name, types .map(type => type.replace(/</, '&lt;').replace(/>/, '&gt;')) .join(', '), description || '' ]) ])}` : ''} ${method.returns.length ? `### Returns ${method.returns.map(param => `${param.types .map(type => type.replace(/</, '&lt;').replace(/>/, '&gt;')) .join(', ')} ${param.description || ''}`)}` : ''} `; const renderFile = (file) => `${file.methods.map(method => renderMethod(method)).join('')}`; export default async (doc) => `# ${doc.homepage ? `[${doc.name}](${doc.homepage})` : doc.name} ${doc.description ? `> ${doc.description}` : ''} ${doc.files .map(file => renderFile(file)) .join('') .trim()} Documentation generated with [doxdox](https://github.com/docsbydoxdox/doxdox) ${!doc.config || doc.config['hideGeneratedTimestamp'] !== true ? `\nGenerated on ${new Date().toDateString()} ${new Date().toTimeString()}\n` : ''}`;