-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b693f4
commit 21c2597
Showing
4 changed files
with
9,379 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,11 @@ | ||
import { useEffect } from 'react' | ||
import { marked } from 'marked'; | ||
|
||
export default function MarkdownViewer({ content }: { content: string }) { | ||
const stylesheetTag = '<link rel="stylesheet" href="/css/markdown.css" />' | ||
const html = stylesheetTag + marked.parse(content) | ||
|
||
const updateSize = (frame: any) => { | ||
frame.style.height = | ||
420 + frame.contentWindow.document.body.scrollHeight + 'px' | ||
frame.style.width = '100%' | ||
} | ||
useEffect(() => { | ||
const frame = document.getElementById('md-frame') as any | ||
|
||
const doc = frame ? frame.contentWindow?.document : null | ||
if (doc) { | ||
doc.open() | ||
doc.write(html) | ||
doc.close() | ||
|
||
updateSize(frame) | ||
} | ||
return () => { } | ||
}, [content, html]) | ||
|
||
return ( | ||
<div className="relative"> | ||
<iframe id="md-frame"></iframe> | ||
<div className="relative markdown-viewer" dangerouslySetInnerHTML={{ __html: html }}> | ||
</div> | ||
) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.