From bd4a8a8f2a8c0decd897bea636d4b8f2adef1ecc Mon Sep 17 00:00:00 2001 From: Tim Scanlin Date: Wed, 20 Oct 2021 20:53:55 -0700 Subject: [PATCH] fix bug with certain headings (#246) --- src/components/Template/Tocbot/index.js | 2 +- src/js/parse-content.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Template/Tocbot/index.js b/src/components/Template/Tocbot/index.js index 91e77cd1..e442d12a 100644 --- a/src/components/Template/Tocbot/index.js +++ b/src/components/Template/Tocbot/index.js @@ -3,7 +3,7 @@ import React from 'react' const TOCBOT_OPTIONS = { tocSelector: '.js-toc', contentSelector: '.js-toc-content', - headingSelector: 'h2, h3, h4', + headingSelector: 'h2, h3, h4, h5, h6', positionFixedSelector: '.js-toc', includeHtml: true, includeTitleTags: false, diff --git a/src/js/parse-content.js b/src/js/parse-content.js index dad91af6..59c80644 100644 --- a/src/js/parse-content.js +++ b/src/js/parse-content.js @@ -78,7 +78,10 @@ module.exports = function parseContent (options) { while (counter > 0) { lastItem = getLastItem(array) - if (lastItem && lastItem.children !== undefined) { + // Handle case where there are multiple h5+ in a row. + if (lastItem && level === lastItem.headingLevel) { + break + } else if (lastItem && lastItem.children !== undefined) { array = lastItem.children } counter--