doctoc
Advanced tools
Comparing version 1.4.0 to 2.0.0
@@ -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 |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
162
3
0
20661
7
357
+ Added@textlint/markdown-to-ast@6.1.7(transitive)
+ Addeddebug@4.3.4(transitive)
+ Addeddom-serializer@1.4.1(transitive)
+ Addeddomhandler@3.3.04.3.1(transitive)
+ Addeddomutils@2.8.0(transitive)
+ Addedhtmlparser2@4.1.0(transitive)
+ Addedms@2.1.2(transitive)
+ Addedunderscore@1.10.2(transitive)
- Removed@textlint/markdown-to-ast@6.0.9(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddom-serializer@0.2.2(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.7.0(transitive)
- Removedentities@1.1.2(transitive)
- Removedhtmlparser2@3.9.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedms@2.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedunderscore@1.8.3(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedhtmlparser2@~4.1.0
Updatedminimist@~1.2.5
Updatedunderscore@~1.10.2
Updatedupdate-section@~0.3.3