-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Is your feature request related to a problem? Please describe.
Right now, there seem to be code highlighting for the <Code />
component only for javascript, json, jsx and typescript. I'm using it as a preview component for the Studio, and I pass in the selected language in parameter (for example, "tsx" or "sh") but I can't get highlighting to work, even if I try registerLanguage
myself.
Describe the solution you'd like
It would be nice to be able to support other languages
Describe alternatives you've considered
This is a shortened version of what I'm trying, just to illustrate the problem, but it doesn't work:
import { Stack, Code } from "@sanity/ui";
import { registerLanguage } from "react-refractor";
import tsx from "refractor/lang/tsx";
registerLanguage(tsx);
const Preview = (props) => {
return (
<Stack>
{props.renderDefault(props)}
<Code language={props.language}>{props.code}</Code>
</Stack>
);
};
const schema = defineType({
// ...
preview: {
select: {
code: "code",
language: "language",
},
},
components: {
preview: Preview,
},
});
Additional context
This is what the editor looks like. I've logged the props and the "language" is correctly set to "tsx", but there's no highlight.
It might be worth noting that I have both refractor
and react-refractor
listed as dependencies because I use it differently in my frontend.