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
9be4b804
Commit
9be4b804
authored
Jul 25, 2023
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: markdown url parse error
parent
e7b5695b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
42 deletions
+48
-42
index.tsx
web/app/components/app/chat/thought/index.tsx
+0
-2
markdown.tsx
web/app/components/base/markdown.tsx
+48
-40
No files found.
web/app/components/app/chat/thought/index.tsx
View file @
9be4b804
...
@@ -9,8 +9,6 @@ import { DataSet as DataSetIcon, Loading as LodingIcon, Search, ThoughtList, Web
...
@@ -9,8 +9,6 @@ import { DataSet as DataSetIcon, Loading as LodingIcon, Search, ThoughtList, Web
import
{
ChevronDown
}
from
'@/app/components/base/icons/src/vender/line/arrows'
import
{
ChevronDown
}
from
'@/app/components/base/icons/src/vender/line/arrows'
import
type
{
DataSet
}
from
'@/models/datasets'
import
type
{
DataSet
}
from
'@/models/datasets'
// https://www.freecodecamp.org/news/how-to-write-a-regular-expression-for-a-url/
const
urlRegex
=
/
(
https:
\/\/
www
\.
|http:
\/\/
www
\.
|https:
\/\/
|http:
\/\/)?[
a-zA-Z
]{2,}(\.[
a-zA-Z
]{2,})(\.[
a-zA-Z
]{2,})?\/[
a-zA-Z0-9
]{2,}
|
((
https:
\/\/
www
\.
|http:
\/\/
www
\.
|https:
\/\/
|http:
\/\/)?[
a-zA-Z
]{2,}(\.[
a-zA-Z
]{2,})(\.[
a-zA-Z
]{2,})?)
|
(
https:
\/\/
www
\.
|http:
\/\/
www
\.
|https:
\/\/
|http:
\/\/)?[
a-zA-Z0-9
]{2,}\.[
a-zA-Z0-9
]{2,}\.[
a-zA-Z0-9
]{2,}(\.[
a-zA-Z0-9
]{2,})?
/gi
export
type
IThoughtProps
=
{
export
type
IThoughtProps
=
{
list
:
ThoughtItem
[]
list
:
ThoughtItem
[]
isThinking
?:
boolean
isThinking
?:
boolean
...
...
web/app/components/base/markdown.tsx
View file @
9be4b804
import
ReactMarkdown
from
"react-markdown"
;
import
ReactMarkdown
from
'react-markdown'
import
"katex/dist/katex.min.css"
;
import
'katex/dist/katex.min.css'
import
RemarkMath
from
"remark-math"
;
import
RemarkMath
from
'remark-math'
import
RemarkBreaks
from
"remark-breaks"
;
import
RemarkBreaks
from
'remark-breaks'
import
RehypeKatex
from
"rehype-katex"
;
import
RehypeKatex
from
'rehype-katex'
import
RemarkGfm
from
"remark-gfm"
;
import
RemarkGfm
from
'remark-gfm'
import
SyntaxHighlighter
from
'react-syntax-highlighter'
import
SyntaxHighlighter
from
'react-syntax-highlighter'
import
{
atelierHeathLight
}
from
'react-syntax-highlighter/dist/esm/styles/hljs'
import
{
atelierHeathLight
}
from
'react-syntax-highlighter/dist/esm/styles/hljs'
import
{
useRef
,
useState
,
RefObject
,
useEffect
}
from
"react"
;
import
type
{
RefObject
}
from
'react'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
// import { copyToClipboard } from "../utils";
// 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
function
highlightURL
(
content
:
string
)
{
return
content
.
replace
(
urlRegex
,
'[$&]($&)'
)
}
export
function
PreCode
(
props
:
{
children
:
any
})
{
export
function
PreCode
(
props
:
{
children
:
any
})
{
const
ref
=
useRef
<
HTMLPreElement
>
(
null
)
;
const
ref
=
useRef
<
HTMLPreElement
>
(
null
)
return
(
return
(
<
pre
ref=
{
ref
}
>
<
pre
ref=
{
ref
}
>
...
@@ -18,38 +24,37 @@ export function PreCode(props: { children: any }) {
...
@@ -18,38 +24,37 @@ export function PreCode(props: { children: any }) {
className=
"copy-code-button"
className=
"copy-code-button"
onClick=
{
()
=>
{
onClick=
{
()
=>
{
if
(
ref
.
current
)
{
if
(
ref
.
current
)
{
const
code
=
ref
.
current
.
innerText
;
const
code
=
ref
.
current
.
innerText
// copyToClipboard(code);
// copyToClipboard(code);
}
}
}
}
}
}
></
span
>
></
span
>
{
props
.
children
}
{
props
.
children
}
</
pre
>
</
pre
>
)
;
)
}
}
const
useLazyLoad
=
(
ref
:
RefObject
<
Element
>
):
boolean
=>
{
const
useLazyLoad
=
(
ref
:
RefObject
<
Element
>
):
boolean
=>
{
const
[
isIntersecting
,
setIntersecting
]
=
useState
<
boolean
>
(
false
)
;
const
[
isIntersecting
,
setIntersecting
]
=
useState
<
boolean
>
(
false
)
useEffect
(()
=>
{
useEffect
(()
=>
{
const
observer
=
new
IntersectionObserver
(([
entry
])
=>
{
const
observer
=
new
IntersectionObserver
(([
entry
])
=>
{
if
(
entry
.
isIntersecting
)
{
if
(
entry
.
isIntersecting
)
{
setIntersecting
(
true
)
;
setIntersecting
(
true
)
observer
.
disconnect
()
;
observer
.
disconnect
()
}
}
})
;
})
if
(
ref
.
current
)
{
if
(
ref
.
current
)
observer
.
observe
(
ref
.
current
);
observer
.
observe
(
ref
.
current
)
}
return
()
=>
{
return
()
=>
{
observer
.
disconnect
()
;
observer
.
disconnect
()
}
;
}
},
[
ref
])
;
},
[
ref
])
return
isIntersecting
;
return
isIntersecting
}
;
}
export
function
Markdown
(
props
:
{
content
:
string
})
{
export
function
Markdown
(
props
:
{
content
:
string
})
{
return
(
return
(
...
@@ -62,7 +67,8 @@ export function Markdown(props: { content: string }) {
...
@@ -62,7 +67,8 @@ export function Markdown(props: { content: string }) {
components=
{
{
components=
{
{
code
({
node
,
inline
,
className
,
children
,
...
props
})
{
code
({
node
,
inline
,
className
,
children
,
...
props
})
{
const
match
=
/language-
(\w
+
)
/
.
exec
(
className
||
''
)
const
match
=
/language-
(\w
+
)
/
.
exec
(
className
||
''
)
return
!
inline
&&
match
?
(
return
(
!
inline
&&
match
)
?
(
<
SyntaxHighlighter
<
SyntaxHighlighter
{
...
props
}
{
...
props
}
children=
{
String
(
children
).
replace
(
/
\n
$/
,
''
)
}
children=
{
String
(
children
).
replace
(
/
\n
$/
,
''
)
}
...
@@ -71,17 +77,19 @@ export function Markdown(props: { content: string }) {
...
@@ -71,17 +77,19 @@ export function Markdown(props: { content: string }) {
showLineNumbers
showLineNumbers
PreTag=
"div"
PreTag=
"div"
/>
/>
)
:
(
)
:
(
<
code
{
...
props
}
className=
{
className
}
>
<
code
{
...
props
}
className=
{
className
}
>
{
children
}
{
children
}
</
code
>
</
code
>
)
)
}
}
,
}
}
}
}
linkTarget=
{
"_blank"
}
linkTarget=
{
'_blank'
}
>
>
{
props
.
content
}
{
/* Markdown detect has problem. */
}
{
highlightURL
(
props
.
content
)
}
</
ReactMarkdown
>
</
ReactMarkdown
>
</
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