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

Need Prettier Support #42

Open
jazimabbas opened this issue Apr 9, 2024 · 2 comments
Open

Need Prettier Support #42

jazimabbas opened this issue Apr 9, 2024 · 2 comments

Comments

@jazimabbas
Copy link

jazimabbas commented Apr 9, 2024

I want to format the code using the Prettier API. I am using Next.js Server Component. I am trying to implement it within the beforeHighlight function in the extensions hook. However, the issue arises because the Prettier format function returns a promise, whereas beforeHighlight does not expect a promise.
How can I resolve this problem? I prefer not to place the Prettier logic in the client component. Can anyone please assist me with this?

Isn't nice if somehow beforeHighlight function resolve the promise, then the problem would be solved very easily.

@pomber
Copy link
Contributor

pomber commented Apr 9, 2024

maybe wrap it in your own server component?

import { Code } from "bright"

async function MyCode(props) {
  const newProps = await format(props)
  return <Code {...newProps} />
}

@jazimabbas
Copy link
Author

I am trying to add Tabs. So this is the code I wrote:

async function TabContent(props) {
  const formattedCode = await format(props.code, props.lang);
  return <Code.Pre {...props} code={formattedCode} />
}

If I console log the formattedCode, I'm getting the correct formatting but it is showing the unformatted code in the browser. Am I missing something ??

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

No branches or pull requests

2 participants