jonschlinkert / markdown-toc

API and CLI for generating a markdown TOC (table of contents) for a README or any markdown files. Uses Remarkable to parse markdown. Used by NASA/openmct, Prisma, Joi, Mocha, Sass, Prettier, Orbit DB, FormatJS, Raneto, hapijs/code, webpack-flow, docusaurus, release-it, ts-loader, json-server, reactfire, bunyan, husky, react-easy-state, react-snap, chakra-ui, carbon, alfresco, repolinter, Assemble, Verb, and thousands of other projects.
https://github.com/jonschlinkert
MIT License
1.66k stars 710 forks source link

Examples with Slugify option #150

Open salmonjean opened 5 years ago

salmonjean commented 5 years ago

Hi

I need a specific slugify function to avoid accentuated and some specials characters. For the moment, I've directly have updated the utils.js source code. It works but it's "not clean". For instance : str = str.split(/[àèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇßØøÅåÆæœ]/).join('-');

I would rather use your option options.slugify Do you have at least one example to show me how to use this option please? Thanks for your help.

Regards,

Jean

jonschlinkert commented 5 years ago

Sure, just pass a function to the slugify option:

const toc = require('markdown-toc');

const slugify = str => {
  // your custom logic here
};

console.log(toc(input, { slugify }));

Is this what you mean?

Also, I published markdown-slug a while ago, for this kind of situation. If you still need to add custom logic with that lib, and you want to do a PR that would be awesome.