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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

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

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.

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