Skip to content

Commit

Permalink
fix: handle case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Mar 20, 2019
1 parent dda3208 commit 6a56578
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions v1/lib/core/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const Remarkable = require('remarkable');
const mdToc = require('markdown-toc');
const toSlug = require('./toSlug');

const TABLE_OF_CONTENTS_TOKEN = '<AUTOGENERATED_TABLE_OF_CONTENTS>';
const tableOfContentsRegex = new RegExp(
'<AUTOGENERATED_TABLE_OF_CONTENTS>',
'i',
);

/**
* Returns a table of content from the headings
Expand Down Expand Up @@ -61,11 +64,7 @@ function insertTOC(rawContent) {
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
) {
if (!tableOfContentsRegex.test(rawContent)) {
return rawContent;
}
const filterRe = /^`[^`]*`/;
Expand All @@ -74,9 +73,7 @@ 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)
.replace(LOWERCASE_TOC_TOKEN, tableOfContents);
return rawContent.replace(tableOfContentsRegex, tableOfContents);
}

module.exports = {
Expand Down

0 comments on commit 6a56578

Please sign in to comment.