Skip to content

Commit

Permalink
[FIX] Markdown viewer heigth
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianDC13 committed Mar 23, 2022
1 parent 4b693f4 commit 21c2597
Show file tree
Hide file tree
Showing 4 changed files with 9,379 additions and 23 deletions.
23 changes: 1 addition & 22 deletions components/apis/markdown-viewer.tsx
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>
)
}
5,225 changes: 5,224 additions & 1 deletion public/css/markdown.css

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions public/css/markdown.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit 21c2597

Please sign in to comment.