Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
10976844
authored
Jan 30, 2026
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: CodeViewer click link and auto wrap
parent
d7c55b92
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletions
+23
-1
web/src/components/playground/CodeViewer.jsx
+23
-1
No files found.
web/src/components/playground/CodeViewer.jsx
View file @
10976844
...
@@ -106,6 +106,22 @@ const highlightJson = (str) => {
...
@@ -106,6 +106,22 @@ const highlightJson = (str) => {
);
);
};
};
const
linkRegex
=
/
(
https
?
:
\/\/[^\s
<"'
\]
),;}
]
+
)
/g
;
const
linkifyHtml
=
(
html
)
=>
{
const
parts
=
html
.
split
(
/
(
<
[^
>
]
+>
)
/g
);
return
parts
.
map
((
part
)
=>
{
if
(
part
.
startsWith
(
'<'
))
return
part
;
return
part
.
replace
(
linkRegex
,
(
url
)
=>
`<a href="
${
url
}
" target="_blank" rel="noreferrer">
${
url
}
</a>`
,
);
})
.
join
(
''
);
};
const
isJsonLike
=
(
content
,
language
)
=>
{
const
isJsonLike
=
(
content
,
language
)
=>
{
if
(
language
===
'json'
)
return
true
;
if
(
language
===
'json'
)
return
true
;
const
trimmed
=
content
.
trim
();
const
trimmed
=
content
.
trim
();
...
@@ -179,6 +195,10 @@ const CodeViewer = ({ content, title, language = 'json' }) => {
...
@@ -179,6 +195,10 @@ const CodeViewer = ({ content, title, language = 'json' }) => {
return
displayContent
;
return
displayContent
;
},
[
displayContent
,
language
,
contentMetrics
.
isVeryLarge
,
isExpanded
]);
},
[
displayContent
,
language
,
contentMetrics
.
isVeryLarge
,
isExpanded
]);
const
renderedContent
=
useMemo
(()
=>
{
return
linkifyHtml
(
highlightedContent
);
},
[
highlightedContent
]);
const
handleCopy
=
useCallback
(
async
()
=>
{
const
handleCopy
=
useCallback
(
async
()
=>
{
try
{
try
{
const
textToCopy
=
const
textToCopy
=
...
@@ -276,6 +296,8 @@ const CodeViewer = ({ content, title, language = 'json' }) => {
...
@@ -276,6 +296,8 @@ const CodeViewer = ({ content, title, language = 'json' }) => {
style=
{
{
style=
{
{
...
codeThemeStyles
.
content
,
...
codeThemeStyles
.
content
,
paddingTop
:
contentPadding
,
paddingTop
:
contentPadding
,
whiteSpace
:
'pre-wrap'
,
wordBreak
:
'break-word'
,
}
}
}
}
className=
'model-settings-scroll'
className=
'model-settings-scroll'
>
>
...
@@ -303,7 +325,7 @@ const CodeViewer = ({ content, title, language = 'json' }) => {
...
@@ -303,7 +325,7 @@ const CodeViewer = ({ content, title, language = 'json' }) => {
{
t
(
'正在处理大内容...'
)
}
{
t
(
'正在处理大内容...'
)
}
</
div
>
</
div
>
)
:
(
)
:
(
<
div
dangerouslySetInnerHTML=
{
{
__html
:
highlight
edContent
}
}
/>
<
div
dangerouslySetInnerHTML=
{
{
__html
:
render
edContent
}
}
/>
)
}
)
}
</
div
>
</
div
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment