Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle TOC token as case insensitive #1288

Merged
merged 4 commits into from
Mar 20, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions v1/lib/core/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ function getTOC(content, headingTags = 'h2', subHeadingTags = 'h3') {
// takes the content of a doc article and returns the content with a table of
// contents inserted
function insertTOC(rawContent) {
if (!rawContent || rawContent.indexOf(TABLE_OF_CONTENTS_TOKEN) === -1) {
if (!rawContent) {
return rawContent;
}
const LOWERCASE_TOC_TOKEN = TABLE_OF_CONTENTS_TOKEN.toLowerCase();
if (
rawContent.indexOf(TABLE_OF_CONTENTS_TOKEN) === -1 &&
rawContent.indexOf(LOWERCASE_TOC_TOKEN) === -1
) {
return rawContent;
}
const filterRe = /^`[^`]*`/;
Expand All @@ -67,7 +74,9 @@ function insertTOC(rawContent) {
.filter(header => filterRe.test(header.rawContent))
.map(header => ` - [${header.rawContent}](#${header.hashLink})`)
.join('\n');
return rawContent.replace(TABLE_OF_CONTENTS_TOKEN, tableOfContents);
return rawContent
.replace(TABLE_OF_CONTENTS_TOKEN, tableOfContents)
.replace(LOWERCASE_TOC_TOKEN, tableOfContents);
}

module.exports = {
Expand Down