UNPKG

typedoc-plugin-markdown

Version:

A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.

87 lines (86 loc) 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.load = void 0; const fs = require("fs"); const path = require("path"); const typedoc_1 = require("typedoc"); const theme_1 = require("./theme"); function load(app) { app.options.addDeclaration({ help: '[Markdown Plugin] Do not render page title.', name: 'hidePageTitle', type: typedoc_1.ParameterType.Boolean, defaultValue: false, }); app.options.addDeclaration({ help: '[Markdown Plugin] Do not render breadcrumbs in template.', name: 'hideBreadcrumbs', type: typedoc_1.ParameterType.Boolean, defaultValue: false, }); app.options.addDeclaration({ help: '[Markdown Plugin] Specifies the base path that all links to be served from. If omitted all urls will be relative.', name: 'publicPath', type: typedoc_1.ParameterType.String, }); app.options.addDeclaration({ help: '[Markdown Plugin] Use HTML named anchors as fragment identifiers for engines that do not automatically assign header ids. Should be set for Bitbucket Server docs.', name: 'namedAnchors', type: typedoc_1.ParameterType.Boolean, defaultValue: false, }); app.options.addDeclaration({ help: '[Markdown Plugin] Output all reflections into seperate output files.', name: 'allReflectionsHaveOwnDocument', type: typedoc_1.ParameterType.Boolean, defaultValue: false, }); app.options.addDeclaration({ help: '[Markdown Plugin] Separator used to format filenames.', name: 'filenameSeparator', type: typedoc_1.ParameterType.String, defaultValue: '.', }); app.options.addDeclaration({ help: '[Markdown Plugin] The file name of the entry document.', name: 'entryDocument', type: typedoc_1.ParameterType.String, defaultValue: 'README.md', }); app.options.addDeclaration({ help: '[Markdown Plugin] Do not render in-page table of contents items.', name: 'hideInPageTOC', type: typedoc_1.ParameterType.Boolean, defaultValue: false, }); app.options.addDeclaration({ help: '[Markdown Plugin] Customise the index page title.', name: 'indexTitle', type: typedoc_1.ParameterType.String, }); app.converter.on(typedoc_1.Converter.EVENT_BEGIN, () => { typedoc_1.Renderer.getDefaultTheme = () => path.join(__dirname, 'resources'); }); app.converter.on(typedoc_1.Converter.EVENT_RESOLVE_BEGIN, () => { const themeName = app.options.getValue('theme'); const themeDir = path.join(__dirname); if (![themeDir, 'default', 'markdown'].includes(themeName)) { const themeFileName = path.resolve(path.join(themeName, 'theme.js')); if (fs.existsSync(themeFileName) && isMarkdownTheme(themeFileName)) { return; } app.logger.warn(`[typedoc-plugin-markdown] '${themeName}' is not a recognised markdown theme. If an html theme is required, please disable this plugin.`); } app.options.setValue('theme', themeDir); }); } exports.load = load; function isMarkdownTheme(themeFileName) { try { const ThemeClass = require(themeFileName).default; return ThemeClass.prototype instanceof theme_1.default; } catch (e) { return false; } }