typescript - 是否可以使用 TypeDoc 为 TypeScript 项目生成单页文档 html?
问题描述
假设我的库中有两个 TypeScript 类,名为SuperBase
. 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
解决方案
您可以在单个命令中使用typedoc
、typedoc-plugin-markdown
和。结果,你们都有一个单一的页面 Markdown 和 HTML。showdown
concat-md
(免责声明:我是开源的开发者concat-md
和readmeasy
)
如何
typedoc-plugin-markdown
从您的 TypeDoc 注释生成一系列 Markdown 文件,并concat-md
从多个 Markdown 文件创建一个文件。
README.md
如果除了包含创建的 API Markdown 文件之外,您还需要进一步自定义文件,您可以使用一个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
- 使用 TypeDoc 注释在
temp-docs
目录中创建 Markdown 文件:
$ typedoc --plugin typedoc-plugin-markdown --theme markdown --mode file --out temp-docs
- 从它们创建一个
README.md
Markdown 文件:(还创建目录,添加目录名称作为标题,并自动降低标题级别)
$ concat-md --toc --decrease-title-levels --dir-name-as-title temp-docs > README.md
- 使用任何转换器将创建的 Markdown 转换为 HTML:(我在此示例中使用了摊牌)
$ showdown makehtml -i README.md -o README.html
推荐阅读
- docker - OpenShift - 在 minishift 中以 root 身份运行容器
- php - 向任何自定义页面或仪表板显示 Woocommerce 订阅操作
- ios - IOS 应用程序在发布版本中崩溃但在调试中没有:应用内购买
- wordpress - 子域总是重定向到主域
- python - Heroku:ModuleNotFoundError:没有名为“bar”的模块
- ios - SKProductsRequestDelegate 方法是否总是在主线程上调用?
- xamarin - 如何知道 Azure Hosted VS2017 Agent 中的 Xamarin Android 项目引用了哪个版本的 Xamarin.Android sdk?
- c# - 如何将所有 C# 8 可空引用警告视为错误?
- php - 数据库未使用 php 从表单接收值
- android - 为什么我的通知没有在指定时间出现