This extended Code block uses language auto-detection to add syntax highlighting, but you can override the language in the block’s settings sidebar. (There is currently no syntax highlighting of the Code block in the editor.) The plugin supports all programming languages that highlight.php supports (being a port of highlight.js). The Code block also is extended to support specifying the aforementioned highlighted lines. There is also a checkbox for whether to show line numbers on the frontend (with the numbers being non-selectable). Lastly, given inconsistencies across themes as to whether lines in a Code block should be wrapped, this plugin adds styling to force them to no-wrap by default, with a checkbox to opt-in to wrapping when desired.
I confess, I've been a happy user of Code Syntax Block for quite a while — a plugin which the author, Weston Router, clearly states that Syntax Highlighting (Code Block) is based upon.
So why force the end-user to bear the burden of all that work? It makes much more sense to pre-render everything on the server, and then let the web server send the already-parsed HTML from its cache. That way, the end-user will already have everything on their browser, no need to wait for parsing!
Also, if you 'forget' to set the language that your code is in (it happens...), the auto-detecting feature will only run on the server, and just once, when you save the post you're writing. Even if it takes a fraction of a second more to save, think of how much time all those users will save when they get the already-rendered page!
So, this plugin is definitely recommended. As a bonus: if you are already using some sort of code block on your WP setup, once you turn off whatever plugin you were using, Syntax Highlighting (Code Block) will immediately pick it up and start its magic (you might need to open and save all the pages you've got code on, though — I'm not quite sure if that's really the case). That means zero effort (beyond saving) — what you already had will continue to work. And, naturally enough, when you disable this plugin, your code block will just revert to the internal WP code block instead — nothing will be 'lost' that way!
If you're still hesitant and reading this to the end... while you wasted your time here, think of how many of your users would have saved their time if you already had this plugin installed 🙂
No agrega bloques nuevos a WordPress, ya que potencia el bloque de código existente. Soporta gran cantidad de Lenguajes, puedes mostrar líneas y marcar ciertas partes del código. ¡Vaya todo lo que necesito!
Y no hay que configurar nada!
Just found this gem of a plugin when looking for code syntax highlighting plugins. No hassle at all to get working, just install and activate and it formats and styles existing code blocks in posts.
Could not be happier with this plugin. Wlldone!
I've switched to "Syntax-highlighting Code Block" from a similar plugin, mainly because the old one didn't recognize the new Java Text Blocks.
This one does, and GTMetrix also reports a heavily reduced DOM size for almost all my pages, for example:
from 2,363 elements down to 1,654 elements
from 1,842 elements down to 1,442 elements
That's an amazing and surprising improvement!
I do have one feature request, though:
It would be great if one could select a subset of the available languages for the dropdown, so you don't always have to scroll through all 185 languages.
I just wanted to stop by to say thanks for such a great plugin.
It does the job perfectly for me.
The way you have used CSS allows me to customise the different colours etc for different components and I have even got a dark mode version working (with prefers darkmode CSS).
I really hope you are able to keep this project maintained.