doxdox-renderer-markdown
Version:
Markdown renderer for doxdox.
46 lines (36 loc) • 1.28 kB
JavaScript
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(/</, '<').replace(/>/, '>'))
.join(', '),
description || ''
])
])}`
: ''}
${method.returns.length
? `### Returns
${method.returns.map(param => `${param.types
.map(type => type.replace(/</, '<').replace(/>/, '>'))
.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`
: ''}`;