Skip to content

Commit de12642

Browse files
committed
feat: add html syntax highlighter in code renderer
1 parent f35aac3 commit de12642

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@assistant-ui/react-markdown": "^0.2.18",
1818
"@assistant-ui/react-syntax-highlighter": "^0.0.13",
1919
"@codemirror/lang-cpp": "^6.0.2",
20+
"@codemirror/lang-html": "^6.4.9",
2021
"@codemirror/lang-java": "^6.0.1",
2122
"@codemirror/lang-javascript": "^6.2.2",
2223
"@codemirror/lang-php": "^6.0.1",

src/components/artifacts/CodeRenderer.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import { cpp } from "@codemirror/lang-cpp";
66
import { java } from "@codemirror/lang-java";
77
import { php } from "@codemirror/lang-php";
88
import { python } from "@codemirror/lang-python";
9-
109
import styles from "./CodeRenderer.module.css";
1110
import { cleanContent } from "@/lib/normalize_string";
11+
import { html } from "@codemirror/lang-html";
1212

1313
export interface CodeRendererProps {
1414
artifact: Artifact;
1515
setArtifactContent: (id: string, content: string) => void;
1616
editorRef: MutableRefObject<EditorView | null>;
1717
}
1818

19-
export function CodeRenderer(props: CodeRendererProps) {
19+
export function CodeRenderer(props: Readonly<CodeRendererProps>) {
2020
let extensions: any[] = [];
2121
if (props.artifact.language === "javascript") {
2222
extensions = [javascript({ jsx: true, typescript: false })];
@@ -30,6 +30,8 @@ export function CodeRenderer(props: CodeRendererProps) {
3030
extensions = [php()];
3131
} else if (props.artifact.language === "python") {
3232
extensions = [python()];
33+
} else if (props.artifact.language === "html") {
34+
extensions = [html()];
3335
}
3436

3537
if (!props.artifact.content) {

yarn.lock

+19-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"@lezer/common" "^1.0.2"
124124
"@lezer/css" "^1.1.7"
125125

126-
"@codemirror/lang-html@^6.0.0":
126+
"@codemirror/lang-html@^6.0.0", "@codemirror/lang-html@^6.4.9":
127127
version "6.4.9"
128128
resolved "https://registry.yarnpkg.com/@codemirror/lang-html/-/lang-html-6.4.9.tgz#d586f2cc9c341391ae07d1d7c545990dfa069727"
129129
integrity sha512-aQv37pIMSlueybId/2PVSP6NPnmurFDVmZwzc7jszd2KAF8qd4VBbvNYPXWQq90WIARjsdVkPbw29pszmHws3Q==
@@ -5428,8 +5428,16 @@ streamsearch@^1.1.0:
54285428
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
54295429
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
54305430

5431-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
5432-
name string-width-cjs
5431+
"string-width-cjs@npm:string-width@^4.2.0":
5432+
version "4.2.3"
5433+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
5434+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
5435+
dependencies:
5436+
emoji-regex "^8.0.0"
5437+
is-fullwidth-code-point "^3.0.0"
5438+
strip-ansi "^6.0.1"
5439+
5440+
string-width@^4.1.0:
54335441
version "4.2.3"
54345442
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
54355443
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -5517,7 +5525,14 @@ stringify-entities@^4.0.0:
55175525
character-entities-html4 "^2.0.0"
55185526
character-entities-legacy "^3.0.0"
55195527

5520-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
5528+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
5529+
version "6.0.1"
5530+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
5531+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
5532+
dependencies:
5533+
ansi-regex "^5.0.1"
5534+
5535+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
55215536
version "6.0.1"
55225537
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
55235538
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==

0 commit comments

Comments
 (0)