Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
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
Vũ Hoàng Anh
canifa_note
Commits
03d67d5a
Unverified
Commit
03d67d5a
authored
Feb 19, 2024
by
Kristián
Committed by
GitHub
Feb 19, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add mermaid support in codeblock (#2971)
parent
a86117f6
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
911 additions
and
7 deletions
+911
-7
docker-compose.dev.yaml
scripts/docker-compose.dev.yaml
+1
-0
package.json
web/package.json
+3
-0
pnpm-lock.yaml
web/pnpm-lock.yaml
+869
-7
App.tsx
web/src/App.tsx
+3
-0
CodeBlock.tsx
web/src/components/MemoContent/CodeBlock.tsx
+8
-0
MermaidBlock.tsx
web/src/components/MemoContent/MermaidBlock.tsx
+27
-0
No files found.
scripts/docker-compose.dev.yaml
View file @
03d67d5a
...
@@ -62,6 +62,7 @@ services:
...
@@ -62,6 +62,7 @@ services:
-
pnpm-store:/work/web/.pnpm-store
-
pnpm-store:/work/web/.pnpm-store
-
../proto:/work/proto
-
../proto:/work/proto
-
../web:/work/web
-
../web:/work/web
-
../web/node_modules:/work/web/node_modules
healthcheck
:
healthcheck
:
test
:
[
"
CMD"
,
"
wget"
,
"
-qO"
,
"
-"
,
"
http://localhost:3001"
]
test
:
[
"
CMD"
,
"
wget"
,
"
-qO"
,
"
-"
,
"
http://localhost:3001"
]
interval
:
10s
interval
:
10s
...
...
web/package.json
View file @
03d67d5a
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
"katex"
:
"^0.16.9"
,
"katex"
:
"^0.16.9"
,
"lodash-es"
:
"^4.17.21"
,
"lodash-es"
:
"^4.17.21"
,
"lucide-react"
:
"^0.309.0"
,
"lucide-react"
:
"^0.309.0"
,
"mermaid"
:
"^10.8.0"
,
"react"
:
"^18.2.0"
,
"react"
:
"^18.2.0"
,
"react-dom"
:
"^18.2.0"
,
"react-dom"
:
"^18.2.0"
,
"react-hot-toast"
:
"^2.4.1"
,
"react-hot-toast"
:
"^2.4.1"
,
...
@@ -38,6 +39,8 @@
...
@@ -38,6 +39,8 @@
"devDependencies"
:
{
"devDependencies"
:
{
"@bufbuild/buf"
:
"^1.29.0"
,
"@bufbuild/buf"
:
"^1.29.0"
,
"@trivago/prettier-plugin-sort-imports"
:
"^4.3.0"
,
"@trivago/prettier-plugin-sort-imports"
:
"^4.3.0"
,
"@types/d3"
:
"^7.4.3"
,
"@types/dompurify"
:
"^3.0.5"
,
"@types/katex"
:
"^0.16.7"
,
"@types/katex"
:
"^0.16.7"
,
"@types/lodash-es"
:
"^4.17.12"
,
"@types/lodash-es"
:
"^4.17.12"
,
"@types/node"
:
"^20.11.16"
,
"@types/node"
:
"^20.11.16"
,
...
...
web/pnpm-lock.yaml
View file @
03d67d5a
This diff is collapsed.
Click to expand it.
web/src/App.tsx
View file @
03d67d5a
import
{
useColorScheme
}
from
"@mui/joy"
;
import
{
useColorScheme
}
from
"@mui/joy"
;
import
mermaid
from
"mermaid"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
Outlet
}
from
"react-router-dom"
;
import
{
Outlet
}
from
"react-router-dom"
;
...
@@ -18,6 +19,8 @@ const App = () => {
...
@@ -18,6 +19,8 @@ const App = () => {
const
{
appearance
,
locale
,
systemStatus
}
=
globalStore
.
state
;
const
{
appearance
,
locale
,
systemStatus
}
=
globalStore
.
state
;
const
userSetting
=
userStore
.
userSetting
;
const
userSetting
=
userStore
.
userSetting
;
mermaid
.
initialize
({
startOnLoad
:
false
,
theme
:
mode
});
// Redirect to sign up page if no host.
// Redirect to sign up page if no host.
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
systemStatus
.
host
)
{
if
(
!
systemStatus
.
host
)
{
...
...
web/src/components/MemoContent/CodeBlock.tsx
View file @
03d67d5a
...
@@ -3,8 +3,11 @@ import copy from "copy-to-clipboard";
...
@@ -3,8 +3,11 @@ import copy from "copy-to-clipboard";
import
hljs
from
"highlight.js"
;
import
hljs
from
"highlight.js"
;
import
toast
from
"react-hot-toast"
;
import
toast
from
"react-hot-toast"
;
import
Icon
from
"../Icon"
;
import
Icon
from
"../Icon"
;
import
MermaidBlock
from
"./MermaidBlock"
;
import
{
BaseProps
}
from
"./types"
;
import
{
BaseProps
}
from
"./types"
;
const
MERMAID_LANGUAGE
=
"mermaid"
;
interface
Props
extends
BaseProps
{
interface
Props
extends
BaseProps
{
language
:
string
;
language
:
string
;
content
:
string
;
content
:
string
;
...
@@ -19,6 +22,10 @@ const CodeBlock: React.FC<Props> = ({ language, content }: Props) => {
...
@@ -19,6 +22,10 @@ const CodeBlock: React.FC<Props> = ({ language, content }: Props) => {
return
<
div
className=
"w-full overflow-auto !my-2"
dangerouslySetInnerHTML=
{
{
__html
:
content
}
}
/>;
return
<
div
className=
"w-full overflow-auto !my-2"
dangerouslySetInnerHTML=
{
{
__html
:
content
}
}
/>;
}
}
if
(
formatedLanguage
===
MERMAID_LANGUAGE
)
{
return
<
MermaidBlock
content=
{
content
}
/>;
}
try
{
try
{
const
temp
=
hljs
.
highlight
(
content
,
{
const
temp
=
hljs
.
highlight
(
content
,
{
language
:
formatedLanguage
,
language
:
formatedLanguage
,
...
@@ -39,6 +46,7 @@ const CodeBlock: React.FC<Props> = ({ language, content }: Props) => {
...
@@ -39,6 +46,7 @@ const CodeBlock: React.FC<Props> = ({ language, content }: Props) => {
<
span
className=
"text-sm font-mono"
>
{
formatedLanguage
}
</
span
>
<
span
className=
"text-sm font-mono"
>
{
formatedLanguage
}
</
span
>
<
Icon
.
Copy
className=
"w-4 h-auto cursor-pointer hover:opacity-80"
onClick=
{
handleCopyButtonClick
}
/>
<
Icon
.
Copy
className=
"w-4 h-auto cursor-pointer hover:opacity-80"
onClick=
{
handleCopyButtonClick
}
/>
</
div
>
</
div
>
<
pre
className=
"w-full p-2 bg-amber-50 dark:bg-zinc-700 whitespace-pre-wrap relative"
>
<
pre
className=
"w-full p-2 bg-amber-50 dark:bg-zinc-700 whitespace-pre-wrap relative"
>
<
code
<
code
className=
{
classNames
(
`language-${formatedLanguage}`
,
"block text-sm leading-5"
)
}
className=
{
classNames
(
`language-${formatedLanguage}`
,
"block text-sm leading-5"
)
}
...
...
web/src/components/MemoContent/MermaidBlock.tsx
0 → 100644
View file @
03d67d5a
import
mermaid
from
"mermaid"
;
import
{
useEffect
,
useRef
}
from
"react"
;
interface
Props
{
content
:
string
;
}
const
MermaidBlock
:
React
.
FC
<
Props
>
=
({
content
}:
Props
)
=>
{
const
mermaidDockBlock
=
useRef
<
null
>
(
null
);
useEffect
(()
=>
{
if
(
!
mermaidDockBlock
.
current
)
{
return
;
}
// Render mermaid when mounted
mermaid
.
run
({
nodes
:
[
mermaidDockBlock
.
current
],
});
});
return
(
<
pre
ref=
{
mermaidDockBlock
}
className=
"w-full p-2 whitespace-pre-wrap relative"
dangerouslySetInnerHTML=
{
{
__html
:
content
}
}
></
pre
>
);
};
export
default
MermaidBlock
;
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