New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-toc

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-toc

Create a table of contents from the given markdown text.

latest
Source
npmnpm
Version
3.1.0
Version published
Weekly downloads
241
-43.95%
Maintainers
1
Weekly downloads
 
Created
Source

react-toc

NPM npm bundle size npm MIT

Overview

  • The idea is that you can automatically create a customizable table of contents from your markdown text.
  • It's regex based. Thus, managed to keep the bundle size pretty tiny.(Check it out on BUNDLEPHOBIA)

Image from Gyazo

Demo

Check out the demo page.

Installation

npm install --save react-toc

or

yarn add react-toc

Usage

Import Toc from the package and pass props to it. As for now, markdownText is the only required prop.

import React from "react";
import Toc from "react-toc";

const Example = () => {
  const yourMarkdownText = "# test \n your markdown Content # test2\n";
  return <Toc markdownText={yourMarkdownText} />;
};

export default Example;

Props

NameTypeDescription
markdownTextstringRequired The markdown text you want to creat a TOC from.
titleLimitnumberThe maximum length of each title in the TOC.
highestHeadingLevelnumberThe highest level of headings you want to extract from the given markdownText.
lowestHeadingLevelnumberThe lowest level of headings you want to extract from the given markdownText.
classNamestrigYour custom className.
type"deafult" or"raw"The type of a TOC you want to use.
customMatchers{ [key: string]: string }The matchers you want to use to replace the letters with.

CustomDesign

Add a custom className

Pass className like the code below.

import React from "react";
import Toc from "react-toc";

const Example = () => {
  const yourMarkdownText = "# test \n your markdown Content # test2\n";
  return <Toc markdownText={yourMarkdownText} className={"customClassName"} />;
};

export default Example;

Style the custom class

Now you can style your custom class just like the code below.

.customClassName {
  border: solid 1px;
}
.customClassName > li {
  padding-bottom: 10px;
}

Custom Matchers

You can use the customMatchers prop to replace letters in your toc. For instance, if you want to replace ? or ! with - in your list, you can simply do this.

import React from "react";
import Toc from "react-toc";

const Example = () => {
  const yourMarkdownText = "# test \n your markdown Content # test2\n";
  const matchers = { "[?!]": "-" }

  return <Toc markdownText={yourMarkdownText} className={"customClassName"} customMatchers={matchers}/>;
};

export default Example;

You can also give more options to the customMatchers prop like the code below.

import React from "react";
import Toc from "react-toc";

const Example = () => {
  const yourMarkdownText = "# test \n your markdown Content # test2\n";
  const matchers = { "[?!]": "-", "\\*": "" }

  return <Toc markdownText={yourMarkdownText} className={"customClassName"} customMatchers={matchers}/>;
};

export default Example;

Development

  • Install dev dependencies.
$ yarn install
  • Test
$ yarn test
  • Lint
$ yarn lint
  • Run demo locally
$ cd demo && yarn && yarn start

License

MIT

FAQs

Package last updated on 13 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts