Skip to content
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

Feat: DO-3456 extract code from markdown and use code viewer in chat component #348

Conversation

patricia-causalens
Copy link
Contributor

@patricia-causalens patricia-causalens commented Jul 24, 2024

Motivation and Context

Improve the visuals of code blocks rendered within Chat component, and allow users to easily copy its content

Implementation Description

Added a parser that breaks the message string into Markdown and CodeViewer components. This is only applied to the displayed message so that when editing users still have full control of the markdown string and can make changes if needed

Updated base markdown component to use CodeViewer for code blocks with a specified language.

Any new dependencies Introduced

How Has This Been Tested?

Locally on storybook

PR Checklist:

  • I have implemented all requirements? (see JIRA, project documentation).
  • I am not affecting someone else's work, If I am, they are included as a reviewer.
  • I have added relevant tests (unit, integration or regression).
  • I have added comments to all the bits that are hard to follow.
  • I have added/updated Documentation.
  • I have updated the appropriate changelog with a line for my changes.

Screenshots (if appropriate):

Screenshot 2024-07-24 at 21 20 57

* A function to parse markdown such that code blocks return CodeViewer component
* @param message
*/
function parseMarkdown(message: string): React.ReactNode[] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could simply utilize the tag->component map like in the example here https://github.com/remarkjs/react-markdown?tab=readme-ov-file#use-custom-components-syntax-highlight rather than relying on our own regex?

@krzysztof-causalens
Copy link
Collaborator

Updated the approach slightly. Baked the code display into the base markdown display instead, if the code block has a specified language e.g. "```python...".
If no language is specified or it's an inline code block e.g. some code then default display is used.

Screenshot 2024-07-25 at 12 14 03

@tamara-causalens let me know if this behaviour looks okay.

@krzysztof-causalens
Copy link
Collaborator

Dark mode doesn't look great in general yet but code blocks do switch to the opposite color which looks pretty good imo.

Screenshot 2024-07-25 at 12 23 11

Copy link
Contributor

@tamara-causalens tamara-causalens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing! 😍

jsumiguin-causalens

This comment was marked as resolved.

@krzysztof-causalens krzysztof-causalens merged commit d2b7ec5 into master Jul 25, 2024
2 checks passed
@krzysztof-causalens krzysztof-causalens deleted the DO-3456-extract-code-from-markdown-and-use-code-viewer-in-chat-component branch July 25, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants