首页 > 解决方案 > 是否可以使用 TypeDoc 为 TypeScript 项目生成单页文档 html?

问题描述

假设我的库中有两个 TypeScript 类,名为SuperBase. DatabaseRecord。_

是否可以使用 TypeDoc 生成具有以下非常简单格式的单个页面。它不必完全是那样,只是一些简单和相似的东西。

它应该非常简单和最小,并且只有一页。像你会在 Markdown 自述文件中写自己的东西。它需要做的只是从源中获取这些文档并将其粘贴到单个 HTML 页面中。TypeDoc 或者其他一些TypeScript工具可以做到这一点吗?

(header) SuperBase
(text) description of the package taken from package.json or somewhere else

(header) Database
(text) Description of the database taken from class docs

(subheader) connect(url: string)
(text) description of the connect method taken from method docs

(header) Record
(text) Description of the Record taken from class docs

(subheader) validate()
(text) description of the validate method taken from method docs

标签: typescripttypedoc

解决方案


您可以在单个命令中使用typedoctypedoc-plugin-markdown和。结果,你们都有一个单一的页面 Markdown 和 HTML。showdownconcat-md

(免责声明:我是开源的开发者concat-mdreadmeasy

如何

typedoc-plugin-markdown从您的 TypeDoc 注释生成一系列 Markdown 文件,并concat-md从多个 Markdown 文件创建一个文件。

README.md如果除了包含创建的 API Markdown 文件之外,您还需要进一步自定义文件,您可以使用一个README.hbsREADME.njk模板,readmeasy并将创建的 API Markdown 包含到您的自定义README.md.

例子

单一命令

下面的命令在临时目录中创建多个文件,将它们合并到README.md文件并删除临时目录。(rimraf模块用于删除,因为它是跨操作系统兼容的)

$ npm install -D typedoc typedoc-plugin-markdown concat-md rimraf showdown
$ rimraf temp-docs && typedoc --plugin typedoc-plugin-markdown --theme markdown --mode file --out temp-docs && concat-md --toc --decrease-title-levels --dir-name-as-title temp-docs > README.md && showdown makehtml -i README.md -o README.html && rimraf temp-docs

描述

  • 安装必要的模块:
$ npm install -D typedoc typedoc-plugin-markdown concat-md showdown
  • 使用 TypeDoc 注释在temp-docs目录中创建 Markdown 文件:
$ typedoc --plugin typedoc-plugin-markdown --theme markdown --mode file --out temp-docs
  • 从它们创建一个README.mdMarkdown 文件:(还创建目录,添加目录名称作为标题,并自动降低标题级别)
$ concat-md --toc --decrease-title-levels --dir-name-as-title temp-docs > README.md
  • 使用任何转换器将创建的 Markdown 转换为 HTML:(我在此示例中使用了摊牌)
$ showdown makehtml -i README.md -o README.html

推荐阅读