From c556083940b58755630c507b4bb90c93c6ecffbf Mon Sep 17 00:00:00 2001 From: Sudaraka Jayathilaka Date: Wed, 1 May 2024 00:40:14 +0800 Subject: [PATCH] fix(java-syntax-highlighting): Fix Java syntax highlighting --- src/components/Code/Code.Prism.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/Code/Code.Prism.tsx b/src/components/Code/Code.Prism.tsx index b6e7e9e..15b3c0b 100644 --- a/src/components/Code/Code.Prism.tsx +++ b/src/components/Code/Code.Prism.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { Highlight, defaultProps, Language, themes } from 'prism-react-renderer' +import { Highlight, themes, Prism } from 'prism-react-renderer' import styled from "@emotion/styled"; import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live"; @@ -42,8 +42,14 @@ const Copy: React.FC = ({ toCopy }) => { const RE = /{([\d,-]+)}/; +const loadCustomLanguages = () => { + (typeof global !== "undefined" ? global : window).Prism = Prism + require("prismjs/components/prism-java") +} + const CodePrism: React.FC = (props) => { + loadCustomLanguages(); const { props: { className, children: codeString, metastring } } = props.children; if (props["live"]) { return (