signalwerk / gatsby-remark-table-of-contents

gatsby remark plugin to generate table of contents
21 stars 10 forks source link

MDX render is printing wrapping HTML tag instead of rendering #33

Open blue148 opened 2 years ago

blue148 commented 2 years ago

After installing the plugin and setting up the config, the output of the MDX file into HTML is "printing" the wrapping div tag as a string instead of rendering it as an HTML tag

gatsby-config.js

module.exports = {
  siteMetadata: {
    title: `Elevate Design System`,
    description: `Design System to support the Elevate Methodology`,
    author: `[Your Name]`,
    language: `en`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-styled-components`,
    `gatsby-plugin-dark-mode`,
    {
      resolve: `gatsby-plugin-mdx`,
        options:{
          gatsbyRemarkPlugins: [

          `gatsby-remark-autolink-headers`,
          {
            resolve: `gatsby-remark-table-of-contents`,
            options: {
              exclude: "Table of Contents",
              tight: true,
              ordered: false,
              fromHeading: 2,
              toHeading: 4,
              className: "table-of-contents"
            },
          },
          `gatsby-remark-prismjs`,
          ],

        },

    },

    {
      resolve: `gatsby-plugin-sass`,
      options: {
        implementation: require("sass"),
        additionalData: `@import "${__dirname}/src/styles/__colors.scss";`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `pages`,
        path: `${__dirname}/src/pages/`,
      },
    },
    {
      resolve: `gatsby-plugin-google-fonts`,
      options: {
        fonts: [
          `inter\:300, 300i,400,400i,600,600i,700` // you can also specify font weights and styles
        ],
        display: 'swap'
      }
    },
    {
      resolve: "gatsby-plugin-root-import",
      options: {
        data: path.join(__dirname, "src", "data"),
        foundations: path.join(__dirname,"src","components","foundation"),
        components: path.join(__dirname,"src","components"),
        styles: path.join(__dirname, "src","styles"),
      },
    },
  ],
};

MDX sample file

---
title: Typography
description: Typography Guidelines for an Elevate Experience
---

```toc
# This code block gets replaced with the TOC
exclude: Table of Contents

Typography Usage

Typography Fonts

Typography Sizes

Accessibility Considerations with Type


Rendered Output code 

Typography

<div className="table-of-contents"> </div>

Typography Usage

Typography Fonts

Typography Sizes

Accessibility Considerations with Type



There's no way I can see to configure the type of HTML wrapper that I can see. Unsure why this would be outputting the tag as string instead of code
angelo-martinez commented 1 year ago

Same Issue, I started getting it when I updated to mdxv2

christopher-besch commented 1 year ago

I also have the same issue, after updating to gatsby-plugin-mdx v4 and mdxv2.

lucastobrazil commented 1 year ago

Same here

lucastobrazil commented 1 year ago

has anyone found any workarounds?

angelo-martinez commented 1 year ago

I had to build my own. Just made a custom component that I add in the markdown<TableOfContents tableOfContents={props.data.mdx.tableOfContents} /> and then I loop over the tableOfContents.items inside that component.

lucastobrazil commented 1 year ago

@signalwerk any thoughts on whether this is a bug or oils be addressed? Seems like basically mdx2 is not supported with the current version due to this...

longkluong commented 1 year ago

Having the same issue sadly.

fgerschau commented 1 year ago

I couldn't figure out how to fix the tests, but I published @ricale's patch as a new npm package to use in the meantime.

https://www.npmjs.com/package/gatsby-remark-table-of-contents-patch