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
cc9edfff
Unverified
Commit
cc9edfff
authored
Sep 04, 2023
by
Joel
Committed by
GitHub
Sep 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: markdown code lang capitalization and line number color (#1098)
parent
6fa2454c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
markdown.tsx
web/app/components/base/markdown.tsx
+20
-16
markdown.scss
web/app/styles/markdown.scss
+4
-0
No files found.
web/app/components/base/markdown.tsx
View file @
cc9edfff
...
...
@@ -10,17 +10,26 @@ 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
// Available language https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD
const
capitalizationLanguageNameMap
:
Record
<
string
,
string
>
=
{
sql
:
'SQL'
,
javascript
:
'JavaScript'
,
typescript
:
'TypeScript'
,
vbscript
:
'VBScript'
,
css
:
'CSS'
,
html
:
'HTML'
,
xml
:
'XML'
,
php
:
'PHP'
,
}
const
getCorrectCapitalizationLanguageName
=
(
language
:
string
)
=>
{
if
(
!
language
)
return
'Plain'
// 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
// })
// }
if
(
language
in
capitalizationLanguageNameMap
)
return
capitalizationLanguageNameMap
[
language
]
return
language
.
charAt
(
0
).
toUpperCase
()
+
language
.
substring
(
1
)
}
export
function
PreCode
(
props
:
{
children
:
any
})
{
const
ref
=
useRef
<
HTMLPreElement
>
(
null
)
...
...
@@ -75,12 +84,7 @@ export function Markdown(props: { content: string }) {
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'
})()
const
languageShowName
=
getCorrectCapitalizationLanguageName
(
language
||
''
)
return
(
!
inline
&&
match
)
?
(
<
div
>
...
...
web/app/styles/markdown.scss
View file @
cc9edfff
...
...
@@ -1047,3 +1047,7 @@
.
markdown-body
:
:-
webkit-calendar-picker-indicator
{
filter
:
invert
(
50%
);
}
.markdown-body
.react-syntax-highlighter-line-number
{
color
:
#D0D5DD
;
}
\ No newline at end of file
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