Add syntax highlighting support to MessageBubble component with rehype-highlight and highlight.js

This commit is contained in:
ecwu
2025-02-07 21:52:09 +00:00
parent 8db892caf7
commit 8d4a9b840a
5 changed files with 125 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import { LightBulbIcon, XMarkIcon } from "@heroicons/react/24/outline";
import Markdown from "react-markdown";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import rehypeHighlight from "rehype-highlight";
import "katex/dist/katex.min.css";
import {
useContext,
@@ -338,7 +339,7 @@ export default function Message(props: { messageIndex: number }) {
) : renderMarkdown ? (
<Markdown
remarkPlugins={[remarkMath]}
rehypePlugins={[rehypeKatex]}
rehypePlugins={[rehypeKatex, rehypeHighlight]}
disallowedElements={[
"script",
"iframe",