Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"axios": "^1.6.7",
"clsx": "^2.1.0",
"date-fns": "^4.1.0",
"dompurify": "^3.4.5",
"lucide-react": "^0.314.0",
"marked": "^18.0.3",
"react": "^18.2.0",
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/DocumentEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState, useEffect, useCallback } from 'react'
import { useState, useEffect, useCallback, useMemo } from 'react'
import { Save, Eye, EyeOff } from 'lucide-react'
import CodeMirror from '@uiw/react-codemirror'
import { markdown } from '@codemirror/lang-markdown'
import DOMPurify from 'dompurify'
import { marked } from 'marked'
import api from '../services/api'

Expand All @@ -22,6 +23,10 @@ export default function DocumentEditor({
const [showPreview, setShowPreview] = useState(false)
const [isSaving, setIsSaving] = useState(false)
const [saveTimeout, setSaveTimeout] = useState<ReturnType<typeof setTimeout> | null>(null)
const sanitizedPreview = useMemo(() => {
const renderedMarkdown = marked.parse(content, { async: false }) as string
return DOMPurify.sanitize(renderedMarkdown)
}, [content])

const handleSave = useCallback(async () => {
setIsSaving(true)
Expand Down Expand Up @@ -91,7 +96,7 @@ export default function DocumentEditor({
<div className="flex-1 overflow-auto">
{showPreview ? (
<div className="prose max-w-none p-6">
<div dangerouslySetInnerHTML={{ __html: marked.parse(content, { async: false }) }} />
<div dangerouslySetInnerHTML={{ __html: sanitizedPreview }} />
</div>
) : (
<div className="h-full">
Expand All @@ -107,4 +112,4 @@ export default function DocumentEditor({
</div>
</div>
)
}
}