Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
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
Unverified
Commit
6fb312cc
authored
Jun 20, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
link text
parent
31663761
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
client/src/components/Markdown/Link.tsx
+4
-3
No files found.
client/src/components/Markdown/Link.tsx
View file @
6fb312cc
...
...
@@ -3,12 +3,13 @@ import { Box } from '@chakra-ui/react';
const
regex
=
/
((
http|https|ftp
)
:
\/\/[^\s\u
4e00-
\u
9fa5
\u
3000-
\u
303f
\u
ff00-
\u
ffef
]
+
)
/gi
;
const
Link
=
(
{
href
}:
{
href
?:
string
})
=>
{
const
decText
=
decodeURIComponent
(
href
||
''
);
const
Link
=
(
props
:
{
href
?:
string
;
children
?:
React
.
ReactNode
[]
})
=>
{
const
decText
=
decodeURIComponent
(
props
.
href
||
''
);
const
replaceText
=
decText
.
replace
(
regex
,
(
match
,
p1
)
=>
{
const
text
=
decText
===
props
.
children
?.[
0
]
?
p1
:
props
.
children
?.[
0
];
const
isInternal
=
/^
\/
#/i
.
test
(
p1
);
const
target
=
isInternal
?
'_self'
:
'_blank'
;
return
`<a href="
${
p1
}
" target=
${
target
}
>
${
p1
}
</a>`
;
return
`<a href="
${
p1
}
" target=
${
target
}
>
${
text
}
</a>`
;
});
return
<
Box
as=
{
'span'
}
dangerouslySetInnerHTML=
{
{
__html
:
replaceText
}
}
/>;
...
...
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