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
e8ed437c
Commit
e8ed437c
authored
Jun 04, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: purify html before render
parent
2b49025f
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
61 deletions
+86
-61
package.json
web/package.json
+1
-0
pnpm-lock.yaml
web/pnpm-lock.yaml
+82
-60
CodeBlock.tsx
web/src/components/MemoContent/CodeBlock.tsx
+3
-1
No files found.
web/package.json
View file @
e8ed437c
...
...
@@ -21,6 +21,7 @@
"clsx"
:
"^2.1.1"
,
"copy-to-clipboard"
:
"^3.3.3"
,
"dayjs"
:
"^1.11.11"
,
"dompurify"
:
"^3.1.5"
,
"fuse.js"
:
"^7.0.0"
,
"highlight.js"
:
"^11.9.0"
,
"i18next"
:
"^23.11.5"
,
...
...
web/pnpm-lock.yaml
View file @
e8ed437c
This diff is collapsed.
Click to expand it.
web/src/components/MemoContent/CodeBlock.tsx
View file @
e8ed437c
import
clsx
from
"clsx"
;
import
copy
from
"copy-to-clipboard"
;
import
DOMPurify
from
"dompurify"
;
import
hljs
from
"highlight.js"
;
import
{
useCallback
,
useMemo
}
from
"react"
;
import
toast
from
"react-hot-toast"
;
...
...
@@ -23,7 +24,8 @@ const CodeBlock: React.FC<Props> = ({ language, content }: Props) => {
// Users can set Markdown code blocks as `__html` to render HTML directly.
if
(
formatedLanguage
===
SpecialLanguage
.
HTML
)
{
return
<
div
className=
"w-full overflow-auto !my-2"
dangerouslySetInnerHTML=
{
{
__html
:
content
}
}
/>;
const
purify
=
DOMPurify
(
window
);
return
<
div
className=
"w-full overflow-auto !my-2"
dangerouslySetInnerHTML=
{
{
__html
:
purify
.
sanitize
(
content
)
}
}
/>;
}
else
if
(
formatedLanguage
===
SpecialLanguage
.
MERMAID
)
{
return
<
MermaidBlock
content=
{
content
}
/>;
}
...
...
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