[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 |
|
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/ |
cee-chen
left a comment
There was a problem hiding this comment.
Changes for my feedback look great - thanks for the super thorough unit tests!! 🎉
elizabetdev
left a comment
There was a problem hiding this comment.
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
lineNumbersprop to accept a comma-separated list of line number(s) or range(s) ({ highlight: '1, 5-10, 20-30, 40' }).Amsterdam:

v7:

Also fixes a row height bug for virtualized blocks noticed during this work.
Checklist
- [ ] Checked in mobile