Socket
Socket
Sign inDemoInstall

doctoc

Package Overview
Dependencies
123
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 2.0.0

22

doctoc.js

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

function transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut) {
function transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, processAll, stdOut, updateOnly) {
if (processAll) {
console.log('--all flag is enabled. Including headers before the TOC location.')
}
if (updateOnly) {
console.log('--update-only flag is enabled. Only updating files that already have a TOC.')
}
console.log('\n==================\n');

@@ -26,3 +34,3 @@

var content = fs.readFileSync(x.path, 'utf8')
, result = transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix);
, result = transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix, processAll, updateOnly);
result.path = x.path;

@@ -59,3 +67,3 @@ return result;

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

@@ -81,3 +89,3 @@ for (var key in modes) {

var argv = minimist(process.argv.slice(2)
, { boolean: [ 'h', 'help', 'T', 'notitle', 's', 'stdout'].concat(Object.keys(modes))
, { boolean: [ 'h', 'help', 'T', 'notitle', 's', 'stdout', 'all' , 'u', 'update-only'].concat(Object.keys(modes))
, string: [ 'title', 't', 'maxlevel', 'm', 'entryprefix' ]

@@ -100,3 +108,5 @@ , unknown: function(a) { return (a[0] == '-' ? (console.error('Unknown option(s): ' + a), printUsageAndExit(true)) : true); }

var entryPrefix = argv.entryprefix || '-';
var processAll = argv.all;
var stdOut = argv.s || argv.stdout
var updateOnly = argv.u || argv['update-only']

@@ -118,5 +128,7 @@ var maxHeaderLevel = argv.m || argv.maxlevel;

transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut);
transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, processAll, stdOut, updateOnly);
console.log('\nEverything is OK.');
}
module.exports.transform = transform;

@@ -88,4 +88,4 @@ 'use strict';

function getLinesToToc (lines, currentToc, info) {
if (!currentToc) return lines;
function getLinesToToc (lines, currentToc, info, processAll) {
if (processAll || !currentToc) return lines;

@@ -110,3 +110,3 @@ var tocableStart = 0;

exports = module.exports = function transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix) {
exports = module.exports = function transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix, processAll, updateOnly) {
mode = mode || 'github.com';

@@ -121,6 +121,12 @@ entryPrefix = entryPrefix || '-';

if (!info.hasStart && updateOnly) {
return { transformed: false };
}
var inferredTitle = determineTitle(title, notitle, lines, info);
var titleSeparator = inferredTitle ? '\n\n' : '\n';
var currentToc = info.hasStart && lines.slice(info.startIdx, info.endIdx + 1).join('\n')
, linesToToc = getLinesToToc(lines, currentToc, info);
, linesToToc = getLinesToToc(lines, currentToc, info, processAll);

@@ -145,3 +151,3 @@ var headers = getMarkdownHeaders(linesToToc, maxHeaderLevel)

inferredTitle
+ '\n\n'
+ titleSeparator
+ linkedHeaders

@@ -148,0 +154,0 @@ .map(function (x) {

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

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

@@ -14,17 +14,17 @@ "type": "git",

},
"files": [
"lib"
],
"main": "doctoc.js",
"bin": "doctoc.js",
"engines": {
"node": ">=0.4"
},
"dependencies": {
"@textlint/markdown-to-ast": "~6.0.9",
"anchor-markdown-header": "^0.5.5",
"htmlparser2": "~3.9.2",
"minimist": "~1.2.0",
"underscore": "~1.8.3",
"update-section": "^0.3.0"
"@textlint/markdown-to-ast": "~6.1.7",
"anchor-markdown-header": "~0.5.7",
"htmlparser2": "~4.1.0",
"minimist": "~1.2.5",
"underscore": "~1.10.2",
"update-section": "~0.3.3"
},
"devDependencies": {
"tap": "~10.2.1"
"tap": "^14.10.7"
},

@@ -31,0 +31,0 @@ "license": "MIT",

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

Alternatively, to blank out the title with a newline, use the `--notitle` option. This will simply remove the title from the TOC.
Alternatively, to blank out the title, use the `--notitle` option. This will simply remove the title from the TOC.

@@ -144,2 +144,6 @@ ### Specifying a maximum heading level for TOC entries

### Only update existing ToC
Use `--update-only` or `-u` to only update the existing ToC. That is, the Markdown files without ToC will be left untouched. It is good if you want to use `doctoc` with `lint-staged`.
### Usage as a `git` hook

@@ -153,3 +157,3 @@

- repo: https://github.com/thlorenz/doctoc
sha: ... # substitute a tagged version
rev: ... # substitute a tagged version
hooks:

@@ -156,0 +160,0 @@ - id: doctoc

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