Comparing version 0.6.0 to 0.7.0
@@ -21,10 +21,14 @@ 'use strict'; | ||
function rankify(headers) { | ||
return headers.map(function (x) { | ||
x.rank = parseInt(x.tag.slice(1), 10); | ||
return x; | ||
}) | ||
function rankify(headers, max) { | ||
return headers | ||
.map(function (x) { | ||
x.rank = parseInt(x.tag.slice(1), 10); | ||
return x; | ||
}) | ||
.filter(function (x) { | ||
return x.rank <= max; | ||
}) | ||
} | ||
var go = module.exports = function (lines) { | ||
var go = module.exports = function (lines, maxHeaderNo) { | ||
var md = lines.join('\n'); | ||
@@ -58,4 +62,5 @@ var headers = [], grabbing = null, text = []; | ||
headers = addLinenos(lines, headers) | ||
headers = rankify(headers); | ||
// consider anything past h4 to small to warrant a link, may be made configurable in the future | ||
headers = rankify(headers, maxHeaderNo); | ||
return headers; | ||
} |
@@ -115,4 +115,5 @@ 'use strict'; | ||
exports = module.exports = function transform(content, mode) { | ||
exports = module.exports = function transform(content, mode, maxHeaderNo) { | ||
mode = mode || 'github.com'; | ||
maxHeaderNo = maxHeaderNo || 4; | ||
@@ -127,3 +128,3 @@ var lines = content.split('\n') | ||
.concat(getUnderlinedHeaders(linesToToc)) | ||
.concat(getHtmlHeaders(linesToToc)) | ||
.concat(getHtmlHeaders(linesToToc, maxHeaderNo)) | ||
@@ -146,3 +147,3 @@ headers.sort(function (a, b) { | ||
var indent = _(_.range(x.rank - lowestRank)) | ||
.reduce(function (acc, x) { return acc + '\t'; }, ''); | ||
.reduce(function (acc, x) { return acc + ' '; }, ''); | ||
@@ -149,0 +150,0 @@ return indent + '- ' + x.anchor; |
@@ -5,3 +5,3 @@ { | ||
"description": "Generates TOC for markdown files of local git repo.", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -7,5 +7,5 @@ 'use strict'; | ||
test('\ngiven a file that includes html with header tags', function (t) { | ||
test('\ngiven a file that includes html with header tags and maxHeaderNo 8', function (t) { | ||
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-html.md', 'utf8'); | ||
var headers = transform(content); | ||
var headers = transform(content, 'github.com', 8); | ||
@@ -18,9 +18,9 @@ t.deepEqual( | ||
'- [API](#api)', | ||
'\t\t- [dockops::Containers(docker) → {Object}](#dockopscontainersdocker-→-{object})', | ||
'\t\t\t- [Parameters:](#parameters)', | ||
'\t\t\t- [Returns:](#returns)', | ||
'\t\t- [dockops::Containers::activePorts(cb)](#dockopscontainersactiveportscb)', | ||
'\t\t\t- [Parameters:](#parameters-1)', | ||
'\t\t- [dockops::Containers::clean(id, cb)](#dockopscontainerscleanid-cb)', | ||
'\t\t\t- [Parameters:](#parameters-2)', | ||
' - [dockops::Containers(docker) → {Object}](#dockopscontainersdocker-→-{object})', | ||
' - [Parameters:](#parameters)', | ||
' - [Returns:](#returns)', | ||
' - [dockops::Containers::activePorts(cb)](#dockopscontainersactiveportscb)', | ||
' - [Parameters:](#parameters-1)', | ||
' - [dockops::Containers::clean(id, cb)](#dockopscontainerscleanid-cb)', | ||
' - [Parameters:](#parameters-2)', | ||
'- [License](#license)', | ||
@@ -33,1 +33,22 @@ '' ] | ||
}) | ||
test('\ngiven a file that includes html with header tags using default maxHeaderNo', function (t) { | ||
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-html.md', 'utf8'); | ||
var headers = transform(content); | ||
t.deepEqual( | ||
headers.toc.split('\n') | ||
, [ '**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*', | ||
'', | ||
'- [Installation](#installation)', | ||
'- [API](#api)', | ||
' - [dockops::Containers(docker) → {Object}](#dockopscontainersdocker-→-{object})', | ||
' - [dockops::Containers::activePorts(cb)](#dockopscontainersactiveportscb)', | ||
' - [dockops::Containers::clean(id, cb)](#dockopscontainerscleanid-cb)', | ||
'- [License](#license)', | ||
'' ] | ||
, 'generates correct toc for non html and html headers omitting headers larger than maxHeaderNo' | ||
) | ||
t.end() | ||
}) |
@@ -49,6 +49,6 @@ 'use strict'; | ||
, '- [My Module](#my-module)\n' | ||
, '\t- [API](#api)\n' | ||
, '\t\t- [Method One](#method-one)\n' | ||
, '\t\t- [Method Two](#method-two)\n' | ||
, '\t\t\t- [Main Usage](#main-usage)\n\n\n' | ||
, ' - [API](#api)\n' | ||
, ' - [Method One](#method-one)\n' | ||
, ' - [Method Two](#method-two)\n' | ||
, ' - [Main Usage](#main-usage)\n\n\n' | ||
].join('') | ||
@@ -69,6 +69,6 @@ ) | ||
, '- [My Module using \\r\\n line endings](#my-module-using-\\r\\n-line-endings)\n' | ||
, '\t- [API](#api)\n' | ||
, '\t\t- [Method One](#method-one)\n' | ||
, '\t\t- [Method Two](#method-two)\n' | ||
, '\t\t\t- [Main Usage](#main-usage)\n\n\n' | ||
, ' - [API](#api)\n' | ||
, ' - [Method One](#method-one)\n' | ||
, ' - [Method Two](#method-two)\n' | ||
, ' - [Main Usage](#main-usage)\n\n\n' | ||
].join('') | ||
@@ -86,3 +86,3 @@ ) | ||
, '- [My Module](#my-module)\n' | ||
, '\t- [API](#api)\n\n\n' | ||
, ' - [API](#api)\n\n\n' | ||
].join('') | ||
@@ -98,3 +98,3 @@ ) | ||
, '- [My Module](#my-module)\n' | ||
, '\t- [API](#api)\n\n\n' | ||
, ' - [API](#api)\n\n\n' | ||
].join('') | ||
@@ -244,8 +244,8 @@ ) | ||
, '- [My Module](#markdown-header-my-module)\n' | ||
, '\t- [API](#markdown-header-api)\n' | ||
, '\t\t- [Method One](#markdown-header-method-one)\n' | ||
, '\t\t- [Method Two](#markdown-header-method-two)\n' | ||
, '\t\t\t- [Main Usage](#markdown-header-main-usage)\n\n\n' | ||
, ' - [API](#markdown-header-api)\n' | ||
, ' - [Method One](#markdown-header-method-one)\n' | ||
, ' - [Method Two](#markdown-header-method-two)\n' | ||
, ' - [Main Usage](#markdown-header-main-usage)\n\n\n' | ||
].join('') | ||
, 'bitbucket.org' | ||
) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28179
552
5