在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jonschlinkert/markdown-toc开源软件地址(OpenSource Url):https://github.com/jonschlinkert/markdown-toc开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):markdown-toc
Table of Contents(TOC generated by verb using markdown-toc) InstallInstall with npm: $ npm install --save markdown-toc CLI
HighlightsFeatures
Safe!
Usagevar toc = require('markdown-toc');
toc('# One\n\n# Two').content;
// Results in:
// - [One](#one)
// - [Two](#two) To allow customization of the output, an object is returned with the following properties:
APItoc.pluginUse as a remarkable plugin. var Remarkable = require('remarkable');
var toc = require('markdown-toc');
function render(str, options) {
return new Remarkable()
.use(toc.plugin(options)) // <= register the plugin
.render(str);
} Usage example var results = render('# AAA\n# BBB\n# CCC\nfoo\nbar\nbaz'); Results in:
toc.jsonObject for creating a custom TOC. toc('# AAA\n## BBB\n### CCC\nfoo').json;
// results in
[ { content: 'AAA', slug: 'aaa', lvl: 1 },
{ content: 'BBB', slug: 'bbb', lvl: 2 },
{ content: 'CCC', slug: 'ccc', lvl: 3 } ] toc.insertInsert a table of contents immediately after an opening (This strategy works well since code comments in markdown are hidden when viewed as HTML, like when viewing a README on GitHub README for example). Example
Would result in something like:
Utility functionsAs a convenience to folks who wants to create a custom TOC, markdown-toc's internal utility methods are exposed: var toc = require('markdown-toc');
Example var result = toc('# AAA\n## BBB\n### CCC\nfoo');
var str = '';
result.json.forEach(function(heading) {
str += toc.linkify(heading.content);
}); Optionsoptions.appendAppend a string to the end of the TOC. toc(str, {append: '\n_(TOC generated by Verb)_'}); options.filterType: Default: Params:
Example From time to time, we might get junk like this in our TOC.
Unless you like that kind of thing, you might want to filter these bad headings out. function removeJunk(str, ele, arr) {
return str.indexOf('...') === -1;
}
var result = toc(str, {filter: removeJunk});
//=> beautiful TOC options.slugifyType: Default: Basic non-word character replacement. Example var str = toc('# Some Article', {slugify: require('uslug')}); options.bulletsType: Default: The bullet to use for each item in the generated TOC. If passed as an array ( options.maxdepthType: Default: Use headings whose depth is at most maxdepth. options.firsth1Type: Default: Exclude the first h1-level heading in a file. For example, this prevents the first heading in a README from showing up in the TOC. options.stripHeadingTagsType: Default: Strip extraneous HTML tags from heading text before slugifying. This is similar to GitHub markdown behavior. AboutRelated projects
ContributingPull requests and stars are always welcome. For bugs and feature requests, please create an issue. Contributors
Building docs(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.) To generate the readme, run the following command: $ npm install -g verbose/verb#dev verb-generate-readme && verb Running testsRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: $ npm install && npm test AuthorJon Schlinkert LicenseCopyright © 2017, Jon Schlinkert. Released under the MIT License. This file was generated by verb-generate-readme, v0.6.0, on September 19, 2017. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论