Skip to content

Commit

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

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

/**
* Returns a table of content from the headings
Expand Down Expand Up @@ -61,10 +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) {
return rawContent;
}
if (!tableOfContentsRegex.test(rawContent)) {
if (!rawContent || !tocRegex.test(rawContent)) {
return rawContent;
}
const filterRe = /^`[^`]*`/;
Expand All @@ -73,7 +67,7 @@ function insertTOC(rawContent) {
.filter(header => filterRe.test(header.rawContent))
.map(header => ` - [${header.rawContent}](#${header.hashLink})`)
.join('\n');
return rawContent.replace(tableOfContentsRegex, tableOfContents);
return rawContent.replace(tocRegex, tableOfContents);
}

module.exports = {
Expand Down

0 comments on commit 163622d

Please sign in to comment.