cmaas / markdown-it-table-of-contents

A table of contents plugin for Markdown-it
MIT License
99 stars 33 forks source link

Unable to pass options object into plugin. #39

Closed penseleit closed 3 years ago

penseleit commented 5 years ago

Debugging shows that when I pass an object with options settings into the markdown-it constructor via

use(require("markdown-it-table-of-contents"), options);

the object does not get passed in.

module.exports = (md, o) => {
  const options = Object.assign({}, defaults, o);
  const tocRegexp = options.markerPattern;

In the code snippet above in index.js, the object o is undefined in my debugging session.

I use this object:

{
        "includeLevel": [2, 3, 4],
        "containerClass": "table-of-contents",
        "slugify": "(s) => encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'))",
        "markerPattern": "/^\\[\\[toc\\]\\]/im",
        "listType": "ul",
        "format": "",
        "forceFullToc": false,
        "containerHeaderHtml": "",
        "containerFooterHtml": ""
    }

I think it may be related to this issue:

Usage of arguments.callee is prohibited in strict mode https://github.com/chaijs/chai/issues/384

Because I saw this Error in the debugger:

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them

martinlissmyr commented 3 years ago

Closing as noone seems to want to do a fix for it. If you create a with PR with the necessary fixes I'd accept it.