1.2.0 • Published 5 years ago
gatsby-remark-toc v1.2.0
🚀 Install
npm install gatsby-remark-toc --save
🎓 How to use
// in your gatsby-config.js
plugins: [
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
{
resolve: 'gatsby-remark-toc',
options: {
header: 'Table of Contents', // the custom header text
include: [
'content/**/*.md' // an include glob to match against
]
}
}
]
}
}
];
If you want your table of contents to appear at a specific place in your Markdown file, use the reuseExistingHeader
option:
// in your gatsby-config.js
plugins: [
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
{
resolve: 'gatsby-remark-toc',
options: {
header: 'Table of Contents', // the custom header text
reuseExistingHeader: true, // searches for `Table of Contents` in your Markdown file and adds the list right after it
include: [
'content/**/*.md' // an include glob to match against
]
}
}
]
}
}
];
Use the orderedList
option if you want to change the list type from <ul>
to <ol>
.
Additionally, you can pass custom options directly to mdast-util-toc like so:
// in your gatsby-config.js
plugins: [
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
{
resolve: 'gatsby-remark-toc',
options: {
header: 'Table of Contents', // the custom header text
include: [
'content/**/*.md' // an include glob to match against
],
mdastUtilTocOptions: {
maxDepth: 2
}
}
}
]
}
}
];