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: Add Syntax Highlighting to Multiline Code Blocks using react-syntax-highlighter #764

Merged
merged 9 commits into from
Jan 5, 2025

Conversation

abirc8010
Copy link
Contributor

@abirc8010 abirc8010 commented Dec 31, 2024

Brief Title

Acceptance Criteria fulfillment

  • Implemented syntax highlighting for multiline code blocks using react-syntax-highlighter
  • Rendered inline code in distinct block.
  • Used monokai and vs themes for dark mode and light mode from react-syntax-highlighter .

Fixes #763

Video/Screenshots

Screencast.from.2025-01-01.22-49-52.webm

PR Test Details

Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-764 after approval. Contributors are requested to replace <pr_number> with the actual PR number.

@Spiral-Memory
Copy link
Collaborator

Hey @abirc8010
This is a good change, can you show me how it looks like across all prebuilt themes in the storybook and in both light and dark modes

const code = useMemo(
() => lines.map((line) => line.value.value).join('\n'),
[lines]
);

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use some other library, so we don't have to load the styles like this and apply styles manually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since main RC uses this library so I thought of using it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are they also loading styles this way and manipulating dom element like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are inserting HTML strings and assigning hljs class names. They are also modifying the styles of hljs classes by overriding the predefined CSS of hljs class names.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mmm, Okay...
Still, I am not in favour of this approach, maybe try some different library, where we don't have to load styles and modify dom elements like this.. Let's keep this PR open, we will compare afterwards

@abirc8010 abirc8010 changed the title feat: Add Syntax Highlighting to Multiline Code Blocks using Highlight.js feat: Add Syntax Highlighting to Multiline Code Blocks using react-syntax-highlighter Jan 1, 2025
@abirc8010
Copy link
Contributor Author

@Spiral-Memory I am using react-syntax-highlighter instead

@Spiral-Memory
Copy link
Collaborator

Great @abirc8010
Video attached in the PR description is updated right ?

Copy link
Collaborator

@Spiral-Memory Spiral-Memory left a comment

Choose a reason for hiding this comment

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

LGTM, Nice work @abirc8010 🎉

@abirc8010
Copy link
Contributor Author

Great @abirc8010 Video attached in the PR description is updated right ?

Yes it is the updated one.

@Spiral-Memory
Copy link
Collaborator

Hey @abirc8010
This is good, i am merging it for now, but pls work on making the color consistent in other themes, It should only apply to text not to the container..

image

@Spiral-Memory Spiral-Memory merged commit 12cefd6 into RocketChat:develop Jan 5, 2025
5 checks passed
github-actions bot added a commit that referenced this pull request Jan 5, 2025
@abirc8010
Copy link
Contributor Author

Hey @Spiral-Memory, I'm not sure why the highlighting looks like this now, but when I recorded the video, it was consistent in color and worked fine. I'll look into it.

@Spiral-Memory Spiral-Memory added the enhancement New feature or request label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Add syntax highlighting to multiline code , and render inline code in blocks
2 participants