Support for inline code syntax highlighting #395
Replies: 8 comments
-
|
Hello and welcome! :) Thank you for this feature request! This is currently not possible in Expressive Code, I'd need to add support in the plugin API and all built-in plugins for it so that they can distinguish between block-level code processing and inline code processing. In inline code, most rendering features like frames, line numbers, collapsible blocks etc. would not be possible because no block-level tags are allowed. I'm honestly not very happy with the That being said, I'm not sure yet how useful it actually is to highlight inline code. Do you have any real-world examples I could look at where inline highlighting is being used and looks helpful? |
Beta Was this translation helpful? Give feedback.
-
I think that if you're at the point where you would need to add collapsible blocks, frames, or line numbers to an inline block it might as well be converted into a
I unfortunately don't like it that much either, but it seems like this syntax (or variations of it) are an established thing already in a couple of examples I found:
The main maintainer for Shiki had this discussion here and a couple of good points were made, including that nesting the curly brackets within the backticks themselves (
This feature itself is very, very uncommon--hence why supporting it would make documentation significantly more polished (especially in downstreams e.g. Starlight). These aren't considered "real-life examples" since they are documentation for already existing implementations of this feature (and or my own creations), but I hope you can see the appeal:
Inline syntax highlighting would be useful in these particular use cases, taken from the expressive-code docs itself: The point of syntax highlighting itself is to help the human eye break up tokens into recognizable segments, which is especially true for longer segments e.g. the examples from the docs above. Hopefully this clears things up! |
Beta Was this translation helpful? Give feedback.
-
|
I found an example of this here https://rehype-pretty.pages.dev/. I think it would probably be something people would want to be supported but default off? Not sure. Also, I think personally that grey background only works when you don't have colour as that contrast doesn't look strong enough. So, there's things to think about I suppose. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @hippotastic, is this in your pipeline/planned at all? I can attempt to take a look and send a PR if desired. |
Beta Was this translation helpful? Give feedback.
-
Hi @jktrn, yes, basically every feature request I leave open is something I can imagine having in Expressive Code. I liked your idea and also gave your previous post outlining the idea in more detail a thumbs up. I just didn't get to it yet. :) Thank you very much for offering to implement this! Before you attempt to do it, I'd like to come back to this point I mentioned in my first response:
In my opinion, getting this right in terms of the plugin API is the most crucial part of this feature request. We need to find a way to extend the existing plugin API so that plugins can somehow perform work on inline code as well, while making sure that all existing plugins (which are not aware of this new feature) don't get called on inline code while continuing to work as normal on regular code blocks. You can take my existing plugins like frames, collapsible sections and line numbers as examples for your testing. Imagine that these were third-party code you cannot modify, and try to come up with an extension to the existing plugin API that adds inline code support without breaking these existing plugins. Without having to do any modifications to them, they should not get called on inline code, while your new version of I'd be happy to discuss the API idea here first, but if you want to try something out first (or even already have an idea), feel free to risk it and and show a possible implementation in a PR right away. Either way, thanks again for your offer! |
Beta Was this translation helpful? Give feedback.
-
|
I've been looking to finding a solution for this as I agree it's a highly valuable feature. Upon doing so, some initial testing shows that you can utilize The reason this appears to work is as follows:
I have created a demo of using side-by-side, see example screenshots from the demo below. There are a few drawbacks to this approach:
Of course, having two code block processors isn't ideal and it would be preferrable to have one that handles both block code and inline code. Along that line, I have submitted #336, would welcome any feedback/thoughts! Demo Screenshots of using multiple plugins for inline code highlightingDemo - Please be patient upon initial startup, may take a minute even after initial webpage displays. Expressive Code OnlyExpressive Code w/ Rehype-ShikiExpressive Code w/ Rehype-Pretty-Code |
Beta Was this translation helpful? Give feedback.
-
|
@hippotastic Hi, there's a PR for this now! Any chance you can take a look? |
Beta Was this translation helpful? Give feedback.
-
|
Hello! We are moving feature requests and support questions to discussions and using issues only for bugs to help better track those going forward. See you in the Discussions tab! |
Beta Was this translation helpful? Give feedback.











Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I was wondering if it was possible for syntax highlighting of inline code blocks, e.g. some form of syntax along the lines of
const foo = bar{:js}which would highlight the block in the user's selected theme. As of now, this is supported in:@shikijs/rehype, but attempting to import this overrides expressive-code's<pre>-based code blocksrehype-pretty-codewhich ships it out-of-the-boxCould this be possible within expressive-code with some form of custom Shiki transformer or any other means? Thank you for your time.
Beta Was this translation helpful? Give feedback.
All reactions