shikijs / shiki

A beautiful yet powerful syntax highlighter

Home Page:http://shiki.style/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to highlight code synchronously without top-level await being available?

xsjcTony opened this issue · comments

Clear and concise description of the problem

I'm using React, hence I need to synchronously highlight the code and use dangerouslySetInnerHTML to inject the content.
However, using async in React environment is a bit hard.
I tried to create a highlighter instance to highlight code synchronously in my local and it worked well, however it's not supported in the production environment, due to the browser version as required:
image
Any way I can use the synchronous way without top-level await being available?
I need to use it fully synchronously, but seems either shorthand needs to be async, or getHighlighter needs to be async. I know we are dynamically loading modules, but I wonder whether we have any solution to this.

Suggested solution

This is a Question as no discussion is available

Alternative

No response

Additional context

No response

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue

I'd wish to, but no. It's how JS works, you can't workaround it.