Skip to content

Commit 639827c

Browse files
committed
feat: improved syntax highlighting
1 parent d322aa0 commit 639827c

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

src/components/detailedRequest/index.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { useEffect } from 'react';
3+
import React, { useEffect, useRef } from 'react';
44
import Prism from 'prismjs';
55
import 'prismjs/themes/prism-dark.css';
66
import 'prismjs/components/prism-http';
@@ -18,8 +18,12 @@ interface DetailedRequestP {
1818
}
1919

2020
const DetailedRequest = ({ title, data, view, protocol }: DetailedRequestP) => {
21+
const codeRef = useRef<HTMLElement>(null);
22+
2123
useEffect(() => {
22-
Prism.highlightAll();
24+
if (codeRef.current) {
25+
Prism.highlightElement(codeRef.current);
26+
}
2327
}, [data]);
2428

2529
return (
@@ -36,21 +40,10 @@ const DetailedRequest = ({ title, data, view, protocol }: DetailedRequestP) => {
3640
Copy <CopyIcon />
3741
</button>
3842
<div className="pre_wrapper">
39-
<pre className={`${
40-
protocol === 'http'
41-
? 'language-http'
42-
: protocol === 'dns'
43-
? 'default'
44-
: protocol === 'smtp' && 'default'
45-
}`}>
43+
<pre className={protocol === 'http' ? 'language-http' : 'default'}>
4644
<code
47-
className={`${
48-
protocol === 'http'
49-
? 'language-http'
50-
: protocol === 'dns'
51-
? 'default'
52-
: protocol === 'smtp' && 'default'
53-
}`}
45+
ref={codeRef}
46+
className={protocol === 'http' ? 'language-http' : 'default'}
5447
>
5548
{data}
5649
</code>

0 commit comments

Comments
 (0)