Skip to content
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

MDX linkings should not rely on the remark-slug plugin to generate slug for headers #9329

Closed
patricklafrance opened this issue Jan 5, 2020 · 2 comments

Comments

@patricklafrance
Copy link
Member

patricklafrance commented Jan 5, 2020

Is your feature request related to a problem? Please describe.
The current version of MDX linkings rely on the remark-slug plugin to generate the slugs for headers:

<h1 id="supported-platforms" class="sbdocs sbdocs-h1 css-1j28tt">

There is a few issues with this approach:

  • The plugin doesn't handle MDX dynamic expression:

The following dynamic expression ## <Fragment children={props.title} /> result in the following slug:

<h2 id="fragment-childrenpropstitle-" class="sbdocs sbdocs-h2 css-1lg570m">
  • Since remark-slug is an MDX plugin, it can't be used for DocsPage.

Describe the solution you'd like
SB should develop a set of <Header /> components that will take care of rendering the header element and generate the appropriate slug.

These components could be used for DocsPage and also as custom MDX components for MDX linkings.

@kevin940726
Copy link
Contributor

Looks like we already have a set of components like in

export const HeaderMdx: FC<HeaderMdxProps> = props => {
const { as, id, children, ...rest } = props;
// An id should have been added on every header by the "remark-slug" plugin.
if (id) {
return (
<HeaderWithOcticonAnchor as={as} id={id} {...rest}>
{children}
</HeaderWithOcticonAnchor>
);
}
// @ts-ignore
const Header = components[as];
// Make sure it still work if "remark-slug" plugin is not present.
return <Header {...props} />;
};

So now we need to slugify the text content into id? Since the content is evaluated in run time, how should it suppose to do that 🤔?

@shilman shilman added the todo label Feb 9, 2020
@shilman shilman modified the milestones: 6.0, 6.0 docs May 8, 2020
@shilman shilman modified the milestones: 6.0 docs, 6.1 docs Jun 24, 2020
@shilman shilman modified the milestones: 6.1 docs, 6.2 docs Nov 24, 2020
@shilman shilman removed this from the 6.2 docs milestone Jun 8, 2021
@shilman
Copy link
Member

shilman commented Jun 15, 2023

We’re cleaning house! Storybook has changed a lot since this issue was created and we don’t know if it’s still valid. Please open a new issue referencing this one if this is still relevant in SB 7.x.

@shilman shilman closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants