-
Notifications
You must be signed in to change notification settings - Fork 821
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
[EuiCodeBlock] Highlight line ranges #5207
Conversation
Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/ |
It's looking good @thompsongl, I just found some small design issues. When the But if we remove this background the line number is highlighted and it doesn't pass the a11y contrast check (4.3). To solve this we can make the number with more contrast (maybe using the Sass function makeHighContrastColor) or we just remove the highlight for line numbers. What do you think? Then, on the following section we should also explain that we can also highlight the numbers. |
Good catch with |
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.
Logic LGTM! I have some minor comments/suggestions but none of them are blockers. I didn't look too closely at the documentation/examples/design, since Elizabet is on it 🎉
Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/ |
Resolved all review comments, @miukimiu @constancecchen 🙇 |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/ |
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.
Changes for my feedback look great - thanks for the super thorough unit tests!! 🎉
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.
Thanks, @thompsongl for making the changes. LGTM! 🎉
This PR is great! cc @goodroot as this is useful for document work. We'll probably want to add a more robust wrapper for the docs system at some point. |
I forgot to revert 2b9eee0 🤦 |
OOh yeah this is real slick. Thanks for the awareness. |
Apologies for the necro on a merged topic, I'm using this component currently and I'm just wondering if anyone knows if it would be possible to dynamically highlight code? I have some json i'm displaying in the code block and ideally I want to highlight sections that match a certain syntax or result (i.e. only highlight objects with type "error"?) or is there any way to expose the API for prism? I'd massively appreciate if anyone could point me in the right direction! |
Hi, @jackamondo I don't think is possible right now to dynamically highlight code that matches a certain syntax. Not sure @thompsongl can point out a workaround. But there is a discussion with some feature requests for the EuiCodeBlock where you can comment there and propose the enhancements you would like to see: #5609. |
No workround at the moment unless you write a script that manipulates the DOM (not actually sure how this would work). I see you've added to the discussion, so that's best course right now. |
Summary
Adds the ability to visually highlight line ranges within EuiCodeBlock. Extends the
lineNumbers
prop to accept a comma-separated list of line number(s) or range(s) ({ highlight: '1, 5-10, 20-30, 40' }
).Amsterdam:
![image](https://user-images.githubusercontent.com/2728212/134250839-052e6f8c-4d14-4049-9fe6-b844f444d18d.png)
v7:
![image](https://user-images.githubusercontent.com/2728212/134250871-3f3617b0-c82e-4cb4-934a-331492b0f5f1.png)
Also fixes a row height bug for virtualized blocks noticed during this work.
Checklist
- [ ] Checked in mobile