在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sethen/markdown-include开源软件地址(OpenSource Url):https://github.com/sethen/markdown-include开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Table of Contents
markdown-includemarkdown-include is built using Node.js and allows you to include markdown files into other markdown files using a C style include syntax. Compile your markdown filesmarkdown-include's main feature is that it allows you to include markdown files into other markdown files. For example, you could place the following into a markdown file:
And assuming that
And assuming that
It would compile to:
Pretty neat, huh? Make a table of contentsAside from compiling your markdown files, markdown-include can also build your table of contents. This works by evaluating the heading tags inside of your files. Since markdown works on using For each heading that you would like to be included in a table of contents just add How To Installmarkdown-include is available on npm for easy installation:
Use the How To Use From The Command Linemarkdown-include is very easy to use whether on the command line or in your own node project. Each can help you compile your markdown files as you see fit. markdown-include does require that you define a Run from the command line to compile your documents like so:
markdown.json
How To Use As A ModuleJust require in your node project:
From there, you can use markdown-include's API to fit your needs. APIWhen using as a module, markdown-include offers an API for you to work with markdown files as detailed below:
|
Parameter(s) | Type | Description |
---|---|---|
title |
String |
Title of markdown style link. |
anchor |
String |
Markdown style anchor for linking. |
var markdownInclude = require('markdown-include');
markdownInclude.buildLink("My Link String", "#my-link-string"); // [My Link String](#my-link-string)
buildLinkString
A method for taking strings and building friendly markdown links. This is mostly used internally for building the table of contents.
buildLinkString(str: String) => String
Parameter(s) | Type | Description |
---|---|---|
str |
String |
File path of where everything should be compiled, like README.md . |
var markdownInclude = require('markdown-include');
markdownInclude.buildLinkString("My Link String"); // my-link-string
compileFiles
This is probably the most important method in markdown-include. It takes a path to your markdown.json file, reads your options and returns a promise. When the promise is resolved it returns the data to you. This is exactly the same as running markdown-include in the command line as it runs through the whole lifecycle.
compileFiles(path: String) => Object<Promise>
Parameter(s) | Type | Description |
---|---|---|
path |
String |
Compiles files when given the path to markdown.json |
var markdownInclude = require('markdown-include');
markdownInclude.compileFiles("path/to/markdown.json").then(function (data) {
// do something with compiled files
});
compileHeadingTags
A method for compiling heading tags (!heading
) in a given file.
compileHeadingTags(file: String)
Parameter(s) | Type | Description |
---|---|---|
file |
String |
File with !heading tags |
var markdownInclude = require('markdown-include');
markdownInclude.compileHeadingTags("my_file.md");
findHeadingTags
A method for finding heading tags (!heading
) in a string.
findHeadingTags(data: String) => Array<String>
Parameter(s) | Type | Description |
---|---|---|
data |
String |
Data with !heading tags |
var markdownInclude = require('markdown-include');
markdownInclude.findHeadingTags("### A Heading !heading"); // [ "### A Heading !heading" ]
findIncludeTags
A method for finding include tags (#include "my-include.md"
) in a string.
findIncludeTags(data: String) => Array<String>
Parameter(s) | Type | Description |
---|---|---|
data |
String |
Data with #include "my-include.md" tags |
var markdownInclude = require('markdown-include');
markdownInclude.findIncludeTags('#include "my-include.md"'); // [ '#include "my-include.md"' ]
parseHeadingTag
Parses a heading tag based on the amount of asterisks present before it (### Heading
)
parseHeadingTag(headingTag: String) => Object<count: Number, headingTag: String>
Parameter(s) | Type | Description |
---|---|---|
headingTag |
String |
Heading tag to parse |
var markdownInclude = require('markdown-include');
markdownInclude.parseHeadingTag('### Heading'); // { count: 3, headingTag: 'Heading' }
parseIncludeTag
Parses a include tag (#include "my-include.md"
)
parseIncludeTag(tag: String) => String
Parameter(s) | Type | Description |
---|---|---|
tag |
String |
Heading tag to parse |
var markdownInclude = require('markdown-include');
markdownInclude.parseIncludeTag('#include "my-include.md"'); // "my-include.md"
processFile
Processes a file and adds it to the build object for compiling.
processFile(file: String, currentFile: String)
Parameter(s) | Type | Description |
---|---|---|
file |
String |
File for processing |
currentFile |
String |
Current file include file was found in for additional processing |
var markdownInclude = require('markdown-include');
markdownInclude.processFile('another-include.md', 'my-include.md');
processIncludeTags
Processes a file and adds it to the build object for compiling.
processIncludeTags(file: String, currentFile: String, tags: Array<String>) => Array<String>
Parameter(s) | Type | Description |
---|---|---|
file |
String |
File for processing |
currentFile |
String |
Current file include file was found in for additional processing |
tags |
Array<String> |
Current file include file was found in for additional processing |
var markdownInclude = require('markdown-include');
markdownInclude.processIncludeTags('another-include.md', 'my-include.md', ['one-include.md']); // ['one-include.md']
replaceIncludeTags
Replaces include tags in given file with actual data (file must be added to build object first with processFile
).
replaceIncludeTags(file: String) => String
Parameter(s) | Type | Description |
---|---|---|
file |
String |
File to replace include tags |
var markdownInclude = require
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论