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

Fix support for asynchronous plugins in rehypePlugins #670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vishwamartur
Copy link

Related to #662

Refactor Markdown component to support asynchronous plugins.

  • Markdown Component (core/src/components/TextArea/Markdown.tsx)

    • Import useState from React.
    • Add mdStr state to manage the processed markdown string.
    • Refactor useEffect to handle asynchronous processing of markdown using rehype().process.
    • Update the return statement to use mdStr state.
  • Example Component (www/src/Example.tsx)

    • Import rehypePrettyCode.
    • Add rehypePrettyCode to previewOptions.rehypePlugins.
  • Tests (test/editor.test.tsx)

    • Add a test to verify that MDEditor supports asynchronous plugins.
    • Use an example async plugin that adds a class to the first node.
    • Verify that the class is added to the preview node after processing.

Related to uiwjs#662

Refactor `Markdown` component to support asynchronous plugins.

* **Markdown Component (`core/src/components/TextArea/Markdown.tsx`)**
  - Import `useState` from React.
  - Add `mdStr` state to manage the processed markdown string.
  - Refactor `useEffect` to handle asynchronous processing of markdown using `rehype().process`.
  - Update the return statement to use `mdStr` state.

* **Example Component (`www/src/Example.tsx`)**
  - Import `rehypePrettyCode`.
  - Add `rehypePrettyCode` to `previewOptions.rehypePlugins`.

* **Tests (`test/editor.test.tsx`)**
  - Add a test to verify that `MDEditor` supports asynchronous plugins.
  - Use an example async plugin that adds a class to the first node.
  - Verify that the class is added to the preview node after processing.
Copy link

vercel bot commented Nov 1, 2024

@vishwamartur is attempting to deploy a commit to the kenny wong's projects Team on Vercel.

A member of the Team first needs to authorize it.

// https://github.com/uiwjs/react-md-editor/issues/593
// @ts-ignore
.use(rehypePrism, { ignoreMissing: true })
.process(mdStr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

An error occurred in the example. @vishwamartur

@@ -1,5 +1,6 @@
import React, { Fragment } from 'react';
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
import rehypePrettyCode from 'rehype-pretty-code';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rehype-pretty-code dependency is not included in package.json. @vishwamartur

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.

2 participants