Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
e34dcc04
Unverified
Commit
e34dcc04
authored
Aug 30, 2023
by
Joel
Committed by
GitHub
Aug 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: code support copy (#1057)
parent
a834ba87
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
13 deletions
+50
-13
index.tsx
web/app/components/app/chat/copy-btn/index.tsx
+9
-5
markdown.tsx
web/app/components/base/markdown.tsx
+37
-8
markdown.scss
web/app/styles/markdown.scss
+4
-0
No files found.
web/app/components/app/chat/copy-btn/index.tsx
View file @
e34dcc04
...
...
@@ -8,32 +8,36 @@ import Tooltip from '@/app/components/base/tooltip'
type
ICopyBtnProps
=
{
value
:
string
className
?:
string
isPlain
?:
boolean
}
const
CopyBtn
=
({
value
,
className
,
isPlain
,
}:
ICopyBtnProps
)
=>
{
const
[
isCopied
,
setIsCopied
]
=
React
.
useState
(
false
)
return
(
<
div
className=
{
`${className}`
}
>
<
Tooltip
selector=
"copy-btn-tooltip"
selector=
{
`copy-btn-tooltip-${value}`
}
content=
{
(
isCopied
?
t
(
'appApi.copied'
)
:
t
(
'appApi.copy'
))
as
string
}
className=
'z-10'
>
<
div
className=
{
'box-border p-0.5 flex items-center justify-center rounded-md bg-white cursor-pointer'
}
style=
{
{
boxShadow
:
'0px 4px 8px -2px rgba(16, 24, 40, 0.1), 0px 2px 4px -2px rgba(16, 24, 40, 0.06)'
,
}
}
style=
{
!
isPlain
?
{
boxShadow
:
'0px 4px 8px -2px rgba(16, 24, 40, 0.1), 0px 2px 4px -2px rgba(16, 24, 40, 0.06)'
,
}
:
{}
}
onClick=
{
()
=>
{
copy
(
value
)
setIsCopied
(
true
)
}
}
>
<
div
className=
{
`w-6 h-6 hover:bg-gray-50 ${s.copyIcon} ${isCopied ? s.copied : ''}`
}
></
div
>
<
div
className=
{
`w-6 h-6
rounded-md
hover:bg-gray-50 ${s.copyIcon} ${isCopied ? s.copied : ''}`
}
></
div
>
</
div
>
</
Tooltip
>
</
div
>
...
...
web/app/components/base/markdown.tsx
View file @
e34dcc04
...
...
@@ -8,6 +8,8 @@ import SyntaxHighlighter from 'react-syntax-highlighter'
import
{
atelierHeathLight
}
from
'react-syntax-highlighter/dist/esm/styles/hljs'
import
type
{
RefObject
}
from
'react'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
CopyBtn
from
'@/app/components/app/chat/copy-btn'
// import { copyToClipboard } from "../utils";
// https://txtfiddle.com/~hlshwya/extract-urls-from-text
// const urlRegex = /\b((https?|ftp|file):\/\/|(www|ftp)\.)[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/ig
...
...
@@ -61,6 +63,7 @@ const useLazyLoad = (ref: RefObject<Element>): boolean => {
}
export
function
Markdown
(
props
:
{
content
:
string
})
{
const
[
isCopied
,
setIsCopied
]
=
useState
(
false
)
return
(
<
div
className=
"markdown-body"
>
<
ReactMarkdown
...
...
@@ -71,16 +74,42 @@ export function Markdown(props: { content: string }) {
components=
{
{
code
({
node
,
inline
,
className
,
children
,
...
props
})
{
const
match
=
/language-
(\w
+
)
/
.
exec
(
className
||
''
)
const
language
=
match
?.[
1
]
const
languageShowName
=
(()
=>
{
if
(
language
)
return
language
.
charAt
(
0
).
toUpperCase
()
+
language
.
substring
(
1
)
return
'Plain'
})()
return
(
!
inline
&&
match
)
?
(
<
SyntaxHighlighter
{
...
props
}
children=
{
String
(
children
).
replace
(
/
\n
$/
,
''
)
}
style=
{
atelierHeathLight
}
language=
{
match
[
1
]
}
showLineNumbers
PreTag=
"div"
/>
<
div
>
<
div
className=
'flex justify-between h-8 items-center p-1 pl-3 border-b'
style=
{
{
borderColor
:
'rgba(0, 0, 0, 0.05)'
,
}
}
>
<
div
className=
'text-[13px] text-gray-500 font-normal'
>
{
languageShowName
}
</
div
>
<
CopyBtn
value=
{
String
(
children
).
replace
(
/
\n
$/
,
''
)
}
isPlain
/>
</
div
>
<
SyntaxHighlighter
{
...
props
}
style=
{
atelierHeathLight
}
customStyle=
{
{
paddingLeft
:
12
,
backgroundColor
:
'#fff'
,
}
}
language=
{
match
[
1
]
}
showLineNumbers
PreTag=
"div"
>
{
String
(
children
).
replace
(
/
\n
$/
,
''
)
}
</
SyntaxHighlighter
>
</
div
>
)
:
(
<
code
{
...
props
}
className=
{
className
}
>
...
...
web/app/styles/markdown.scss
View file @
e34dcc04
...
...
@@ -774,6 +774,10 @@
border-radius
:
6px
;
}
.markdown-body
pre
{
padding
:
0
;
}
.markdown-body
pre
code
,
.markdown-body
pre
tt
{
display
:
inline-block
;
...
...
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