diff --git a/.verb.md b/.verb.md index 1720e3a..cf0d5a3 100644 --- a/.verb.md +++ b/.verb.md @@ -1,15 +1,29 @@ ## CLI ``` -Usage: markdown-toc [--json] [-i] +Usage: markdown-toc [options] - input: The markdown file to parse for table of contents, - or "-" to read from stdin. + input: The Markdown file to parse for table of contents, + or "-" to read from stdin. - --json: Print the TOC in json format + -i: Edit the file directly, injecting the TOC at + (Without this flag, the default is to print the TOC to stdout.) - -i: Edit the file directly, injecting the TOC at - (Without this flag, the default is to print the TOC to stdout.) + --json: Print the TOC in JSON format + + --append: Append a string to the end of the TOC + + --bullets: Bullets to use for items in the generated TOC + (Supports multiple bullets: --bullets "*" --bullets "-" --bullets "+") + (Default is "*".) + + --maxdepth: Use headings whose depth is at most maxdepth + (Default is 6.) + + --no-firsth1: Include the first h1-level heading in a file + + --no-stripHeadingTags: Do not strip extraneous HTML tags from heading + text before slugifying ``` ## Highights diff --git a/cli.js b/cli.js index 59df22a..b601704 100755 --- a/cli.js +++ b/cli.js @@ -4,20 +4,39 @@ var fs = require('fs'); var toc = require('./index.js'); var utils = require('./lib/utils'); var args = utils.minimist(process.argv.slice(2), { - boolean: ['i', 'json'] + boolean: ['i', 'json', 'firsth1', 'stripHeadingTags'], + string: ['append', 'bullets'], + default: { + firsth1: true, + stripHeadingTags: true + } }); if (args._.length !== 1) { console.error([ - 'Usage: markdown-toc [--json] [-i] ', + 'Usage: markdown-toc [options] ', + '', + ' input: The Markdown file to parse for table of contents,', + ' or "-" to read from stdin.', + '', + ' -i: Edit the file directly, injecting the TOC at ', + ' (Without this flag, the default is to print the TOC to stdout.)', + '', + ' --json: Print the TOC in JSON format', + '', + ' --append: Append a string to the end of the TOC', + '', + ' --bullets: Bullets to use for items in the generated TOC', + ' (Supports multiple bullets: --bullets "*" --bullets "-" --bullets "+")', + ' (Default is "*".)', '', - ' input: The markdown file to parse for table of contents,', - ' or "-" to read from stdin.', + ' --maxdepth: Use headings whose depth is at most maxdepth', + ' (Default is 6.)', '', - ' --json: Print the TOC in json format', + ' --no-firsth1: Include the first h1-level heading in a file', '', - ' -i: Edit the file directly, injecting the TOC at ', - ' (Without this flag, the default is to print the TOC to stdout.)' + ' --no-stripHeadingTags: Do not strip extraneous HTML tags from heading', + ' text before slugifying' ].join('\n')); process.exit(1); } @@ -37,10 +56,10 @@ if (args._[0] !== '-') input = fs.createReadStream(args._[0]); input.pipe(utils.concat(function(input) { if (args.i) { - var newMarkdown = toc.insert(input.toString()); + var newMarkdown = toc.insert(input.toString(), args); fs.writeFileSync(args._[0], newMarkdown); } else { - var parsed = toc(input.toString()); + var parsed = toc(input.toString(), args); output(parsed); } }));