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
7d324c18
Commit
7d324c18
authored
Jul 26, 2023
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: highlightURL problem
parent
444f035f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
markdown.tsx
web/app/components/base/markdown.tsx
+9
-5
No files found.
web/app/components/base/markdown.tsx
View file @
7d324c18
...
...
@@ -10,11 +10,15 @@ import type { RefObject } from 'react'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
// 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
//
const urlRegex = /\b((https?|ftp|file):\/\/|(www|ftp)\.)[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/ig
function
highlightURL
(
content
:
string
)
{
return
content
.
replace
(
urlRegex
,
'[$&]($&)'
)
}
// function highlightURL(content: string) {
// return content.replace(urlRegex, (url) => {
// // fix http:// in [] will be parsed to link agin
// const res = `[${url.replace('://', '://')}](${url})`
// return res
// })
// }
export
function
PreCode
(
props
:
{
children
:
any
})
{
const
ref
=
useRef
<
HTMLPreElement
>
(
null
)
...
...
@@ -88,7 +92,7 @@ export function Markdown(props: { content: string }) {
linkTarget=
{
'_blank'
}
>
{
/* Markdown detect has problem. */
}
{
highlightURL
(
props
.
content
)
}
{
props
.
content
}
</
ReactMarkdown
>
</
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