You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore: add server-side highlighting mode with highlight.php, update docs and build process
Add highlight.php dependency, new highlighting-mode setting (client/server), token class remapping for visual parity across both modes. Update build scripts to install production dependencies and exclude build-prism.min.js. Remove composer.lock from .gitignore. Update AGENTS.md, CLAUDE.md, README.md with server-mode details.
Copy file name to clipboardExpand all lines: AGENTS.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
# AGENTS.md
2
2
3
-
WordPress plugin extending the native Gutenberg `core/code` block with Prism.js syntax highlighting via JS block filters and a `render_block_core/code` PHP filter. Does not replace the block — existing posts stay valid.
3
+
WordPress plugin extending the native Gutenberg `core/code` block with syntax highlighting via JS block filters and a `render_block_core/code` PHP filter. Does not replace the block — existing posts stay valid.
4
+
5
+
Two highlighting modes:
6
+
-**Client-side** (default): Prism.js runs in the browser. Loads the Prism JS bundle + theme CSS.
7
+
-**Server-side**: highlight.php pre-renders token spans on the server. No JS loaded. Uses the same Prism theme CSS — token class remapping (`remap_token_classes()` in `class-blocks.php`) converts hljs-* span classes to Prism `token *` classes via `strtr`, giving exact visual parity across all 21 themes.
Copy file name to clipboardExpand all lines: CLAUDE.md
+20-5Lines changed: 20 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,11 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
5
5
## Plugin Overview
6
6
7
-
**WebberZone Code Block Highlighting** (plugin slug: `webberzone-code-block-highlighting`) extends the native Gutenberg `core/code` block with Prism.js syntax highlighting via JS block filters and a `render_block_core/code` PHP filter. Does not replace the block — existing posts stay valid. Namespace: `WebberZone\Code_Block_Highlighting`. Requires WordPress 6.6+, PHP 7.4+. No Freemius.
7
+
**WebberZone Code Block Highlighting** (plugin slug: `webberzone-code-block-highlighting`) extends the native Gutenberg `core/code` block with syntax highlighting via JS block filters and a `render_block_core/code` PHP filter. Does not replace the block — existing posts stay valid. Namespace: `WebberZone\Code_Block_Highlighting`. Requires WordPress 6.6+, PHP 7.4+. No Freemius.
8
+
9
+
Two highlighting modes:
10
+
-**Client-side** (default): Prism.js runs in the browser. Loads the Prism JS bundle + theme CSS.
11
+
-**Server-side**: highlight.php pre-renders token spans on the server. No JS loaded. Uses the same Prism theme CSS — token class remapping (`remap_token_classes()` in `class-blocks.php`) converts hljs-* span classes to Prism `token *` classes via `strtr`, giving exact visual parity across all 21 themes.
-`includes/frontend/class-blocks.php` — editor assets, REST route, `render_block_core/code` filter; `render_code_block_server()` for server mode; `remap_token_classes()` for hljs→Prism class mapping
48
+
-`includes/frontend/class-styles-handler.php` — conditional asset loading for both modes: client (Prism JS + theme CSS) and server (theme CSS + `hljs-server-mode.css`, no JS)
@@ -64,9 +68,20 @@ Always `require` the generated `.asset.php` manifest before enqueueing block scr
64
68
65
69
**If you change block attributes in JS**, update `render_code_block()` in `class-blocks.php` and the defaults flow as well.
66
70
71
+
**Server-mode token remapping** — `remap_token_classes()` in `class-blocks.php` uses `strtr()` to convert every `class="hljs-*"` span emitted by highlight.php into the equivalent Prism `class="token *"` span. `strtr()` is safe here because highlight.php emits single-class spans only (no compound classes). Keys are ordered longest-first to prevent prefix collisions (e.g. `hljs-selector-tag` before a hypothetical `hljs-selector`).
72
+
73
+
**highlight.php autoloader** — `\Highlight\Autoloader::register()` does not exist. Use `spl_autoload_register(static function(string $class_name): void { \Highlight\Autoloader::load($class_name); })`.
74
+
75
+
**`hljs-server-mode.css`** — only handles `.wzcbh-highlighted-line` line highlighting. Font-size, line-numbers gutter, and word-wrap are all in `frontend.css` (webpack build), which loads in both modes.
76
+
77
+
**Both modes use the same Prism theme CSS** — `Settings::get_color_scheme_css()` always returns the Prism CSS URL. There is no per-mode branch or hljs-specific theme mapping table.
78
+
67
79
## Asset loading
68
80
69
-
Prism assets load only on pages containing at least one `core/code` block (`Styles_Handler::enqueue_assets()`). Use `wzcbh_force_load_assets` to override.
81
+
Assets load only on pages containing at least one `core/code` block (`Styles_Handler::enqueue_assets()`). Use `wzcbh_force_load_assets` to override.
82
+
83
+
-**Client mode**: `frontend.css` + Prism theme CSS + `wzcbh-prism-js` script bundle (includes all grammars and plugins)
84
+
-**Server mode**: `frontend.css` + Prism theme CSS + `hljs-server-mode.css` (no JS; syntax already pre-rendered in HTML)
Add beautiful syntax highlighting to the Gutenberg Code block — powered by Prism.js with 21 themes and 40 languages, zero configuration required.
19
+
Syntax highlighting for the Gutenberg Code block — Prism.js, 21 themes, 40+ languages, plus an optional no-JavaScript server-side mode.
20
20
21
21
## Description
22
22
23
23
__WebberZone Code Block Highlighting__ is the easiest way to add syntax highlighting to your WordPress site. It extends the native Gutenberg `core/code` block with [Prism.js](https://prismjs.com/) highlighting — no shortcodes, no block replacement, no risk of breaking existing posts.
24
24
25
-
Simply activate the plugin and your code blocks will instantly display beautiful, readable syntax highlighting on the frontend. Choose from 35+ programming languages and 21 colour themes, all controlled from the block editor's Inspector Controls sidebar.
25
+
Simply activate the plugin and your code blocks will instantly display beautiful, readable syntax highlighting on the frontend. Choose from 40+ programming languages and 21 colour themes, all controlled from the block editor's Inspector Controls sidebar.
26
+
27
+
### Two highlighting modes
28
+
29
+
Pick the rendering mode that best fits your site from the settings page:
30
+
31
+
*__Client-side (default)__ — [Prism.js](https://prismjs.com/) highlights your code in the browser. Best for interactive features such as copy-to-clipboard and expand/collapse.
32
+
*__Server-side (no JavaScript)__ — Code is pre-highlighted on the server with [highlight.php](https://github.com/scrivo/highlight.php), so no JavaScript is loaded on the frontend. Ideal for performance, Core Web Vitals, AMP-style setups, and strict content-security policies.
33
+
34
+
Both modes use the same 21 Prism themes and produce visually identical output, so you can switch between client-side and server-side rendering at any time without changing how your code blocks look.
26
35
27
36
### Why use this plugin?
28
37
29
38
*__Safe by design__ — Works as a filter on top of `core/code`. Existing posts are never invalidated. Deactivate the plugin and your blocks are still valid standard WordPress code blocks.
30
39
*__Zero configuration__ — Activate and start writing. No setup wizard, no shortcodes.
31
-
*__Smart asset loading__ — Prism CSS and JS only load on pages that actually contain code blocks. Pages without code stay fast.
40
+
*__JavaScript-free option__ — Server-side highlighting renders syntax colours without loading any frontend JavaScript, keeping your pages lean and fast.
41
+
*__Smart asset loading__ — Theme CSS (and, in client mode, Prism JS) only load on pages that actually contain code blocks. Pages without code stay fast.
32
42
*__Per-block controls__ — Set language, theme, line numbers, word wrap, title, highlighted lines, and max height individually for each block.
33
43
*__Developer-friendly__ — Filters to add languages, override themes, and force asset loading.
* Highlighting mode — client-side (Prism.js) or server-side (highlight.php, no JavaScript)
54
65
* Default colour scheme (theme)
55
66
* Default language
56
67
* Default line numbers toggle and start value
@@ -99,8 +110,11 @@ No. The plugin uses JavaScript and PHP filters to extend `core/code`. Deactivati
99
110
__Which languages are supported?__
100
111
40 out of the box. Use the `wzcbh_languages` filter to add or remove entries from the language picker — note the corresponding Prism.js grammar must also be available on the frontend.
101
112
113
+
__What is the difference between client-side and server-side highlighting?__
114
+
Client-side mode runs [Prism.js](https://prismjs.com/) in the browser and enables interactive toolbar features (copy-to-clipboard, expand/collapse). Server-side mode pre-renders the highlighted markup with [highlight.php](https://github.com/scrivo/highlight.php) so no JavaScript is loaded on the frontend — ideal for performance and strict content-security policies. Both modes share the same 21 themes and look identical, so you can switch freely from __Settings > Code Block Highlighting__.
115
+
102
116
__Does Prism.js load on every page?__
103
-
No. Assets are only enqueued on pages containing at least one code block. Use `wzcbh_force_load_assets` to override.
117
+
No. Theme CSS and (in client-side mode) Prism JS are only enqueued on pages containing at least one code block. Use `wzcbh_force_load_assets` to override.
104
118
105
119
__How do I highlight specific lines?__
106
120
Enter a comma-separated list of lines or ranges in the __Highlight Lines__ field in the sidebar (e.g. `1,3-5,8`).
'desc' => __( 'Client-side: Prism.js runs in the browser (default, supports all block features). Server-side: highlight.php pre-renders syntax on the server — no JavaScript required.', 'webberzone-code-block-highlighting' ),
'desc' => __( 'Choose the syntax highlighting theme for all code blocks. This styling is applied only on the frontend and not in the block editor.', 'webberzone-code-block-highlighting' ),
195
+
'desc' => __( 'Choose the syntax highlighting theme. The same Prism.js theme is used in both client-side and server-side modes.', 'webberzone-code-block-highlighting' ),
185
196
'type' => 'select',
186
197
'default' => 'prism-onedark',
187
198
'options' => self::$color_schemes,
@@ -310,10 +321,8 @@ public function enqueue_language_data( string $hook ): void {
310
321
/**
311
322
* Get the URL (or filesystem path) to the active color scheme CSS file.
0 commit comments