Code Monkey home page Code Monkey logo

tocbot's Introduction

github-actions cdnjs GitHub Sponsors

Tocbot builds a table of contents (TOC) from headings in an HTML document. This is useful for documentation websites or long markdown pages because it makes them easier to navigate. This library was inspired by Tocify, the main difference is that Tocbot uses native DOM methods and avoids the jQuery & jQuery UI dependencies.

Get Started

You can use npm to install it or include the script on the page with HTML.

Download it here

Include JS

Install it with npm.

npm install --save tocbot

Then use with either commonjs or ESM imports:

const tocbot = require('tocbot/dist/tocbot.js')
// OR
import tocbot from 'tocbot'

// Initialize tocbot
tocbot.init()

OR

Include the script at the bottom of the page before the closing body tag.

<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.27.4/tocbot.min.js"></script>

Include CSS

CSS is used for expanding & collapsing groupings and some basic styling.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.27.4/tocbot.css">

OR

If you installed it with npm and use sass / postcss you might try importing the styles from 'node_modules', see the includePath option documentation for more info

@import 'tocbot/src/scss/tocbot';

Usage

Initialize the script at the bottom of the page before the closing body tag.

tocbot.init({
  // Where to render the table of contents.
  tocSelector: '.js-toc',
  // Where to grab the headings to build the table of contents.
  contentSelector: '.js-toc-content',
  // Which headings to grab inside of the contentSelector element.
  headingSelector: 'h1, h2, h3',
  // For headings inside relative or absolute positioned containers within content.
  hasInnerContainers: true,
});

NOTE: Make sure the body is scrollable and the document headings have id attributes, tocbot and your browser needs these things to make hashes jump to the proper heading, some markdown libraries (like marked) already do this for you.

If content in the div has changed then trigger a refresh (optionally with new options).

tocbot.refresh();

Also you can use it within typescript:

import * as tocbot from 'tocbot';

tocbot.init({
  // Options
});

tocbot.refresh();

tocbot.destroy();

Examples

If you'd like to add your page to this list open a pull request.

Requirements

This library uses vanilla JavaScript. It is less than 350 bytes of CSS and about 3.6Kb of JavaScript (minified and gzipped) it also has no dependencies.

This script works in all modern browsers and IE 9+.

Make sure rendered headings have id attributes, some markdown libraries (like marked) already do this. If you need to do this client side see this script.

NOTE: to exclude anchor elements from smooth scrolling, add the class no-smooth-scroll.

Fixed headers

To handle fixed headers with tocbot, just pass the header offsets as options to tocbot. For example, the options needed for a 40px tall fixed header would be:

tocbot.init({
  headingsOffset: 40,
  scrollSmoothOffset: -40
})

API

Options

// Where to render the table of contents.
tocSelector: '.js-toc',
// Or, you can pass in a DOM node instead
tocElement: element,
// Where to grab the headings to build the table of contents.
contentSelector: '.js-toc-content',
// Or, you can pass in a DOM node instead
contentElement: element,
// Which headings to grab inside of the contentSelector element.
headingSelector: 'h1, h2, h3',
// Headings that match the ignoreSelector will be skipped.
ignoreSelector: '.js-toc-ignore',
// For headings inside relative or absolute positioned containers within content
hasInnerContainers: false,
// Main class to add to links.
linkClass: 'toc-link',
// Extra classes to add to links.
extraLinkClasses: '',
// Class to add to active links,
// the link corresponding to the top most heading on the page.
activeLinkClass: 'is-active-link',
// Main class to add to lists.
listClass: 'toc-list',
// Extra classes to add to lists.
extraListClasses: '',
// Class that gets added when a list should be collapsed.
isCollapsedClass: 'is-collapsed',
// Class that gets added when a list should be able
// to be collapsed but isn't necessarily collapsed.
collapsibleClass: 'is-collapsible',
// Class to add to list items.
listItemClass: 'toc-list-item',
// Class to add to active list items.
activeListItemClass: 'is-active-li',
// How many heading levels should not be collapsed.
// For example, number 6 will show everything since
// there are only 6 heading levels and number 0 will collapse them all.
// The sections that are hidden will open
// and close as you scroll to headings within them.
collapseDepth: 0,
// Smooth scrolling enabled.
scrollSmooth: true,
// Smooth scroll duration.
scrollSmoothDuration: 420,
// Smooth scroll offset.
scrollSmoothOffset: 0,
// Callback for scroll end.
scrollEndCallback: function (e) {},
// Headings offset between the headings and the top of the document (this is meant for minor adjustments).
headingsOffset: 1,
// Timeout between events firing to make sure it's
// not too rapid (for performance reasons).
throttleTimeout: 50,
// Element to add the positionFixedClass to.
positionFixedSelector: null,
// Fixed position class to add to make sidebar fixed after scrolling
// down past the fixedSidebarOffset.
positionFixedClass: 'is-position-fixed',
// fixedSidebarOffset can be any number but by default is set
// to auto which sets the fixedSidebarOffset to the sidebar
// element's offsetTop from the top of the document on init.
fixedSidebarOffset: 'auto',
// includeHtml can be set to true to include the HTML markup from the
// heading node instead of just including the innerText.
includeHtml: false,
// includeTitleTags automatically sets the html title tag of the link
// to match the title. This can be useful for SEO purposes or
// when truncating titles.
includeTitleTags: false,
// onclick function to apply to all links in toc. will be called with
// the event as the first parameter, and this can be used to stop,
// propagation, prevent default or perform action
onClick: function (e) {},
// orderedList can be set to false to generate unordered lists (ul)
// instead of ordered lists (ol)
orderedList: true,
// If there is a fixed article scroll container, set to calculate titles' offset
scrollContainer: null,
// prevent ToC DOM rendering if it's already rendered by an external system
skipRendering: false,
// Optional callback to change heading labels.
// For example it can be used to cut down and put ellipses on multiline headings you deem too long.
// Called each time a heading is parsed. Expects a string and returns the modified label to display.
// Additionally, the attribute `data-heading-label` may be used on a heading to specify
// a shorter string to be used in the TOC.
// function (string) => string
headingLabelCallback: false,
// ignore headings that are hidden in DOM
ignoreHiddenElements: false,
// Optional callback to modify properties of parsed headings.
// The heading element is passed in node parameter and information parsed by default parser is provided in obj parameter.
// Function has to return the same or modified obj.
// The heading will be excluded from TOC if nothing is returned.
// function (object, HTMLElement) => object | void
headingObjectCallback: null,
// Set the base path, useful if you use a `base` tag in `head`.
basePath: '',
// Only takes affect when `tocSelector` is scrolling,
// keep the toc scroll position in sync with the content.
disableTocScrollSync: false,
// Offset for the toc scroll (top) position when scrolling the page.
// Only effective if `disableTocScrollSync` is false.
tocScrollOffset: 0,

Methods

.init

Initialize tocbot with an options object.

tocbot.init(options)

.destroy

Destroy tocbot and remove event listeners.

tocbot.destroy()

.refresh

Refresh tocbot if the document changes and it needs to be rebuilt.

tocbot.refresh()

Troubleshooting

  • Tocbot scrolls to the right position onClick but highlighting doesn't seem to show the active section
    • Try running this from the console: tocbot.refresh({ ...tocbot.options, hasInnerContainers: true }). If that works then one option (hasInnerContainers: true) to handle inner containers should be all you need to add.
  • If you have a really long TOC and are seeing headings getting truncated, then have a look at this issue for a workaround to resolve it.

Contributing

Contributions and suggestions are welcome! Please feel free to open an issue if you run into a problem or have a feature request. I'll do my best to respond in a timely fashion.

If you want to open a pull request just fork the repo but please make sure all tests and lint pass.

Running Tests

npm run test

Steps to publish

  • Push a branch and open a pull request
  • run npm version <patch|minor|major>
  • Update readme.md with notes
  • Merge the pull request
  • commit dist/
  • run npm publish
  • make release on github

License

MIT

tocbot's People

Contributors

a1youssef avatar adipasquale avatar alex-ketch avatar bashmish avatar benceszalai avatar bopeng avatar brian-pho avatar deining avatar dependabot[bot] avatar dkniffin avatar dmalan avatar e-vance avatar erickzhao avatar felipemarcos avatar gjhenrique avatar gjones avatar hoytech avatar jeffwillette avatar jensenhwa avatar kaitlynkatz avatar kbrabrand avatar mashirozx avatar nchilada avatar nehalist avatar pissedcapslock avatar regulyarniy avatar ronnielsen avatar tscanlin avatar vimcaw avatar zoomingiladsher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tocbot's Issues

Scrolling problem with large TOCs

The scrolling fails with large TOCs: the list continues beyond the lower scroll limit.

For example, run the following command and paste the result into the "Try it" Markdown tester on https://tscanlin.github.io/tocbot/. (Warning: the xclip command will write to your clipboard.)

i=0; while [ $i -lt 50 ]; do [ $i = 0 ] && echo "# top"; i=$(($i + 1)); echo "## section $i"; done | xclip -selection clipboard

Thanks!

Bower

Thanks for sharing such a great library!

Is there a chance you could add Bower support please?

Option to add anchors next to header tags or wrap header tags as anchors

Hi @tscanlin ,

thank you for this awesome tool.

It's good if I can achieve this

<h2 id="the-header-id"><a href="#the-header-id">About this Guide</a></h2>

Or <h2 id="the-header-id">About this Guide<a href="#the-header-id">&#128279;</a></h2> with &#128279; configurable.

Since the id of the header is generated by tocbot, so the option to make the header tags linkable from tocbot would be nice.

Cheers

Feature: How to deal with huge footers?

When a site has a huge footer since the left side is fixed it will go over the footer.

I was thinking maybe making a new class called: toc-footer-stopper
When the footer id is close to the view-port remove the fixed class from the fixed class target and add the footer-stopper class which makes the toc absolute to the bottom of it's container, and when the footer is scrolled back out of the view-port remove it and add back the fixed class?

Is this a good approach or is there a better way?

add css and min.js to repo

hi, recently we want to add your lib to https://cdnjs.com, could you please consider adding tocbot.css and tocbot.min.js to git repo or nam package so that we can use git auto-update config or npm auto-update config to automatically add them and later version.
we will respect you if you don't want to do that, then we may add them manually with a PR, but it will be hard to keep your lib the latest version on cdnjs.
thank you very mush!

cdnjs/cdnjs#8844

Cannot read property 'getBoundingClientRect' of null

@tscanlin I get "Cannot read property 'getBoundingClientRect' of null" in console when I click on dropdown in my
Bootstrap navigation. I'm pulling js and css from CDN. I have my code set as this:

tocbot.init({
    // Where to render the table of contents.
    tocSelector: '.help-sidebar',
    // Where to grab the headings to build the table of contents.
    contentSelector: '.help-main',
    // Which headings to grab inside of the contentSelector element.
    headingSelector: 'h1, h2, h3, h4, h5, h6',
});

The issue is somehow caused by my href="#!" on dropdown, As soon as I remove exclamation mark from href attribute - everything works fine.

Is this expected behaviour since I have tocSelector and contentSelector defined. I thought that these two were enough to isolate tocbot from the rest of the page.

Thanks.

callback

Hi,
is there a way to have a callback when a tocbot item is clicked?
I'm trying to trigger something when a link is clicked but it ignores it.
I tried directly with a selector:

$('.tocbot a').on('click', function(){
    // Stuff I want to do
    console.log('callback');
});

And I've also tried to use SmoothScroll callback option:

smoothScrollOptions: {
    easing: 'easeOutQuart',
    offset: 0,
    speed: 600,
    callback: function ( anchor, toggle ) {
        // Stuff I want to do
        console.log('callback');
    }
},

None works. Is there an obvious way I'm missing?

Thanks

Script initialization question

Hello,
I am trying to apply Tocbot to my company's documentation project. In the ReadMe, the initialization is shown as below:

tocbot.init({
  // Where to render the table of contents.
  tocSelector: '.js-toc',
  // Where to grab the headings to build the table of contents.
  contentSelector: '.js-toc-content',
  // Which headings to grab inside of the contentSelector element.
  headingSelector: 'h1, h2, h3',
});

As I assume, the js-toc should be the nav ID of my TOC, and the js-toc-content should be the div ID of my content. Am I thinking correctly?

Thank you.

Set classes on list item

Alongside the

  listClass: 'toc-list'

configuration option for the ul list elements, it would be very useful to also have an option for applying class(es) to the li list item elements. Something like

listItemClass: 'toc-list-item'

For example, this would make it possible to use a Bootstrap list group for the TOC, by applying the list-group class at ul level, and the list-group-item class at li level.

Doesn't quite work in Edge / IE11

Thanks for tocbot, really appreciated. I am having some cross-browser compatibility issues, however. I'm afraid my Javscript skills are inadequate to trace further. It can be readily seen on the example website however.

What happened:

Using Microsoft Edge 38.14393.1066.0 and going to https://tscanlin.github.io/tocbot/

  1. When I scroll down using my wheel mouse I see the green bar moving down.
  2. When I put in the debug console, document.getElementsByClassName('is-active-link')[0] I get the correct entry.
  3. I now click on a TOC link different to the highlighted one. The contents on the left scrolls to the correct link. The green bar on the right does not move. The same command in the debug console shows no change (i.e. is on the previous TOC entry relating to the still highlighted green entry).

What I expected:

I expect when I clicked on an entry the green bar would move to it and it would receive the is-active-link class.

This does not work in IE11 11.1770.14393.0
This does work as I expected in Chrome 61.0.3163.91 (Official Build) (64-bit)

Since compatibility is an aim for tocbot if this could be remedied I would be most grateful.

Seems not support non English title?

It's unable to jump to a element with a Chinese (uft-8) id like <a href="#第一章">第一章</a> and <h1 id="第一章">第一章<h1>

You may see it Here

I guess it maybe href to id itself not support utf-8 characters, so am I able to change the id into something else? Like only a number as id instead of the original text?

Menu resizes

Hello,

I got tocbot working - and it seems to work great.

But there is a little problem: The menu box resizes as shown in this gif.

2017-05-15 09 48 20

How can I solve this?

I encounter a problem with using tocbot on my project

my subtiltle tag is like:

<h3 id="Emacs"><a href="#Emacs" class="headerlink" title="Emacs"></a>Emacs</h3>

and generated table of contents is:

<li class="toc-list-item"><a data-scroll="" href="#Emacs" class="toc-link node-name--H3 ">
<a href="#Emacs" class="headerlink" title="Emacs"></a>Emacs</a>
</li>

It doesn't work on this situation!
If I click one or other toc list item, the web page will scroll to the top.
There is my initialization:

tocbot.init({
      // Where to render the table of contents.
      tocSelector: '#toc',
      // Where to grab the headings to build the table of contents.
      contentSelector: '.article-content',
      // Which headings to grab inside of the contentSelector element.
      headingSelector: 'h2, h3',
      collapsibleClass: 'is-collapsible',
      smoothScrollOptions: {
        easing: 'easeInOutCubic',
        //offset: 0,
        speed: 300, // animation duration.
        updateURL: false
      },
      listClass: 'toc-list',
      headingsOffset: 0,
      includeHtml: true
    });

Through I setup the 'updateURL' false, the URL is still changing with my clicking toc.
Is there a problem?

Undesired extra space after </html> tag

When the table of content is activated, an extra space is added after the closing tag like so:

image

I guess it is to allow jumping to the last heading even if there is not enough space to do so but how can I prevent/control that? (I just copied the code from the documentation without adding modifications)

it don't jump to heading afterclicking the toc item of non English.

toc item:

<a href="#绘图区构建" class="toc-link node-name--H1  is-active-link">绘图区构建</a>

heading:

<h1 id="绘图区构建"><a href="#绘图区构建" class="headerlink" title="绘图区构建"></a>绘图区构建</h1>

After I click the toc item of non English, nothing has happen, don't jump to the heading, URL bar don't change also, and Console is empty.
it work on Emglish heading.

Prevent wrong active link

Hello,

at the moment the active link is not set correctly.

If I open my site the first header is selected correctly. But if I am scrolling down just a bit, it "hops" over all other headings and sets the last one as "active" (the actual heading is not even visible yet).

How can I fix that?

bildschirmfoto 2017-07-18 um 16 51 21

toc-link and node--name class are not seperated

Hi,

I just installed tocbot and its working great. But in the browser console, I always got an error that the className could not be found. After debugging indeed it was empty. After some research we found out that in file build-html.js e.g. line 166 the split function is cutting out the SPACE_CHAR between the two css classes. I fixed this with an space in the join function, which is coming right after.

Would be nice if this could be fixed in the code, too.

Cheers,
Steffen

Allow specifying where `top` should be calculated from

Hi,

I'm working on a project where the page content is inside a position: fixed; element with overflow: scroll set. This seems to break the way top is calculated.

I believe the fix would be to fall back to scrollTop of the content container. Perhaps this could use the existing contentSelector option to find the element?

Relevant line:

var top = document.documentElement.scrollTop || body.scrollTop;

I don't do much front end dev so I'm not sure if this would be the best way. Would you accept a patch like that or is there another way you would tackle it?

Cheers

Adding tocbot lets href='#' jump to page header

Hi everybody,

I just mentioned the following:

If I include app/assets/tocbot/tocbot.js all links that are leading to # are bringing me back to the pagestart. If I don't include app/assets/tocbot/tocbot.js this is not the case.

Example: Visit https://reptilien.blog/blog/2018/02/futtertierzucht and click on Antworten (German for "Answer") and the link points to the top of the page.

Do the same thing here and it does not jump to the page's top.

I'm really not good in JS - but this shouldn't be the case, right?

In the roadmap it mentioned that it needed reactJS support?

It mentioned that reactJS support was needed which led me to believe that it was not currently working with rectJS. I got it working pretty much effortlessly in reactJS so I was wondering what you meant by reactJS support or if that can be removed from the readme?

IE10 compatibility when using via NPM

Hi

I am using Tocbot in Gatsby site like this:

import Tocbot from "tocbot";

export class Component extends Component {
    componentDidMount() {
        Tocbot.init({
            tocSelector: "#toc",
            contentSelector: "#content",
            headingSelector: "h1, h2, h3",
            scrollSmooth: false
        });
    }

    componentDidUpdate() {
        Tocbot.refresh();
    }

    componentWillUnmount() {
        Tocbot.destroy();
    }

Problem is that this fails in IE10, because scrollsmooth uses const declarations, which do not work in IE<11.

It seems to be only place in Tocbot to use const declarations, so perhaps its an accident ?

http://tscanlin.github.io/tocbot/ does seem to work in IE10, so apparently code running there is babelized somehow ?

Strange thing is that that this is not fixed in Gatsby's build process, perhaps I have to investigate that further.

"onClick" init option does not seem to work

Hello,
we are trying to set up an action on click event on Tocbot links with the "onClick" init option :

tocbot.init({
       tocSelector: '#page-dossier-summary-list',
       contentSelector: '#page-dossier-content',
       headingSelector: 'h2',
       linkClass: 'page-dossier-summary-link',
       listClass: 'page-dossier-summary-list',
       scrollSmooth: false,
       onClick: function(e){ console.log("test"); }
});

Tocbot is correctly init. But clicking on the links does not execute our function.

We tried to disable smooth scrolling with scrollSmooth: false as we thought the plugin action would be stopping the click event propagation. But it did not fix.

TypeError: Type error

Hello,

I would really like to use tocbot - but unfortunately I'm getting this error:

bildschirmfoto 2017-05-12 um 12 13 49

I'm initializing the tocbot like this:

<script src="/assets/tocbot/dist/tocbot.js"></script>
        <script>
								tocbot.init({
                                    tocSelector: '.toc',
                                    contentSelector: '.uk-article',
                                    headingSelector: 'h1, h2, h3',
								 });
								</script>

The source of the page is:

<article class="uk-article tm-container-small">
    <h1 class="uk-article-title">Test</h1>

    <p class="uk-article-meta">
        Written by admin on <time datetime="2017-05-09T06:44:10+00:00" v-cloak>{{ "2017-05-09T06:44:10+00:00" | date "longDate" }}</time>    </p>

    <div class="uk-margin">
<div class='toc'></div>
<h2>Test</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

<h2>Test 2</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p></div>

Setting scroll offset

Hi,
I hope I'm just missing something here, but shouldn't there be a setting to set an offset for the auto scroll?
"headingsOffset" works when manually scrolling, but if I click on a link in the TOC, the heading is hidden behind the fixed top navbar:

tocbot

Any suggestions?

zenscroll + nextjs issue

This is not really a bug, but more of a heads up.

Backstory
I've been working on a site on top of nextjs. We've been struggling with a bug for a long while where the next/routercomplains that url is undefined. It happened when I navigated from one page to another, and then clicked back and then forward in the browser.

cue hours of digging...

Findings
After digging through large portions of next/router and our own code, I was able to isolate the issue to tocbot. I had a hunch that the problem was that the location and that next got confused.

In the end it turned out to be zenscroll setting the window.location that mess up the history data. So when going back and then forward again, next won't find enough information to figure out what page to show.

"Solution"
Disable smooth scrolling by setting smoothScroll in the tocbot initialization. In my app I've worked around it by disabling scrolling, adding an onclick handler where next router is used to replaceState.

I handle the animation to the element in my app, but the crux is to prevent manipulation of the window.location from places other than next/router.

Body { overflow: hidden; } vs. Dynamic highlight

Hi, Tim! Thank you very much for Tocbot, looks very interesting!

I have a layout with 2 columns - left column for TOC and right column for main content. Quite common approach.

Each column have it's own scrollbar (overflow: auto), while the body itself is not scrollable
(body { overflow: hidden; }).

(This way, each column could be scrolled independently of another.)

And, my problem is that Tocbot doesn't work in this case. TOC is shown, but despite of scrolling, it always highlight only the first header.

Here is code which I tested:
https://jsfiddle.net/opbkpvwj/

TypeError: target.className.indexOf is not a function at Object.disableTocAnimation

Hi there,

Thanks for amazing plugin! But I faced with bug using it.

If you place some svg icon on the page and try to click it you'll see the error in your console:

Uncaught TypeError: target.className.indexOf is not a function
    at Object.disableTocAnimation (tocbot.js:549)
    at HTMLDocument.<anonymous> (tocbot.js:215)
    at HTMLDocument.<anonymous> (tocbot.js:128)

screen shot 2017-03-01 at 15 49 27

Hiding headings from the ToC

Hi,

In our documentation set, we hide some content based on a toggle that the reader can select. When that includes a heading, we'd like to hide the heading from the ToC, too. If we could do something like add a class (perhaps called "hideFromToC" to the heading when we want to hide it and remove the class when we want to show it, that'd do the trick. (We'd use the refresh function to redraw after hiding or showing).

Thanks.

OL wrapping element instead of UL

Thanks for this great script. Unless I'm missing it, could you please add an option to use OL instead of UL as the list container tag (including sublists)? Thanks.

Limitation on number of nodes in TOC

I have a TOC that has 172 (!) sub-nodes under a top-level node (the document is an API reference generated from Swagger via swagger2markup).

Only 114 of the nodes are rendered by Tocbot, even though I can see all 172 list items in the generated HTML source.

Is this a known limitation?

HTML in headlines is not working

Hey!

Today I noticed that using <sup> in a headline the TOC entry is not correct/ignored. – Can you fix it, please?!

Example:
<h3 id="app-current">„Test<sup><small><strong>16.1</strong></small></sup>“</h3>
becomes
<a class="toc-link node-name--H3 " href="#app-current" data-scroll="">„Test16.1“</a>
in TOC.

Thanks and best regards! :-)

empty href

Hi, I'm just trying your plugin but something ins't working like it should. The TOC references are returning empty:
<a data-scroll="" href="#" class="toc-link node-name--H2 is-active-link">My H2 Heading</a>
and the headings have no id attached to them.

Any idea why?

(node:41536) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token: name (tocbot)

I use npm to install tocbot, import it and init it.
I don't use the tool like webpack or gulp.

import tocbot from 'tocbot'

tocbot.init({
    // Where to render the table of contents.
    tocSelector: '.sidebar',
    // Where to grab the headings to build the table of contents.
    contentSelector: 'article',
    // Which headings to grab inside of the contentSelector element.
    headingSelector: 'h1, h2, h3',
    onClick: function () {
        if (shade.style.display === 'block') {
            switchSidebar();
        }
    }
});

But when I run, console display:

(node:41536) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token: name (tocbot)

Selected TOC element scrolls under fixed header

Hey, I have a site with a fixed header (style="position: fixed;"). When I click an item in the TOC, the selected element scrolls to the top of the page, as expected, but ends up underneath the fixed header. I have tried setting headingsOffset to the height of the header, but it seems to have no effect. Am I missing an option for this situation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.