Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

doctoc

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doctoc - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

test/transform.js

40

lib/transform.js

@@ -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",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc