mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 02:08:55 +02:00
fix: handle case insensitive table of contents token (#1288)
* fix: check for lowercase TOC token * run prettier * fix: handle case insensitive * nits
This commit is contained in:
parent
d89401b47e
commit
79bbe8e59e
1 changed files with 3 additions and 3 deletions
|
@ -9,7 +9,7 @@ const Remarkable = require('remarkable');
|
||||||
const mdToc = require('markdown-toc');
|
const mdToc = require('markdown-toc');
|
||||||
const toSlug = require('./toSlug');
|
const toSlug = require('./toSlug');
|
||||||
|
|
||||||
const TABLE_OF_CONTENTS_TOKEN = '<AUTOGENERATED_TABLE_OF_CONTENTS>';
|
const tocRegex = new RegExp('<AUTOGENERATED_TABLE_OF_CONTENTS>', 'i');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a table of content from the headings
|
* Returns a table of content from the headings
|
||||||
|
@ -58,7 +58,7 @@ function getTOC(content, headingTags = 'h2', subHeadingTags = 'h3') {
|
||||||
// takes the content of a doc article and returns the content with a table of
|
// takes the content of a doc article and returns the content with a table of
|
||||||
// contents inserted
|
// contents inserted
|
||||||
function insertTOC(rawContent) {
|
function insertTOC(rawContent) {
|
||||||
if (!rawContent || rawContent.indexOf(TABLE_OF_CONTENTS_TOKEN) === -1) {
|
if (!rawContent || !tocRegex.test(rawContent)) {
|
||||||
return rawContent;
|
return rawContent;
|
||||||
}
|
}
|
||||||
const filterRe = /^`[^`]*`/;
|
const filterRe = /^`[^`]*`/;
|
||||||
|
@ -67,7 +67,7 @@ function insertTOC(rawContent) {
|
||||||
.filter(header => filterRe.test(header.rawContent))
|
.filter(header => filterRe.test(header.rawContent))
|
||||||
.map(header => ` - [${header.rawContent}](#${header.hashLink})`)
|
.map(header => ` - [${header.rawContent}](#${header.hashLink})`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
return rawContent.replace(TABLE_OF_CONTENTS_TOKEN, tableOfContents);
|
return rawContent.replace(tocRegex, tableOfContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue