From 79bbe8e59ece457938aa6c7dbd238eb968e78c35 Mon Sep 17 00:00:00 2001 From: vikrantsinghthakur Date: Wed, 20 Mar 2019 15:54:17 +0530 Subject: [PATCH] fix: handle case insensitive table of contents token (#1288) * fix: check for lowercase TOC token * run prettier * fix: handle case insensitive * nits --- v1/lib/core/toc.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/v1/lib/core/toc.js b/v1/lib/core/toc.js index 691d202b09..9ee9a70457 100644 --- a/v1/lib/core/toc.js +++ b/v1/lib/core/toc.js @@ -9,7 +9,7 @@ const Remarkable = require('remarkable'); const mdToc = require('markdown-toc'); const toSlug = require('./toSlug'); -const TABLE_OF_CONTENTS_TOKEN = ''; +const tocRegex = new RegExp('', 'i'); /** * 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 // contents inserted function insertTOC(rawContent) { - if (!rawContent || rawContent.indexOf(TABLE_OF_CONTENTS_TOKEN) === -1) { + if (!rawContent || !tocRegex.test(rawContent)) { return rawContent; } const filterRe = /^`[^`]*`/; @@ -67,7 +67,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); + return rawContent.replace(tocRegex, tableOfContents); } module.exports = {