@aaronhuggins/concat-md 中文文档教程
concat-md
CLI 和 API 用于连接降价文件并根据需要进行修改。
Install
$ npm install -g concat-md
或者通过 npx
使用它:
$ npx concat-md docs
Usage
如果文件已经在 markdown 中有标题:
$ concat-md --toc --decrease-title-levels --dir-name-as-title typedoc-api-docs > README.md
如果文件在 FrontMatter 元数据中有标题:
$ concat-md --toc --decrease-title-levels --title-key title --file-name-as-title --dir-name-as-title docs > README.md
如果文件 没有没有标题:
$ concat-md --toc --decrease-title-levels --file-name-as-title --dir-name-as-title docs > README.md
Features
- Scans all markdown files in a directory,
- Optionally ignores some files,
- Concatenates all of them,
- Adds table of contents,
- Optionally adds titles from
FrontMatter
, file names and directory names, - Decreases level of existing titles to comply with added titles,
- Adds anchor tags (
<a name=""></a>
) to files, if no optional titles are generated. - Converts relative links to point to concatenated file,
- Works async (default) and sync.
CLI Options
Usage
$ concat-md [options] <dir>
Options
--ignore <globs csv> - Glob patterns to exclude in 'dir'.
--toc - Adds table of the contents at the beginning of file.
--decrease-title-levels - Whether to decrease levels of all titles in markdown file to set them below file and directory title levels.
--start-title-level-at <level no> - Level to start file and directory levels. Default: 1
--join-string <string> - String to be used to join concatenated files. Default: new line
--title-key <key name> - Key name to get title in 'FrontMatter' meta data in markdown headers.
--file-name-as-title - Whether to use file names as titles.
--dir-name-as-title - Whether to use directory names as titles.
--debug - Print stack trace in errors.
Examples
If files have titles in markdown already:
$ npx concat-md --toc --decrease-title-levels --dir-name-as-title typedoc-api-docs > README.md
If files have titles in FrontMatter meta data:
$ npx concat-md --toc --decrease-title-levels --title-key title --file-name-as-title --dir-name-as-title docs > README.md
If files don't have titles:
$ npx concat-md --toc --decrease-title-levels --file-name-as-title --dir-name-as-title docs > README.md
Example
└─ Development
└─ Projects
└─ project-a
├─ docs
├─ classes
│ ├─ widget.md
│ ├─ utility.md
└─ interfaces
└─ screen.md
classes/widget.md
# Description
Widget details lorem ipsum...
classes/utility.md
# Description
Utility details lorem ipsum...
interfaces/screen.md
# Description
Screen details lorem ipsum...
$ md-merge --decrease-title-levels --file-name-as-title --dir-name-as-title docs > README.md
以上命令;
- Concatenates markdown files,
- Adds directory names and file names as title,
- Decreases level of
Description
titles, - Outputs to
README.md
as below:
README.md
# Classes
## Widget
### Description
Widget details lorem ipsum...
## Utility
### Description
Utility details lorem ipsum...
# Interfaces
## Screen
### Description
Screen details lorem ipsum...
API
Index
Interfaces
Functions
Functions
concatMd
▸ concatMd (目录
:字符串,选项?
:ConcatOptions):Promise< string>
扫描并连接给定目录中的所有降价文件。
Example
import concatMd, { concatMdSync } from "concat-md";
参数:
Name | Type | Description |
---|---|---|
dir | string | is the directory to scan markdown files in. |
options? | ConcatOptions | are several parameters to modify concatenation behaviour. |
返回: Promise
markdown 文件的串联内容。
concatMdSync
▸ concatMdSync(dir
:字符串,选项?
:ConcatOptions): string
扫描并连接给定目录中的所有降价文件。
Example
import concatMd, { concatMdSync } from "concat-md";
参数:
Name | Type | Description |
---|---|---|
dir | string | is the directory to scan markdown files in. |
options? | ConcatOptions | are several parameters to modify concatenation behaviour. |
返回: string
markdown 文件的连接内容。
Interfaces
Interface: ConcatOptions
Concat 函数选项。
Hierarchy
- ConcatOptions
Index
Properties
- decreaseTitleLevels
- dirNameAsTitle
- fileNameAsTitle
- ignore
- joinString
- startTitleLevelAt
- titleKey
- toc
- tocLevel
Properties
Optional
decreaseTitleLevels
• 减少TitleLevels? : 未定义 | 假 | true
是否降低降价文件中所有标题的级别以将它们设置在文件和目录标题级别之下。
Optional
dirNameAsTitle
• dirNameAsTitle? : 未定义 | 假 | true
是否使用目录名作为标题。
Optional
fileNameAsTitle
• fileNameAsTitle? : 未定义 | 假 | true
是否使用文件名作为标题。
Optional
ignore
• 忽略? : 字符串 | string[]
定义在 index.ts:48< /a>
要在 dir
中排除的 Glob 模式。
Optional
joinString
• 加入字符串? : 未定义 | string
用于连接串联文件的字符串。
Optional
startTitleLevelAt
• startTitleLevelAt? : 未定义 | number
开始文件和目录级别的级别。
Optional
titleKey
• titleKey? : 未定义 | string
定义在 index.ts:64
在 Markdown 标头的 FrontMatter
元数据中获取标题的键名。
Optional
toc
• 目录? : 未定义 | 假 | true
是否添加目录。
Optional
tocLevel
• tocLevel? : 未定义 | number
将 TOC 条目限制为仅达到指定级别的标题。
concat-md
CLI and API to concatenate markdown files and modify as necessary.
Install
$ npm install -g concat-md
or use it via npx
:
$ npx concat-md docs
Usage
If files have titles in markdown already:
$ concat-md --toc --decrease-title-levels --dir-name-as-title typedoc-api-docs > README.md
If files have titles in FrontMatter meta data:
$ concat-md --toc --decrease-title-levels --title-key title --file-name-as-title --dir-name-as-title docs > README.md
If files don't have titles:
$ concat-md --toc --decrease-title-levels --file-name-as-title --dir-name-as-title docs > README.md
Features
- Scans all markdown files in a directory,
- Optionally ignores some files,
- Concatenates all of them,
- Adds table of contents,
- Optionally adds titles from
FrontMatter
, file names and directory names, - Decreases level of existing titles to comply with added titles,
- Adds anchor tags (
<a name=""></a>
) to files, if no optional titles are generated. - Converts relative links to point to concatenated file,
- Works async (default) and sync.
CLI Options
Usage
$ concat-md [options] <dir>
Options
--ignore <globs csv> - Glob patterns to exclude in 'dir'.
--toc - Adds table of the contents at the beginning of file.
--decrease-title-levels - Whether to decrease levels of all titles in markdown file to set them below file and directory title levels.
--start-title-level-at <level no> - Level to start file and directory levels. Default: 1
--join-string <string> - String to be used to join concatenated files. Default: new line
--title-key <key name> - Key name to get title in 'FrontMatter' meta data in markdown headers.
--file-name-as-title - Whether to use file names as titles.
--dir-name-as-title - Whether to use directory names as titles.
--debug - Print stack trace in errors.
Examples
If files have titles in markdown already:
$ npx concat-md --toc --decrease-title-levels --dir-name-as-title typedoc-api-docs > README.md
If files have titles in FrontMatter meta data:
$ npx concat-md --toc --decrease-title-levels --title-key title --file-name-as-title --dir-name-as-title docs > README.md
If files don't have titles:
$ npx concat-md --toc --decrease-title-levels --file-name-as-title --dir-name-as-title docs > README.md
Example
└─ Development
└─ Projects
└─ project-a
├─ docs
├─ classes
│ ├─ widget.md
│ ├─ utility.md
└─ interfaces
└─ screen.md
classes/widget.md
# Description
Widget details lorem ipsum...
classes/utility.md
# Description
Utility details lorem ipsum...
interfaces/screen.md
# Description
Screen details lorem ipsum...
$ md-merge --decrease-title-levels --file-name-as-title --dir-name-as-title docs > README.md
Above command;
- Concatenates markdown files,
- Adds directory names and file names as title,
- Decreases level of
Description
titles, - Outputs to
README.md
as below:
README.md
# Classes
## Widget
### Description
Widget details lorem ipsum...
## Utility
### Description
Utility details lorem ipsum...
# Interfaces
## Screen
### Description
Screen details lorem ipsum...
API
Index
Interfaces
Functions
Functions
concatMd
▸ concatMd(dir
: string, options?
: ConcatOptions): Promise<string>
Defined in index.ts:295
Scans and concatenates all markdown files in given directory.
Example
import concatMd, { concatMdSync } from "concat-md";
Parameters:
Name | Type | Description |
---|---|---|
dir | string | is the directory to scan markdown files in. |
options? | ConcatOptions | are several parameters to modify concatenation behaviour. |
Returns: Promise<string>
concatenated contents of markdown files.
concatMdSync
▸ concatMdSync(dir
: string, options?
: ConcatOptions): string
Defined in index.ts:281
Scans and concatenates all markdown files in given directory.
Example
import concatMd, { concatMdSync } from "concat-md";
Parameters:
Name | Type | Description |
---|---|---|
dir | string | is the directory to scan markdown files in. |
options? | ConcatOptions | are several parameters to modify concatenation behaviour. |
Returns: string
concatenated contents of markdown files.
Interfaces
Interface: ConcatOptions
Concat function options.
Hierarchy
- ConcatOptions
Index
Properties
- decreaseTitleLevels
- dirNameAsTitle
- fileNameAsTitle
- ignore
- joinString
- startTitleLevelAt
- titleKey
- toc
- tocLevel
Properties
Optional
decreaseTitleLevels
• decreaseTitleLevels? : undefined | false | true
Defined in index.ts:52
Whether to decrease levels of all titles in markdown file to set them below file and directory title levels.
Optional
dirNameAsTitle
• dirNameAsTitle? : undefined | false | true
Defined in index.ts:72
Whether to use directory names as titles.
Optional
fileNameAsTitle
• fileNameAsTitle? : undefined | false | true
Defined in index.ts:68
Whether to use file names as titles.
Optional
ignore
• ignore? : string | string[]
Defined in index.ts:48
Glob patterns to exclude in dir
.
Optional
joinString
• joinString? : undefined | string
Defined in index.ts:60
String to be used to join concatenated files.
Optional
startTitleLevelAt
• startTitleLevelAt? : undefined | number
Defined in index.ts:56
Level to start file and directory levels.
Optional
titleKey
• titleKey? : undefined | string
Defined in index.ts:64
Key name to get title in FrontMatter
meta data in markdown headers.
Optional
toc
• toc? : undefined | false | true
Defined in index.ts:40
Whether to add a table of contents.
Optional
tocLevel
• tocLevel? : undefined | number
Defined in index.ts:44
Limit TOC entries to headings only up to the specified level.