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

feat: Add MDX rehypeSyntaxHighlight plugin options #3706

Closed
wants to merge 3 commits into from

Conversation

swwind
Copy link
Contributor

@swwind swwind commented Apr 7, 2023

What is it?

  • Feature / enhancement
  • Bug
  • Docs / tests

Description

fixes QwikDev/qwik-evolution#86

Add plugin options for all 3 core plugins.

Use cases and why

// vite.config.mts

import fsharp from "refractor/lang/fsharp";

export default defineConfig(() => {
  return {
    plugins: [
      qwikCity({
        mdxPlugins: {
          remarkGfm: {
            singleTilde: false,
          },
          rehypeSyntaxHighlight: {
            setup(refractor) {
              refractor.register(fsharp)
            }
          },
          rehypeAutolinkHeadings: false,
        }
      })
    ]
  }

Checklist:

  • My code follows the developer guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • Added new tests to cover the fix / functionality

@stackblitz
Copy link

stackblitz bot commented Apr 7, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@swwind swwind marked this pull request as draft April 10, 2023 06:18
@swwind
Copy link
Contributor Author

swwind commented Apr 10, 2023

This fix still contains a problem, types of refractor, remark-gfm and rehype-autolink-headings must be installed manually to have full functionality.

i.e. You must install remark-gfm manually to make remarkGfm option in mdxPlugins have type boolean | import('remark-gfm').Options, otherwise it will be any due to the bundle step doesn't bundle external types all together.

Despite this little problem, other functionalities just works fine.

@swwind swwind marked this pull request as ready for review April 10, 2023 06:50
@manucorporat
Copy link
Contributor

It's a big problem, no? if we merge this, it will break everybody's project because of missing types

@swwind
Copy link
Contributor Author

swwind commented Apr 20, 2023

It's a big problem, no? if we merge this, it will break everybody's project because of missing types

@manucorporat I think it's possible to inline all the types to handle this problem, but I think the original solution requires more API design thinking.

The original issue wants to have setup function for configuring refractor, but qwik-city bundled every dependency into a single package, and user manually installed refractor package version may differ than our bundled version. Combining pieces of code from different versions of a package has a high potential for bugs and vulnerabilities.

@swwind swwind marked this pull request as draft April 20, 2023 07:29
@swwind
Copy link
Contributor Author

swwind commented Apr 21, 2023

It doesn't give sense to inline the types. And I have no idea how to deal with type declaration.

I'll suggest export rehype-syntax-highlight as an independent package and override configs using old styles.

@swwind swwind closed this Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[✨] Add extra syntax highlighters via. MDX config
2 participants