Syntax-highlighting Code Block (with Server-side Rendering)

Beskrivelse

This plugin extends to Code block in WordPress core to add syntax highlighting which is rendered on the server. By performing the syntax highlighting on the server, there is then no need to enqueue any JavaScript on the frontend (e.g. Highlight.js or Prism.js) and this ensures there is no flash of unhighlighted code (FOUC?). Reducing script on the frontend improves frontend performance and it also allows for the syntax highlighted code to appear properly in AMP pages as rendered by the official AMP plugin (see also ampproject/amp-wp#972).

The extended Code block uses auto-detection for the language in the block to add syntax highlighting, but you can override the language in the block inspector. (There is currently no syntax highlighting of the Code block in the editor.) The plugin supports for all 185 programming languages that highlight.php supports (being a port of highlight.js).

Any one of 89 styles may be enqueued that highlight.php/highlight.js provide. To change the default style, you may do so by picking a theme via Customizer in the Colors section. To override the default style programmatically, use the syntax_highlighting_code_block_style to supply the one of the style names, for example github:

add_filter(
    'syntax_highlighting_code_block_style',
    function() {
        return 'github';
    }
);

When a filter is provided, the theme selector in Customizer is automatically disabled.

This plugin is developed on GitHub. See list of current issues with the plugin. Please feel free to file any additional issues or requests that you may come across. Pull requests are welcome to help extend.

Credits

This is a fork of Code Syntax Block by Marcus Kazmierczak (mkaz), which is also available on WordPress.org. Copyright (c) 2018 Marcus Kazmierczak. Licensed under GPL 2.0 or later.

highlight.php is released under the BSD 3-Clause License. Copyright © 2006-2013, Ivan Sagalaev (maniac@softwaremaniacs.org), highlight.js (original author). Copyright © 2013, Geert Bergman (geert@scrivo.nl), highlight.php

Skjermskudd

  • Supply content as you do normally in the Code block, optionally overriding the auto-detected language.
  • The Code block renders with syntax highlighting on the frontend without any JavaScript enqueued.

Blokker

Denne utvidelsen gir 1 blokk.

core/code
Syntax-highlighting Code Block (with Server-side Rendering)

Vurderinger

3. november, 2019
Plug and play. The language auto detection is awesome and it works with Gutenberg. Thank you for the great plugin!
30. august, 2019
The best plugin for highlighting code in the block editor Gutenberg. Its main advantage: no need to enqueue any JavaScript. The only drawback is the long plugin name. Great!
1. august, 2019
Just installed this on my site and started writing up a new post. I can't get over how well it works. Thanks, Weston!
31. juli, 2019
Thanks for publishing this plugin, Weston! I just installed it on my website and it works great. No configuration needed. My coding tutorials look so much better now 🙂
Les alle 5 vurderinger

Bidragsytere og utviklere

“Syntax-highlighting Code Block (with Server-side Rendering)” er programvare med åpen kildekode. Følgende personer har bidratt til denne utvidelsen.

Bidragsytere

“Syntax-highlighting Code Block (with Server-side Rendering)” har blitt oversatt til 3 språk. Takk til oversetterne for deres bidrag.

Oversett “Syntax-highlighting Code Block (with Server-side Rendering)” til ditt språk.

Interessert i utvikling?

Bla gjennom koden, sjekk ut SVN-repositoriet, eller abonner på utviklingsloggen med RSS.

Endringslogg

For the plugin’s changelog, please see the Releases page on GitHub.