eleventy-plugin-toc icon indicating copy to clipboard operation
eleventy-plugin-toc copied to clipboard

Stringified override options don't parse

Open Heydon opened this issue 7 years ago • 5 comments

Hi! So far so good, except when I pass the JSON string in your example, the template no longer parses (Having trouble writing template: docs/components/card/index.html (TemplateWriterWriteError)).

Any idea what that might be? Thanks.

Heydon avatar Oct 09 '18 15:10 Heydon

Sorry for the (inexcusably) late reply; I'll test this out. Can you provide any other info about this particular Eleventy config?

  • What template option are you using?
  • Can you provide an example of the stringified JSON option object you're passing in?

jdsteinbach avatar Jul 29 '20 20:07 jdsteinbach

In my case I have tried two ways and options are not being uptaken by the plugin, they are just being ignored. I was to use UL instead of OL:

const tocOptions = {
  
    tags: ['h2', 'h3', 'h4'], // which heading tags are selected
    wrapper: 'nav',           // element to put around the root `ol`
    wrapperClass: 'toc-abc',       // class for the element around the root `ol`
    ul: true,
    flat: true, 
  
}

module.exports = function(eleventyConfig) {

  //Plugins
  eleventyConfig.setLibrary(
    'md',
    markdownIt(mdOptions)
      .use(markdownItAnchor, mdAnchorOpts)
  )
  
  //eleventyConfig.addPlugin(pluginTOC,tocOptions);

  eleventyConfig.addPlugin(pluginTOC, {
      tags: ['h2', 'h3', 'h4'], // which heading tags are selected
      wrapper: 'nav',           // element to put around the root `ol`
      wrapperClass: 'toc-abc',       // class for the element around the root `ol`
      ul: true,
      flat: false, 
  });

helmutgranda avatar Aug 06 '20 17:08 helmutgranda

@helmutgranda Just published 1.1.0 which supports .eleventy.js options in addPlugin

jdsteinbach avatar Aug 06 '20 17:08 jdsteinbach

@Heydon Recent updates also fixed an issue with JSON options in templates. If you're still using this plugin, can you update the version and see if that works for you? Thanks!

jdsteinbach avatar Aug 06 '20 17:08 jdsteinbach

This issue is >1y old and should be resolved by prior work. However, if anyone is still having this issue, I'll give a week to comment, then close. Thanks!

jdsteinbach avatar Sep 28 '21 21:09 jdsteinbach