Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
markdown-toc-gen
Advanced tools
Generating and updating table of contents in Markdown files which conform with prettier.
Install with npm:
npm install markdown-toc-gen
markdown-toc-gen
is a lightweight tool to create and update table of contents in Markdown files. The navigation of
the created toc works with GitHub Flavored Markdown Spec and
pandoc. The focus was on conformity with prettier.
So only hyphens are allowed as bullet list.
This tool can also handle duplicate headings in a Markdown file without breaking the navigation. Code blocks will be ignored so there are no issues with code comments or Markdown in code blocks.
To use this tool you have to add the following lines in your markdown files which are separated with one or more newlines:
<-- toc -->
<-- tocstop -->
The default configuration only allows to create the toc from headings with a level from 2 (##
) to 6 (######
). The level 1
should only used for the markdown title which shouldn't be a part of the toc. If level 1 headings are used in your markdown
markdown-toc-gen
will ignore it for creating the toc. It's possible to define the maxDepth for parsing headings in the
range [2,6].
Usage: markdown-toc-gen <command> [options]
Commands:
markdown-toc-gen insert [files..] insert/update the toc in given markdown file [aliases: update]
markdown-toc-gen dry-run [files..] returns only created markdown toc without changing given file
markdown-toc-gen check [files..] check if toc exists or if toc is outdated
Options:
-d, --max-depth max depth for header parsing (default: 6) [number]
--version Show version number [boolean]
--help Show help [boolean]
Examples:
markdown-toc-gen insert README.md insert table of content for README.md
markdown-toc-gen insert ./**/README.md insert table of content for given README.md files
markdown-toc-gen update README.md update given table of content for README.md
markdown-toc-gen dry-run README.md test toc creation for given README.md
markdown-toc-gen dry-run ./**/README.md test toc creation for given README.md files
markdown-toc-gen check README.md check if toc exists or it toc is outdated
markdown-toc-gen check ./**/README.md validates toc for given README.md files
copyright 2021 by TheSilk
Released under MIT License
It's possible to treat multiple files at once. You have to use the ./**/README.md
syntax. Please notice that the
node_modules
directory will be ignored. In future versions it will also be possible to exclude given directories.
After adding the placeholders in your markdown file you can add the generated toc with
markdown-toc-gen insert README.md
markdown-toc-gen insert ./**/README.md
markdown-toc-gen insert ./**/*.md
Updating an existing toc is also no issue. With the following command the existing toc will be updated.
markdown-toc-gen update README.md
markdown-toc-gen update ./**/README.md
markdown-toc-gen update ./**/*.md
It is also possible to test the toc creation with a dry-run
mode. In this mode the headings will be parsed and printed
to STDOUT. There are no modifications on the given file.
markdown-toc-gen dry-run README.md
markdown-toc-gen dry-run ./**/README.md
markdown-toc-gen dry-run src/**/*.md
It is possible to check if a given Markdown file has a table of content or if the toc is outdated. Use cases could be a CI integration to avoid pushing Markdown files with outdated tocs.
markdown-toc-gen check README.md
markdown-toc-gen check ./**/README.md
markdown-toc-gen check ./**/*.md
If you develop on a library with many components inside and each have an own README.md I can recommend to use
markdown-toc
in combination with husky and lint-staged.
With these tools you can create a pre-commit hook which updates or inserts a toc to each staged markdown file.
This can prevent to push an outdated table of content. An example package.json
configuration could be:
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"**/README.md": "markdown-toc-gen insert"
}
}
}
Please be aware of manipulation your markdown file with this tool should work in the most cases. There are many tests which are cover many edge cases. But sometimes it is not possible to handle all of them. So I recommend to use this tool only with files in VCS environment or in local copies. The use of this tool is at your sole risk, so I can not accept any liability for any misconduct and damaged files.
Copyright 2021-2024 by TheSilk. Released under MIT License
FAQs
Generating and updating table of contents in Markdown files which conform with prettier.
The npm package markdown-toc-gen receives a total of 3,548 weekly downloads. As such, markdown-toc-gen popularity was classified as popular.
We found that markdown-toc-gen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.