• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

sethen/markdown-include: Include markdown files into other markdown files with C ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

sethen/markdown-include

开源软件地址(OpenSource Url):

https://github.com/sethen/markdown-include

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

Table of Contents

markdown-include

Build Status

markdown-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 files

markdown-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:

#include "markdown-file.md"
#include "another-markdown-file.md"

And assuming that markdown.file.md contents are:

Something in markdown file!

And assuming that another-markdown-file.md contents are:

Something in another markdown file!

It would compile to:

Something in markdown file!
Something in another markdown file!

Pretty neat, huh?

Make a table of contents

Aside 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 making HTML headings, this makes it easy to assemble table of contents from them. The more # you have in front of your headings (up to 6) will decide how the table of contents is built. Use one # and it's a top level navigation item... Use two # and it would be underneath the previous navigation item and so on.

For each heading that you would like to be included in a table of contents just add !heading to the end of it.

How To Install

markdown-include is available on npm for easy installation:

npm install markdown-include

Use the -g flag if you wish to install markdown-include globally on your system. Use the --save flag to save in your package.json file in your local project.

How To Use From The Command Line

markdown-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 markdown.json file with your options for compile. See below for all of the options available to you.

Run from the command line to compile your documents like so:

node_modules/bin/cli.js path/to/markdown.json

markdown.json

markdown.json can be populated with the following options:

Option Type Description
build String File path of where everything should be compiled, like README.md.
files Array Array of files to to compile.
tableOfContents Object Object to hold options for table of contents generation.
tableOfContents.heading String Heading for table of contents (use markdown syntax if desired).
tableOfContents.lead String What navigation items in table of contents lead with. If value is number will add numbers before each item and subitem. If not, will add asterisks. Refer to markdown syntax to understand the difference.

How To Use As A Module

Just require in your node project:

var markdownInclude = require('markdown-include');

From there, you can use markdown-include's API to fit your needs.

API

When using as a module, markdown-include offers an API for you to work with markdown files as detailed below:


buildLink

Description

A method for making markdown style anchor tags.

Signature

buildLink(title: String, anchor: String) => String

Parameters

Parameter(s) Type Description
title String Title of markdown style link.
anchor String Markdown style anchor for linking.

Example

var markdownInclude = require('markdown-include');
markdownInclude.buildLink("My Link String", "#my-link-string"); // [My Link String](#my-link-string)

buildLinkString

Description

A method for taking strings and building friendly markdown links. This is mostly used internally for building the table of contents.

Signature

buildLinkString(str: String) => String

Parameters

Parameter(s) Type Description
str String File path of where everything should be compiled, like README.md.

Example

var markdownInclude = require('markdown-include');
markdownInclude.buildLinkString("My Link String"); // my-link-string

compileFiles

Description

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.

Signature

compileFiles(path: String) => Object<Promise>

Parameters

Parameter(s) Type Description
path String Compiles files when given the path to markdown.json

Example

var markdownInclude = require('markdown-include');
markdownInclude.compileFiles("path/to/markdown.json").then(function (data) {
	// do something with compiled files
});

compileHeadingTags

Description

A method for compiling heading tags (!heading) in a given file.

Signature

compileHeadingTags(file: String)

Parameters

Parameter(s) Type Description
file String File with !heading tags

Example

var markdownInclude = require('markdown-include');
markdownInclude.compileHeadingTags("my_file.md");

findHeadingTags

Description

A method for finding heading tags (!heading) in a string.

Signature

findHeadingTags(data: String) => Array<String>

Parameters

Parameter(s) Type Description
data String Data with !heading tags

Example

var markdownInclude = require('markdown-include');
markdownInclude.findHeadingTags("### A Heading !heading"); // [ "### A Heading !heading" ]

findIncludeTags

Description

A method for finding include tags (#include "my-include.md") in a string.

Signature

findIncludeTags(data: String) => Array<String>

Parameters

Parameter(s) Type Description
data String Data with #include "my-include.md" tags

Example

var markdownInclude = require('markdown-include');
markdownInclude.findIncludeTags('#include "my-include.md"'); // [ '#include "my-include.md"' ]

parseHeadingTag

Description

Parses a heading tag based on the amount of asterisks present before it (### Heading)

Signature

parseHeadingTag(headingTag: String) => Object<count: Number, headingTag: String>

Parameters

Parameter(s) Type Description
headingTag String Heading tag to parse

Example

var markdownInclude = require('markdown-include');
markdownInclude.parseHeadingTag('### Heading'); // { count: 3, headingTag: 'Heading' }

parseIncludeTag

Description

Parses a include tag (#include "my-include.md")

Signature

parseIncludeTag(tag: String) => String

Parameters

Parameter(s) Type Description
tag String Heading tag to parse

Example

var markdownInclude = require('markdown-include');
markdownInclude.parseIncludeTag('#include "my-include.md"'); // "my-include.md"

processFile

Description

Processes a file and adds it to the build object for compiling.

Signature

processFile(file: String, currentFile: String)

Parameters

Parameter(s) Type Description
file String File for processing
currentFile String Current file include file was found in for additional processing

Example

var markdownInclude = require('markdown-include');
markdownInclude.processFile('another-include.md', 'my-include.md');

processIncludeTags

Description

Processes a file and adds it to the build object for compiling.

Signature

processIncludeTags(file: String, currentFile: String, tags: Array<String>) => Array<String>

Parameters

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

Example

var markdownInclude = require('markdown-include');
markdownInclude.processIncludeTags('another-include.md', 'my-include.md', ['one-include.md']); // ['one-include.md']

replaceIncludeTags

Description

Replaces include tags in given file with actual data (file must be added to build object first with processFile).

Signature

replaceIncludeTags(file: String) => String

Parameters

Parameter(s) Type Description
file String File to replace include tags

Example

var markdownInclude = require
                      

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap