0.4.5 • Published 5 years ago
front-matter-markdown v0.4.5
front-matter-markdown 
Get the config object from a markdown string. It will extract configuration from front-matter.
And get the directory(contents) from the list of heading TOC/Table Of Content/Summary.
It will generate a TOC from the markdown string if the list is empty
Usage
parseMarkdown = require('front-matter-markdown')
markdownStr = """
---
title: this is a title
---
# table of contents
* [Directory](./dir1)
* [Directory2](/dir2)
* [Directory3](#inline)
# this is a inline heading {#inline}
"""
console.log(JSON.stringify parseMarkdown(markdownStr), null, 1)the results:
{
"title": "this is a title",
"skipSize": 31,
"ordered": false,
"contents": [
{
"title": "Directory",
"path": "./dir1",
"ordered": false,
"contents": [
{
"title": "Directory2",
"path": "/dir2"
}
]
},
{
"title": "Directory3",
"path": "#inline"
}
]
}API
var parseMarkdown = require('front-matter-markdown');parseMarkdown(aMarkdownString, aOptions): parse a markdown string to a plain object.aOptions(Object):content(Boolean): whether extract the markdown content from configuration. defaults to true. it will store the compiled markdown to$compiledtoo.- Note: the
contentand$compiledattributes are non-enumerable.
- Note: the
toc(Boolean): whether extract the directory from the list in the specified heading. defaults to false. the 'directoy' is put intocontentsattributes.links(Boolean): merge the markdown links label to the result, default to false.heading(String|RegExp|ArrayOf(String)): the toc list in the heading(s) to extract the directory. defaults to 'TOC', 'Table Of Content', 'Summary'headingsAsToc(Boolean|Object): whethergeneratethe directory from the headings of markdown. defaults to false. It willgeneratethe toc if no toc list in the specified heading(tocenabled).maxDepth(Number): Use headings whose depth is at most max depth forgenerate. defaluts to 3.firstLevel(Number): the first level togeneratethe directory from the headings of markdown. defaluts to 1.
Returns:skipSizeNumber: the front-matter configuration size if existscontentString: the markdown string after removing the front-matter configuration. (available oncontentis true)$compiledObject: the compiled markdown tree.(available oncontentis true)contentsObject: the directory from the list in the specified heading. (available ontoc)
Changes
v0.3
- markdown inline options to control parser.
- toc
- heading: the toc list in the heading section.
- headingsAsToc
- setOptionAlias function
- broken: toc, headingsAsToc options are defaults to false now.
- add the links option: merge the markdown links label to the result, default to false.
markdownStr = """
---
title: this is a title
toc: false
headingsAsToc: false
heading: Category
---
# Category
* [Directory](./dir1)
* [Directory2](/dir2)
* [Directory3](#inline)
# this is a inline heading {#inline}
[linkLabel1]: hi
[linkLabel2]: url "with title text"
"""
result = parseMarkdown(markdownStr) #= parseMarkdown markdownStr,
# toc:false
# headingsAsToc: false
# heading: 'Category'License
MIT
0.4.5
5 years ago
0.4.4
6 years ago
0.4.3
8 years ago
0.4.2
10 years ago
0.4.1
10 years ago
0.4.0
10 years ago
0.3.6
10 years ago
0.3.5
10 years ago
0.3.4
10 years ago
0.3.3
10 years ago
0.3.2
10 years ago
0.3.1
10 years ago
0.3.0
10 years ago
0.2.1
10 years ago
0.2.0
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago
0.0.1
10 years ago
0.0.0
10 years ago