-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown rendering #1544
Merged
Merged
Markdown rendering #1544
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a29fb97
Add Markdown rendering with syntax highlighting
mashdragon dd119f7
Use lazy loading for Markdown rendering
mashdragon fc9b820
Use tailwind typography for Markdown styling
mashdragon 805dcff
Remove unnecessary styling around code blocks
mashdragon db51ea0
Use same style for all code blocks
mashdragon bb45531
render markdown in message
notmd 310a586
remove debug code
notmd a21fc07
remove change in tailwind config
notmd 55fcc9d
move import to top level
notmd b42433e
remove memo callback check
notmd bacb78b
extract plugin
notmd 0db6d11
Merge branch 'main' into markdown-rendering
notmd adf7a24
tweak style
notmd ed65092
render markdown in modal
notmd 5b691b3
Merge remote-tracking branch 'origin/main' into markdown-rendering
notmd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { SystemStyleObject } from "@chakra-ui/react"; | ||
import { Prose } from "@nikolovlazar/chakra-ui-prose"; | ||
import { memo } from "react"; | ||
import { ReactMarkdown } from "react-markdown/lib/react-markdown"; | ||
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; | ||
import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism"; | ||
import remarkGfm from "remark-gfm"; | ||
interface RenderedMarkdownProps { | ||
markdown: string; | ||
} | ||
|
||
const components = { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
code({ node, inline, className, children, style, ...props }) { | ||
const match = /language-(\w+)/.exec(className || ""); | ||
const lang = match ? match[1] : ""; | ||
return !inline ? ( | ||
<SyntaxHighlighter style={oneDark} language={lang} {...props}> | ||
{String(children).replace(/\n$/, "")} | ||
</SyntaxHighlighter> | ||
) : ( | ||
<code className={className} {...props}> | ||
{children} | ||
</code> | ||
); | ||
}, | ||
}; | ||
|
||
const sx: SystemStyleObject = { | ||
pre: { | ||
bg: "transparent", | ||
}, | ||
code: { | ||
before: { | ||
content: `""`, // charka prose come with "`" by default | ||
}, | ||
bg: "gray.300", | ||
p: 0.5, | ||
borderRadius: "2px", | ||
_dark: { | ||
bg: "gray.700", | ||
}, | ||
}, | ||
"p:only-child": { | ||
my: 0, // ovoid margin when markdown only render 1 p tag | ||
}, | ||
p: { | ||
whiteSpace: "pre-wrap", | ||
display: "inline-block", | ||
}, | ||
display: "inline-block", | ||
wordBreak: "break-word", | ||
"> blockquote": { | ||
borderInlineStartColor: "gray.300", | ||
_dark: { | ||
borderInlineStartColor: "gray.500", | ||
}, | ||
}, | ||
"table tbody tr": { | ||
borderBottomColor: "gray.400", | ||
_dark: { | ||
borderBottomColor: "gray.700", | ||
}, | ||
}, | ||
"table thead tr": { | ||
borderBottomColor: "gray.400", | ||
borderBottomWidth: "1px", | ||
_dark: { | ||
borderBottomColor: "gray.700", | ||
}, | ||
}, | ||
}; | ||
|
||
const plugins = [remarkGfm]; | ||
|
||
// eslint-disable-next-line react/display-name | ||
const RenderedMarkdown = memo(({ markdown }: RenderedMarkdownProps) => { | ||
return ( | ||
<Prose as="div" sx={sx}> | ||
<ReactMarkdown remarkPlugins={plugins} components={components}> | ||
{markdown} | ||
</ReactMarkdown> | ||
</Prose> | ||
); | ||
}); | ||
|
||
export default RenderedMarkdown; |
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
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fix issue where the tree still display connection when it only have root (no children).