From b04414a421ba8ae376c3991b69464dbc1263f4ed Mon Sep 17 00:00:00 2001 From: Olivier Berger Date: Thu, 25 Aug 2022 10:01:03 +0200 Subject: [PATCH] Fix minitoc I make a distinction between searching the whole doc contents or just the current section, as I've adapted bigblow to not tabify main sections --- src/bigblow_theme/css/bigblow.css | 1 + src/bigblow_theme/js/bigblow.js | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/bigblow_theme/css/bigblow.css b/src/bigblow_theme/css/bigblow.css index 4a3836c..0282348 100644 --- a/src/bigblow_theme/css/bigblow.css +++ b/src/bigblow_theme/css/bigblow.css @@ -620,6 +620,7 @@ span.todo .selected { padding: 4px; position: fixed; width: auto; + white-space: pre; } #minitoc a { diff --git a/src/bigblow_theme/js/bigblow.js b/src/bigblow_theme/js/bigblow.js index 7ae30f3..6ee48da 100644 --- a/src/bigblow_theme/js/bigblow.js +++ b/src/bigblow_theme/js/bigblow.js @@ -45,13 +45,27 @@ $(function() { // generate contents of minitoc function generateMiniToc(divId) { - $('#minitoc').empty().append('

In this section

'); - $('#' + divId).find('h3').each(function(i) { - let pos = $(this).text().search(" "); - let text = $(this).text().substring(0, pos); - $("#minitoc").append("" - + text + ""); - }); + let headers = null; + if(divId) { + $('#minitoc').empty().append('

In this section

'); + headers = $('#' + divId).find('h3'); + } + else { + $('#minitoc').empty().append('

In this document

'); + headers = $('div#content').find(':header'); + } + headers.each(function(i) { + let text = $(this) + .clone() //clone the element + .children() //select all the children + .remove() //remove all the children + .end() //again go back to selected element + .text().trim(); + var level = parseInt(this.nodeName.substring(1), 10); + let prefix = "".padStart(level-1, " "); + $("#minitoc").append("" + + prefix + text + ""); + }); // Ensure that the target is expanded (hideShow) $('#minitoc a[href^="#"]').click(function() { var href = $(this).attr('href');