-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Replace 'markdown-to-jsx' with 'remarkable' for Better Large Mar…
…kdown String Support (#903) * Added new package to render markdown: remarkable * Refactor the component to use 'remarkable' library to render markdown * Uninstall 'markdown-to-jsx' library
- Loading branch information
1 parent
fdb5a0c
commit e886ac7
Showing
3 changed files
with
74 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
38 changes: 14 additions & 24 deletions
38
frontend/src/components/agency/markdown-renderer/MarkdownRenderer.jsx
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,22 @@ | ||
import PropTypes from "prop-types"; | ||
import ReactMarkdown from "markdown-to-jsx"; | ||
import { memo, useMemo } from "react"; | ||
import { Remarkable } from "remarkable"; | ||
|
||
function MarkdownRenderer({ markdownText }) { | ||
return ( | ||
<ReactMarkdown | ||
options={{ | ||
overrides: { | ||
pre: { | ||
component: MyParagraph, | ||
}, | ||
}, | ||
}} | ||
> | ||
{markdownText} | ||
</ReactMarkdown> | ||
); | ||
} | ||
const md = new Remarkable(); | ||
|
||
MarkdownRenderer.propTypes = { | ||
markdownText: PropTypes.string, | ||
}; | ||
const MarkdownRenderer = memo(({ markdownText }) => { | ||
const htmlContent = useMemo(() => { | ||
if (!markdownText) return ""; | ||
return md.render(markdownText); | ||
}, [markdownText]); | ||
|
||
const MyParagraph = ({ children, ...props }) => ( | ||
<div {...props}>{children}</div> | ||
); | ||
return <div dangerouslySetInnerHTML={{ __html: htmlContent }} />; | ||
}); | ||
|
||
MyParagraph.propTypes = { | ||
children: PropTypes.any, | ||
MarkdownRenderer.displayName = "MarkdownRenderer"; | ||
|
||
MarkdownRenderer.propTypes = { | ||
markdownText: PropTypes.string, | ||
}; | ||
|
||
export { MarkdownRenderer }; |