New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MDX2: Add automigration for GFM support #20091
Comments
I've been struggling for days, trying to figure out how to enable GFM with MDX2. If nothing else, there should be a simple example of how to do this in the docs. It's extraordinarily frustrating. |
I'd imagine that:
... that should do it? @Kwooda ? |
@shilman I tried writing the automigration code, and due to the flexibility of It can be ESM or CJS, TypeScript of Plain javascript, it can have 1 default export, or a bunch of named exports.. and can technically even export a function a default. AFAIK we do not have a reliable way of getting/setting this, which would allow me to add runtime-code to the file. I need to add an import/require statement, and I need to add a function invocation. It's not impossible, but I am convinced it's going to be way way waaay easier to add this to the user's main.js using the existing methods: module.exports = {
addons: [‘@storybook/addon-gfm']
}; And this new addon is responsible for depending on the package, and injecting it in the proper place in the preset-chain. It might make it less transparent for the user.. I'm not sure which one is truly more important? easy of migration or easy of modification after? Depending on which one we prioritize, we either: write the migration OR we improve docs.. |
@ndelangen I tried that and it doesn't know what remarkGfm is. |
Yeah, you'd have to import/require the module.. here's the recipe:
|
It's ESM only and won't let me include it that way. And I can't use an import there, either, as it complains that I can't use it outside of a module. import remarkGfm from 'remark-gfm' |
@shilman looks like making the preset is pretty much required then.. |
@ndelangen I'm not sure that's true. I have it working in the mdx2-csf repo example Storybook. Granted I'm not doing any CJS stuff there like storyshots. Let's discuss on Monday? |
We talked about it and we need to create a documentation-page about MDX guide. One of the items on that page needs to be about how to add GFM to storybook. The auto-migration fro mdx1-to-csf needs to be updated to notify users to go to that page, and for what reasons. |
@Kwooda The code I linked to isn't ESM, it's CommonJS. I can't know what "it" refers to when you say:
Perhaps it helps if you rename |
@ndelangen when I use require in main.js, I get this message:
When I try to use import, I get this message:
|
@Kwooda Could you try using the import and changing main.js to main.mjs ? |
Looks like the new version is ESM only @shilman |
@joshwooding I get the same errors:
Except I don't know why it's complaining about require() since I am using import.
|
@Kwooda Ah, it's the import of the main.mjs file in the storybook code that's erroring there. Just curious what version of Storybook are you testing this with? |
@joshwooding I am using version 6.5.14 |
Ah, ESM support came in an early v7 alpha. |
Is there a way to make GFM work with MDX2 in 6.5.14, or do I need to wait until version 7 comes out? |
@ndelangen, @joshwooding I tried this with esm in storybook@7.0.0-beta.13 and still couldn't get it to work. // .storybook/main.mjs
import remarkGfm from "remark-gfm";
...
export const addons = [
"@storybook/addon-links",
{
name: "@storybook/addon-docs",
options: {
mdxCompileOptions: {
remarkPlugins: [remarkGfm],
},
},
},
{
name: "@storybook/preset-create-react-app",
options: {
scriptsPackageName: "react-scripts",
},
},
"@storybook/addon-postcss",
];
... No error messages, it just doesn't render tables like I expected. Am I doing something wrong here? |
@justintemps would you happen to have a repro for me to debug? |
@ndelangen fair enough! Will put one together as soon as I get a chance. |
The solution here does not work under the storybook/docs/snippets/common/storybook-main-config-remark-options.js.mdx |
I think it's fixed by #20116 ... will try to get that merged ASAP |
It looks good. |
I'm still having issues with the |
@markpalfreeman can you share your project, or at least your |
@markpalfreeman, not sure if this helps, but I just ran into this issue today. Make sure your plugin is under {
name: "@storybook/addon-docs",
options: {
mdxPluginOptions: {
mdxCompileOptions: {
remarkPlugins: [remarkGfm],
},
},
},
}, |
Thank you for that comment @jameschensmith |
🤯 @jameschensmith that works! Thanks, I think the docs need to be tweaked to match. As a slight aside, I get this console message (twice) from the dev server, but the plugin seems to render the GFM features as expected:
Here's my main.ts file: import type { StorybookConfig } from '@storybook/web-components-vite';
import rootConfig from '../../../../.storybook/main';
import remarkGfm from 'remark-gfm';
const config: StorybookConfig = {
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-a11y',
{
name: '@storybook/addon-docs',
options: {
mdxPluginOptions: {
mdxCompileOptions: {
remarkPlugins: [remarkGfm]
}
}
}
}
],
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|ts)'],
framework: {
name: '@storybook/web-components-vite',
options: {}
}
};
export default config; |
@markpalfreeman, yeah, I think you might also need to disable docs from the essentials add-on (snippet highly truncated): export default {
addons: [
{
name: "@storybook/addon-essentials",
options: {
docs: false,
},
},
{
name: "@storybook/addon-docs",
options: {
mdxPluginOptions: {
mdxCompileOptions: {
remarkPlugins: [remarkGfm],
},
},
},
},
],
}; |
Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.54 containing PR #21186 that references this issue. Upgrade today to the
|
I tested this configuration under @storybook/react-webpack5, but it didn't work. The tables in the mdx file were not rendered.
@storybook/addon-docs@7.0.7 |
Edit: My bad worked after migrating from requirejs to esm. |
Are there any plans to support |
@mayerraphael how did you do that? Edit: it's done by replacing import remarkGfm from 'remark-gfm';
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
// Other addons go here
{
name: '@storybook/addon-docs',
options: {
mdxPluginOptions: {
mdxCompileOptions: {
remarkPlugins: [remarkGfm],
},
},
},
},
],
};
export default config; |
Is your feature request related to a problem? Please describe
One of the breaking changes from MDX1 to MDX2 is lack of Github-flavored markdown (GFM) support. This will break a lot of SB users as they upgrade.
Describe the solution you'd like
We could add GFM by default in Storybook, but we're trying to get away from doing magic stuff and get as close to "standard MDX2" as possible.
Therefore, we should have an automigration that asks whether you want to add GFM support and updates your configuration accordingly.
Here's an example in a real project:
Describe alternatives you've considered
Just setting the defaults to support GFM
Are you able to assist to bring the feature to reality?
yes, I can
Additional context
No response
The text was updated successfully, but these errors were encountered: