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

markdown-toc

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-toc - npm Package Compare versions

Comparing version 0.12.14 to 0.12.15

README.md

45

index.js

@@ -46,2 +46,3 @@ 'use strict';

var opts = utils.merge({firsth1: true, maxdepth: 6}, options);
var seen = opts.seen = {};
var stripFirst = opts.firsth1 === false;

@@ -54,3 +55,2 @@

var tocstart = -1;
var seen = {};
var arr = [];

@@ -80,3 +80,3 @@ var res = {};

var tok = arr[j++];
if (tok.lines[0] > tocstart) {
if (tok.lines && (tok.lines[0] > tocstart)) {
if (!seen.hasOwnProperty(tok.content)) {

@@ -89,3 +89,3 @@ seen[tok.content] = 0;

tok.seen = seen[tok.content];
tok.slug = slugify(tok.content, opts, tok);
tok.slug = utils.slugify(tok.content, opts);
res.json.push(utils.pick(tok, ['content', 'slug', 'lvl', 'i', 'seen']));

@@ -177,3 +177,7 @@ result.push(linkify(tok, opts));

var text = titleize(tok.content, opts);
var slug = slugify(tok.content, opts, tok);
var slug = utils.slugify(tok.content, opts);
if (tok.seen) {
slug += '-' + tok.seen;
}
if (opts && typeof opts.linkify === 'function') {

@@ -188,32 +192,2 @@ return opts.linkify(tok, text, slug, opts);

/**
* Slugify the url part of a markdown link.
*
* @name options.slugify
* @param {String} `str` The string to slugify
* @param {Object} `opts` Pass a custom slugify function on `slugify`
* @return {String}
* @api public
*/
function slugify(str, options, token) {
var opts = utils.merge({}, options);
if (opts && opts.slugify === false) return str;
if (opts && typeof opts.slugify === 'function') {
return opts.slugify(str, opts, token);
}
str = utils.getTitle(str);
str = utils.stripColor(str);
str = str.toLowerCase();
str = str.split(/ /).join('-');
str = str.split(/\t/).join('--');
str = str.split(/[|$&`~=\\\/@+*!?({[\]})<>=.,;:'"^]/).join('');
if (token && typeof token === 'object' && token.seen) {
if (token.seen > 0) {
str += '-' + token.seen;
}
}
return str;
}
/**
* Titleize the title part of a markdown link.

@@ -253,3 +227,2 @@ *

}
if (Array.isArray(opts.strip) && opts.strip.length) {

@@ -270,5 +243,5 @@ var res = opts.strip.join('|');

toc.linkify = linkify;
toc.slugify = slugify;
toc.slugify = utils.slugify;
toc.titleize = titleize;
toc.plugin = generate;
toc.strip = strip;

27

lib/utils.js

@@ -32,3 +32,3 @@ 'use strict';

utils.getTitle = function(str) {
if (/^\[/.test(str) && /\]\(/.test(str)) {
if (/^\[[^\]]+\]\(/.test(str)) {
var m = /^\[([^\]]+)\]/.exec(str);

@@ -41,2 +41,27 @@ if (m) return m[1];

/**
* Slugify the url part of a markdown link.
*
* @name options.slugify
* @param {String} `str` The string to slugify
* @param {Object} `options` Pass a custom slugify function on `options.slugify`
* @return {String}
* @api public
*/
utils.slugify = function(str, options) {
options = options || {};
if (options.slugify === false) return str;
if (typeof options.slugify === 'function') {
return options.slugify(str, options);
}
str = utils.getTitle(str);
str = utils.stripColor(str);
str = str.toLowerCase();
str = str.split(/ /).join('-');
str = str.split(/\t/).join('--');
str = str.split(/[|$&`~=\\\/@+*!?({[\]})<>=.,;:'"^]/).join('');
return str;
};
/**
* Expose `utils` modules

@@ -43,0 +68,0 @@ */

{
"name": "markdown-toc",
"description": "Generate a markdown TOC (table of contents) with Remarkable.",
"version": "0.12.14",
"version": "0.12.15",
"homepage": "https://github.com/jonschlinkert/markdown-toc",

@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

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