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
d4d9e1fe
authored
Aug 14, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: markdonw link
parent
0d702202
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 additions
and
34 deletions
+1
-34
client/src/components/Markdown/Link.tsx
+0
-32
client/src/components/Markdown/index.tsx
+1
-2
No files found.
client/src/components/Markdown/Link.tsx
deleted
100644 → 0
View file @
0d702202
import
React
,
{
useMemo
}
from
'react'
;
import
{
Box
}
from
'@chakra-ui/react'
;
import
Image
from
'./img/Image'
;
const
regex
=
/
((
http|https|ftp
)
:
\/\/[^\s\u
4e00-
\u
9fa5
\u
3000-
\u
303f
\u
ff00-
\u
ffef
]
+
)
/gi
;
const
Link
=
(
props
:
{
href
?:
string
;
children
?:
any
})
=>
{
const
Html
=
useMemo
(()
=>
{
const
decText
=
decodeURIComponent
(
props
.
href
||
''
);
return
decText
.
replace
(
regex
,
(
match
,
p1
)
=>
{
let
text
=
decText
===
props
.
children
?.[
0
]
?
p1
:
props
.
children
?.[
0
];
const
isInternal
=
/^
\/
#/i
.
test
(
p1
);
const
target
=
isInternal
?
'_self'
:
'_blank'
;
if
(
props
?.
children
?.[
0
]?.
props
?.
node
?.
tagName
===
'img'
)
{
// eslint-disable-next-line @next/next/no-img-element
text
=
`<img src="
${
props
?.
children
?.[
0
]?.
props
?.
src
}
" />`;
}
return `<a href="
$
{
p1
}
"
target
=
$
{
target
}
>
$
{
text
}<
/
a
>
`;
});
}, [props.children, props.href]);
return typeof Html === 'string' ? (
<
Box
as=
{
'span'
}
dangerouslySetInnerHTML=
{
{
__html
:
Html
}
}
/>
) : (
Html
);
};
export default React.memo(Link);
client/src/components/Markdown/index.tsx
View file @
d4d9e1fe
...
...
@@ -9,7 +9,6 @@ import 'katex/dist/katex.min.css';
import
styles
from
'./index.module.scss'
;
import
dynamic
from
'next/dynamic'
;
import
Link
from
'./Link'
;
import
CodeLight
from
'./CodeLight'
;
const
MermaidCodeBlock
=
dynamic
(()
=>
import
(
'./img/MermaidCodeBlock'
));
...
...
@@ -50,7 +49,6 @@ const Markdown = ({
})
=>
{
const
components
=
useMemo
(
()
=>
({
a
:
Link
,
img
:
Image
,
pre
:
'div'
,
p
:
'div'
,
...
...
@@ -68,6 +66,7 @@ const Markdown = ({
rehypePlugins=
{
[
RehypeKatex
]
}
// @ts-ignore
components=
{
components
}
linkTarget=
{
'_blank'
}
>
{
source
}
</
ReactMarkdown
>
...
...
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