Comparing version 0.5.2 to 0.5.3
@@ -27,3 +27,3 @@ 'use strict'; | ||
function getHashedHeaders (_lines) { | ||
function getHashedHeaders (lines) { | ||
var inCodeBlock = false; | ||
@@ -37,3 +37,3 @@ | ||
// Find headers of the form '### xxxx xxx xx [###]' | ||
return _lines | ||
return lines | ||
.filter(function (x) { | ||
@@ -56,6 +56,5 @@ if (x.match(/^```/)) { | ||
.filter(notNull) | ||
.value(); | ||
} | ||
function getUnderlinedHeaders (_lines) { | ||
function getUnderlinedHeaders (lines) { | ||
// Find headers of the form | ||
@@ -65,4 +64,4 @@ // h1 h2 | ||
return _lines | ||
.map(function (line, index, lines) { | ||
return lines | ||
.map(function (line, index, lines_) { | ||
if (index === 0) return null; | ||
@@ -77,3 +76,3 @@ var rank; | ||
rank : rank, | ||
name : lines[index - 1], | ||
name : lines_[index - 1], | ||
line : index - 1 | ||
@@ -83,3 +82,2 @@ }; | ||
.filter(notNull) | ||
.value(); | ||
} | ||
@@ -106,10 +104,25 @@ | ||
function getLinesToToc (lines, currentToc, info) { | ||
if (!currentToc) return lines; | ||
var tocableStart = 0; | ||
// when updating an existing toc, we only take the headers into account | ||
// that are below the existing toc | ||
if (info.hasEnd) tocableStart = info.endIdx; | ||
return lines.slice(tocableStart); | ||
} | ||
exports = module.exports = function transform(content, mode) { | ||
var lines = content.split('\n') | ||
, _lines = _(lines).chain(); | ||
mode = mode || 'github.com'; | ||
var headers = getHashedHeaders(_lines).concat(getUnderlinedHeaders(_lines)); | ||
var lines = content.split('\n') | ||
, info = updateSection.parse(lines, matchesStart, matchesEnd) | ||
var currentToc = info.hasStart && lines.slice(info.startIdx, info.endIdx).join('\n') | ||
, linesToToc = getLinesToToc(lines, currentToc, info); | ||
var headers = getHashedHeaders(linesToToc).concat(getUnderlinedHeaders(linesToToc)); | ||
headers.sort(function (a, b) { | ||
@@ -125,2 +138,3 @@ return a.line - b.line; | ||
var toc = | ||
@@ -140,5 +154,3 @@ '**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*' | ||
var wrappedToc = start + '\n' + toc + '\n' + end; | ||
var info = updateSection.parse(lines, matchesStart, matchesEnd); | ||
var currentToc = info.hasStart && lines.slice(info.startIdx, info.endIdx).join('\n'); | ||
if (currentToc === toc) return { transformed: false }; | ||
@@ -145,0 +157,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Generates TOC for markdown files of local git repo.", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"repository": { | ||
@@ -12,3 +12,3 @@ "type": "git", | ||
"scripts": { | ||
"test": "set -e; for t in test/**/*.js; do node $t; done" | ||
"test": "set -e; for t in test/*.js; do node $t; done" | ||
}, | ||
@@ -15,0 +15,0 @@ "main": "doctoc.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
18644
444
1