rstackjs / rstackjs/rsbuild-plugin-mdx

Syntax highlight in the MDX files

Open
#16 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
9
Forks
0
Avg merge
13h 39m
Merged PRs (30d)
7

Description

Thank you for working on the mdx implementation for the RSBuild. very useful!

I am now migrating Storybook 8 from webpack to RSPack, and I have made good progress so far. Except for the MDX syntax highlight.
As I understand it, Storybook uses react-syntax-highlighter under the hood in their @storybook/addon-docs plugin. For some reason, it is ignored when I switch to storybook-react-rsbuild.

Rsbuild
Image
Webpack
Image

As a workaround, I consider using the PrismJS rehype plugin directly, but it gives a different result

import type {RsbuildConfig} from '@rsbuild/core'
import {pluginReact} from '@rsbuild/plugin-react'
import {pluginMdx} from '@rsbuild/plugin-mdx'
import type {StorybookConfig} from 'storybook-react-rsbuild'
import rehypePrism from '@mapbox/rehype-prism'

const config: StorybookConfig = {
	rsbuildFinal: (cfg: RsbuildConfig): RsbuildConfig => {
		cfg.plugins = [
			pluginReact(),
			pluginMdx({
				mdxLoaderOptions: {
					rehypePlugins: [rehypePrism],
				},
			}),
		]

		return cfg
	},
}
Image

Another option would be to use the mdx-loader directly like this

	{
		test: /\.mdx$/,
		loader: '@storybook/addon-docs/mdx-loader',
		options: {
			rehypePlugins: [rehypePrism],
		}
	},

It is difficult to follow the code in the Storybook, but I think they post-process the parsed MDX file here.
And they use react-syntax-highlighter in order to render the component.

Ideally I would love to re-use the code from @storybook/addon-docs ie the code wrapper for syntax highlight. Or have more examples on how to do it the recommended way with rsbuild-plugin-mdx.

By syntax highlight, I mean the blocks like this one in the *.mdx files

Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing pluginMdx and its mdxLoaderOptions in the rsbuild-plugin-mdx integration used by storybook-react-rsbuild. Compare that behavior with Storybook's linked components.tsx and syntaxhighlighter.tsx, then verify the result with an MDX code block. Done means syntax highlighting works under Rsbuild or the recommended configuration is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
documentation, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.