假设我的库中有两个名为SuperBase
的TypeScript类。 Database
和Record
。
使用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
答案 0 :(得分:1)
您可以在单个命令中使用typedoc
,typedoc-plugin-markdown
,showdown
和concat-md
。结果,您将Markdown和HTML放在了一起。
(免责声明:我是开源concat-md
和readmeasy
的开发人员)
typedoc-plugin-markdown
从您的TypeDoc注释中生成一系列Markdown文件,而concat-md
从多个Markdown文件中创建一个文件。
如果除了包含创建的API Markdown文件之外,还需要进一步自定义README.md
文件,可以将README.hbs
或README.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
temp-docs
目录中:$ typedoc --plugin typedoc-plugin-markdown --theme markdown --mode file --out temp-docs
README.md
降价文件:(还创建目录,将目录名称添加为标题,并自动降低标题级别)$ concat-md --toc --decrease-title-levels --dir-name-as-title temp-docs > README.md
$ showdown makehtml -i README.md -o README.html