Socket
Socket
Sign inDemoInstall

doctoc

Package Overview
Dependencies
278
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

test/fixtures/stdout.md

33

doctoc.js

@@ -19,9 +19,9 @@ #!/usr/bin/env node

function transformAndSave(files, mode, maxHeaderLevel, title, notitle) {
function transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut) {
console.log('\n==================\n');
var transformed = files
.map(function (x) {
var content = fs.readFileSync(x.path, 'utf8')
, result = transform(content, mode, maxHeaderLevel, title, notitle);
, result = transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix);
result.path = x.path;

@@ -31,4 +31,11 @@ return result;

var changed = transformed.filter(function (x) { return x.transformed; })
, unchanged = transformed.filter(function (x) { return !x.transformed; });
, unchanged = transformed.filter(function (x) { return !x.transformed; })
, toc = transformed.filter(function (x) { return x.toc; })
if (stdOut) {
toc.forEach(function (x) {
console.log(x.toc)
})
}
unchanged.forEach(function (x) {

@@ -39,4 +46,8 @@ console.log('"%s" is up to date', x.path);

changed.forEach(function (x) {
console.log('"%s" will be updated', x.path);
fs.writeFileSync(x.path, x.data, 'utf8');
if (stdOut) {
console.log('==================\n\n"%s" should be updated', x.path)
} else {
console.log('"%s" will be updated', x.path);
fs.writeFileSync(x.path, x.data, 'utf8');
}
});

@@ -49,3 +60,3 @@ }

outputFunc('Usage: doctoc [mode] [--notitle | --title title] [--maxlevel level] <path> (where path is some path to a directory (e.g., .) or a file (e.g., README.md))');
outputFunc('Usage: doctoc [mode] [--entryprefix prefix] [--notitle | --title title] [--maxlevel level] <path> (where path is some path to a directory (e.g., .) or a file (e.g., README.md))');
outputFunc('\nAvailable modes are:');

@@ -71,4 +82,4 @@ for (var key in modes) {

var argv = minimist(process.argv.slice(2)
, { boolean: [ 'h', 'help', 'T', 'notitle' ].concat(Object.keys(modes))
, string: [ 'title', 't', 'maxlevel', 'm' ]
, { boolean: [ 'h', 'help', 'T', 'notitle', 's', 'stdout'].concat(Object.keys(modes))
, string: [ 'title', 't', 'maxlevel', 'm', 'entryprefix' ]
, unknown: function(a) { return (a[0] == '-' ? (console.error('Unknown option(s): ' + a), printUsageAndExit(true)) : true); }

@@ -89,2 +100,4 @@ });

var notitle = argv.T || argv.notitle;
var entryPrefix = argv.entryprefix || '-';
var stdOut = argv.s || argv.stdout

@@ -106,5 +119,5 @@ var maxHeaderLevel = argv.m || argv.maxlevel;

transformAndSave(files, mode, maxHeaderLevel, title, notitle);
transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut);
console.log('\nEverything is OK.');
}

@@ -109,4 +109,6 @@ 'use strict';

exports = module.exports = function transform(content, mode, maxHeaderLevel, title, notitle) {
exports = module.exports = function transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix) {
mode = mode || 'github.com';
entryPrefix = entryPrefix || '-';
// only limit *HTML* headings by default

@@ -147,3 +149,3 @@ var maxHeaderLevelHtml = maxHeaderLevel || 4;

return indent + '- ' + x.anchor;
return indent + entryPrefix + ' ' + x.anchor;
})

@@ -150,0 +152,0 @@ .join('\n')

@@ -5,3 +5,3 @@ {

"description": "Generates TOC for markdown files of local git repo.",
"version": "1.1.1",
"version": "1.2.0",
"repository": {

@@ -20,3 +20,3 @@ "type": "git",

"dependencies": {
"anchor-markdown-header": "^0.5.4",
"anchor-markdown-header": "^0.5.5",
"htmlparser2": "~3.7.1",

@@ -23,0 +23,0 @@ "markdown-to-ast": "~3.2.3",

@@ -23,2 +23,3 @@ # DocToc [![build status](https://secure.travis-ci.org/thlorenz/doctoc.svg)](http://travis-ci.org/thlorenz/doctoc)

- [Specifying a maximum heading level for TOC entries](#specifying-a-maximum-heading-level-for-toc-entries)
- [Printing to stdout](#printing-to-stdout)

@@ -136,2 +137,6 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

### Printing to stdout
You can print to stdout by using the `-s` or `--stdout` option.
[ack]: http://beyondgrep.com/

@@ -11,5 +11,5 @@ 'use strict';

function check(md, anchors, mode, maxHeaderLevel, title) {
function check(md, anchors, mode, maxHeaderLevel, title, notitle, entryPrefix) {
test('transforming', function (t) {
var res = transform(md, mode, maxHeaderLevel, title)
var res = transform(md, mode, maxHeaderLevel, title, notitle, entryPrefix)

@@ -331,1 +331,74 @@ // remove wrapper

)
// check the --entryprefix flag
check(
[ '# My Module'
, 'Some text here'
, '## API'
, '### Method One'
, 'works like this'
, '### Method Two'
, '#### Main Usage'
, 'some main usage here'
].join('\n')
, [ '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n'
, '* [My Module](#my-module)\n'
, ' * [API](#api)\n'
, ' * [Method One](#method-one)\n'
, ' * [Method Two](#method-two)\n'
, ' * [Main Usage](#main-usage)\n\n\n'
].join('')
, undefined
, undefined
, undefined
, undefined
, '*' // pass '*' as the prefix for toc entries
)
check(
[ '# My Module'
, 'Some text here'
, '## API'
, '### Method One'
, 'works like this'
, '### Method Two'
, '#### Main Usage'
, 'some main usage here'
].join('\n')
, [ '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n'
, '>> [My Module](#my-module)\n'
, ' >> [API](#api)\n'
, ' >> [Method One](#method-one)\n'
, ' >> [Method Two](#method-two)\n'
, ' >> [Main Usage](#main-usage)\n\n\n'
].join('')
, undefined
, undefined
, undefined
, undefined
, '>>' // pass '>>' as the prefix for toc entries)
)
check(
[ '# My Module'
, 'Some text here'
, '## API'
, '### Method One'
, 'works like this'
, '### Method Two'
, '#### Main Usage'
, 'some main usage here'
].join('\n')
, [ '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n'
, '1. [My Module](#my-module)\n'
, ' 1. [API](#api)\n'
, ' 1. [Method One](#method-one)\n'
, ' 1. [Method Two](#method-two)\n'
, ' 1. [Main Usage](#main-usage)\n\n\n'
].join('')
, undefined
, undefined
, undefined
, undefined
, '1.' // pass '1.' as the prefix for toc entries
)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc