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
Copy file name to clipboardExpand all lines: AGENTS.md
+2-16Lines changed: 2 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
**WebberZone Code Block Highlighting** v1.1.0. 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. Namespace: `WebberZone\Code_Block_Highlighting`. Requires WordPress 6.6+, PHP 7.4+. No Freemius.
4
4
5
5
Two highlighting modes:
6
+
6
7
-**Client-side** (default): Prism.js runs in the browser. Loads the Prism JS bundle + theme CSS.
7
8
-**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.
8
9
@@ -31,6 +32,7 @@ npm run zip # Plugin zip
31
32
Bootstrap: `wzcbh()` singleton on `plugins_loaded` → instantiates `Frontend\Blocks`, `Frontend\Styles_Handler` → `Admin\Admin` on `init` (admin only).
32
33
33
34
Key files:
35
+
34
36
-`includes/class-main.php` — bootstrap and object wiring
35
37
-`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
36
38
-`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)
@@ -48,22 +50,6 @@ Always `require` the generated `.asset.php` manifest before enqueueing block scr
48
50
49
51
**`wzcbh_languages` filter** — controls the editor UI dropdown only. Does not affect which Prism grammars are bundled. Adding a slug without a matching grammar import in `frontend.js` results in plain-text output.
50
52
51
-
**Editor canvas styling** — `enqueue_editor_canvas_styles()` extracts only `background` and `color` from the active Prism theme CSS and re-injects them with `.block-editor-block-list__layout` prepended to win the specificity race against the editor's own `pre` styles. Layout properties are intentionally excluded.
52
-
53
-
**Themes (21):** A11y Dark, Coldark Cold, Coldark Dark, Dracula, Duotone Dark, Duotone Light, GitHub Light, Gruvbox Dark, Gruvbox Light, Lucario, Material Dark, Material Light, Night Owl, Nord, One Dark, One Light, Shades of Purple, Solarized Dark, Synthwave '84, VS Code Dark+, Xonokai (Monokai).
54
-
55
-
**Default color scheme:**`prism-onedark`
56
-
57
-
**If you change block attributes in JS**, update `render_code_block()` in `class-blocks.php` and the defaults flow as well.
58
-
59
-
## Non-obvious implementation details
60
-
61
-
**`_legacyTitle` attribute** — read-only migration attribute; copies `title` from old `code-syntax-block` format on first load, then clears itself.
62
-
63
-
**`maxHeight`** — CSS-only: serialized as inline `style` by the block save function, not touched by the PHP render filter.
64
-
65
-
**`wzcbh_languages` filter** — controls the editor UI dropdown only. Does not affect which Prism grammars are bundled. Adding a slug without a matching grammar import in `frontend.js` results in plain-text output.
66
-
67
53
**Editor canvas styling** — `enqueue_editor_canvas_styles()` extracts only `background` and `color` from the active Prism theme CSS and re-injects them with `.block-editor-block-list__layout` prepended to win the specificity race against the editor's own `pre` styles.
68
54
69
55
**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. Keys are ordered longest-first to prevent prefix collisions.
All [WebberZone Code Block Highlighting](https://webberzone.com/plugins/webberzone-code-block-highlighting/) settings are available at **Settings > Code Block Highlighting**. Settings are stored in a single WordPress option: `wzcbh_settings`.
14
+
15
+
## Highlighting Mode
16
+
17
+
Controls whether syntax highlighting runs in the browser or on the server. Setting key: `highlighting-mode`.
18
+
19
+
-**Client-side (Prism.js)***(default)* — Prism.js runs in the browser. This mode supports interactive features such as copy-to-clipboard and expand/collapse.
20
+
-**Server-side (highlight.php)** — highlight.php pre-renders syntax token spans on the server before the page is sent to the browser. No JavaScript is loaded for highlighting in this mode.
21
+
22
+
Both modes use the same 21 Prism themes.
23
+
24
+
## Color Scheme
25
+
26
+
Selects the syntax highlighting theme applied to all code blocks. The same Prism theme is used in both client-side and server-side modes. Setting key: `color-scheme`. Default: **One Dark**.
27
+
28
+
## Copy to Clipboard
29
+
30
+
When enabled, a **Copy** button appears in the code block toolbar. Visitors can copy the entire code snippet with one click. Setting key: `copy-to-clipboard`. Default: enabled.
31
+
32
+
This feature is available in client-side mode only. It has no effect when **Highlighting Mode** is set to server-side.
33
+
34
+
## Show Language Label
35
+
36
+
When enabled, the programming language name is displayed in the toolbar above each code block. Setting key: `show-language-label`. Default: enabled.
37
+
38
+
## Show File Name
39
+
40
+
When enabled, the file name or title is displayed in the toolbar above each code block, provided a title has been set on the block. Setting key: `show-file-name`. Default: enabled.
41
+
42
+
## Default Language
43
+
44
+
The language pre-selected when a new code block is inserted in the editor. Leave this field blank to insert new code blocks with no language pre-selected. Setting key: `default-lang`.
45
+
46
+
## Font Size (px)
47
+
48
+
Font size in pixels for code blocks. Set to `0` to inherit the font size from the active theme. Setting key: `font-size`.
title: "Getting Started with WebberZone Code Block Highlighting"
4
+
products: [code-block-highlighting]
5
+
sections: [01-wzcbh-getting-started]
6
+
tags: [code-block-highlighting, installation]
7
+
status: publish
8
+
order: 0
9
+
---
10
+
11
+
WebberZone Code Block Highlighting extends the native WordPress Gutenberg `core/code` block with syntax highlighting, and is available for free on WordPress.org.
12
+
13
+
## WordPress install (The easy way)
14
+
15
+
1. Go to **Plugins > Add New**.
16
+
2. Search for **WebberZone Code Block Highlighting**.
17
+
3. Click **Install Now**, then **Activate**.
18
+
19
+
## Manual install
20
+
21
+
1. Download the latest release from [WordPress.org](https://wordpress.org/plugins/webberzone-code-block-highlighting/) or from [GitHub Releases](https://github.com/WebberZone/webberzone-code-block-highlighting/releases).
22
+
2. Unzip the archive and upload the `webberzone-code-block-highlighting` folder to `/wp-content/plugins/`.
23
+
3. Go to **Plugins** in your WordPress admin and activate **WebberZone Code Block Highlighting**.
After activation, open the block editor and add a **Code** block (or select an existing one). A **Code Highlighting** panel appears in the Inspector Controls sidebar on the right. Use that panel to choose the language, color scheme, and other display options for that block.
40
+
41
+
The plugin works as a filter on top of `core/code` — it never replaces the block. If you deactivate the plugin, syntax highlighting is removed but all code blocks remain intact and valid. No content is lost.
[WebberZone Code Block Highlighting](https://webberzone.com/plugins/webberzone-code-block-highlighting/) supports two rendering modes: client-side (Prism.js in the browser) and server-side (highlight.php on the server). The mode is set globally and applies to all code blocks on the site.
12
+
13
+
[kbtoc]
14
+
15
+
## Client-side mode (default)
16
+
17
+
<ahref="https://prismjs.com/"target="_blank"rel="noopener">Prism.js</a> loads in the visitor's browser and highlights the code on page load. The Prism JS bundle (containing all bundled grammars and plugins) and the active theme CSS are enqueued on pages that contain at least one code block. Interactive toolbar features — copy-to-clipboard, expand/collapse, and the language label — are all available in this mode.
18
+
19
+
## Server-side mode
20
+
21
+
<ahref="https://github.com/scrivo/highlight.php"target="_blank"rel="noopener">highlight.php</a> runs during WordPress page rendering and pre-bakes the highlighted token spans directly into the HTML. No Prism JS is loaded on the frontend. Only the active Prism theme CSS and a small helper stylesheet (`hljs-server-mode.css`) are enqueued.
22
+
23
+
This mode is suitable for:
24
+
25
+
- Sites where JavaScript is disabled or restricted by a content-security policy
26
+
- Performance-focused setups that want fewer frontend scripts
27
+
- AMP-compatible pages
28
+
29
+
In server-side mode, the copy-to-clipboard and expand/collapse toolbar buttons are not available. The **Highlight Lines** per-block control has no effect.
30
+
31
+
## Visual output
32
+
33
+
Both modes load the same 21 Prism themes and produce visually identical output. The plugin remaps the token class names emitted by highlight.php to match Prism's class conventions, so the same theme CSS applies correctly in both modes. You can switch modes at any time from **Settings > Code Block Highlighting** without any visible change to your code blocks.
34
+
35
+
## Asset loading
36
+
37
+
In both modes, assets are only enqueued on pages that contain at least one `core/code` block. Pages without code blocks are not affected. Use the `wzcbh_force_load_assets` filter to override this behavior if needed.
38
+
39
+
## Switching modes
40
+
41
+
Go to **Settings > Code Block Highlighting** and change **Highlighting Mode** to either **Client-side (Prism.js)** or **Server-side (highlight.php)**. No other configuration is required.
Each code block has its own highlighting settings, available in the **Code Highlighting** panel of the Inspector Controls sidebar. These override the global defaults set on the [Code Block Highlighting settings page](https://webberzone.com/plugins/webberzone-code-block-highlighting/).
12
+
13
+
[kbtoc]
14
+
15
+
## Language
16
+
17
+
A dropdown listing 40+ supported languages. Selecting a language applies the correct Prism grammar (or highlight.php language in server-side mode). Choosing **Plain Text** renders the code with the active theme's styling but no syntax highlighting.
18
+
19
+
The `wzcbh_languages` filter can be used to add or remove entries from the dropdown. Adding a language to the filter only affects the UI dropdown; the corresponding Prism.js grammar must also be available in `frontend.js` for the language to highlight correctly in client-side mode.
20
+
21
+
## Line Numbers
22
+
23
+
Toggle to show or hide line numbers on this block. When enabled, a **Start Line** field appears. Set this to any integer to begin numbering from that value — useful when showing a code excerpt that starts partway through a file.
24
+
25
+
## Title
26
+
27
+
A text field for an optional filename or label (e.g. `config.yml`). When **Show File Name** is enabled in global settings, the title appears in the toolbar above the block. If **Show File Name** is disabled globally, the title field is still saved but not displayed.
28
+
29
+
## Highlight Lines
30
+
31
+
Enter a comma-separated list of line numbers or ranges (e.g. `1,3-5,8`) to visually highlight those lines. This maps to the Prism `data-line` attribute. Available in client-side mode only; has no effect in server-side mode.
32
+
33
+
## Max Height
34
+
35
+
Set a maximum visible height in pixels. When the code block content exceeds this height, an **Expand** button appears in the toolbar; clicking it reveals the full block. Set to `0` (the default) to disable this limit. The height limit is applied as inline CSS and is not affected by the highlighting mode.
36
+
37
+
## Word Wrap
38
+
39
+
Toggle soft word wrapping for long lines. When disabled (the default), long lines scroll horizontally.
0 commit comments