This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
WebberZone Code Block Highlighting v1.1.0 (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.
Two highlighting modes:
- Client-side (default): Prism.js runs in the browser. Loads the Prism JS bundle + theme CSS.
- Server-side: highlight.php pre-renders token spans on the server. No Prism.js loaded. Loads Prism theme CSS +
hljs-server-mode.css+hljs-clipboard.js(copy-to-clipboard + expand/collapse). Token class remapping (remap_token_classes()inclass-blocks.php) converts hljs-* span classes to Prismtoken *classes viastrtr, giving exact visual parity across all 21 themes.
WordPress.org: https://wordpress.org/plugins/webberzone-code-block-highlighting/ webberzone.com: https://webberzone.com/plugins/webberzone-code-block-highlighting/
# PHP
composer install
composer test
composer phpcs
composer phpstan
# JS
npm install
npm run build # Production build -> includes/blocks/build/
npm run build:prism # Copy Prism themes -> includes/assets/
npm run build:assets # Minify generated CSS/JS assets
npm run start # Watch mode for block/editor/frontend bundles
npm run zip # Plugin zipNamespace: WebberZone\Code_Block_Highlighting
Bootstrap: wzcbh() singleton on plugins_loaded → instantiates Frontend\Blocks, Frontend\Styles_Handler → Admin\Admin on init (admin only).
Key files:
includes/class-main.php— bootstrap and object wiringincludes/frontend/class-blocks.php— editor assets, REST route,render_block_core/codefilter;render_code_block_server()for server mode;remap_token_classes()for hljs→Prism class mappingincludes/frontend/class-styles-handler.php— conditional asset loading for both modes: client (Prism JS + theme CSS) and server (theme CSS +hljs-server-mode.css+hljs-clipboard.js)includes/admin/class-settings.php— settings registration;get_color_scheme_css()always returns Prism CSS URL (no per-mode branch)includes/blocks/src/js/index.js— block filter, Inspector Controlsincludes/blocks/src/js/frontend.js— Prism grammars + plugins
Always require the generated .asset.php manifest before enqueueing block scripts.
_legacyTitle attribute — read-only migration attribute; copies title from old code-syntax-block format on first load, then clears itself.
maxHeight — CSS-only: serialized as inline style by the block save function, not touched by the PHP render filter.
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.
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.
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).
Default color scheme: prism-onedark
If you change block attributes in JS, update render_code_block() in class-blocks.php and the defaults flow as well.
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).
highlight.php autoloader — \Highlight\Autoloader::register() does not exist. Use spl_autoload_register(static function(string $class_name): void { \Highlight\Autoloader::load($class_name); }).
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.
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.
Assets load only on pages containing at least one core/code block (Styles_Handler::enqueue_assets()). Use wzcbh_force_load_assets to override.
- Client mode:
frontend.css+ Prism theme CSS +wzcbh-prism-jsscript bundle (includes all grammars and plugins) - Server mode:
frontend.css+ Prism theme CSS +hljs-server-mode.css+hljs-clipboard.js(copy-to-clipboard + expand/collapse)
wzcbh_languages— language picker UI list (slug => label); UI only, not grammar loaderwzcbh_color_scheme_css_url— override the Prism theme CSS URLwzcbh_force_load_assets— force Prism assets to load on every page- REST route:
wzcbh/v1/default-settings - Settings key:
wzcbh_settings
- Add the theme mapping in
build-prism.js - Copy the CSS to
includes/assets/ - Register the slug in
includes/admin/class-settings.php - Run
npm run build:prism
- Add
import 'prismjs/components/prism-{slug}'tofrontend.js(respect dependency order) - Add
'slug' => 'Label'toget_languages()inclass-blocks.php - Run
npm run build
Toolbar language labels are aria-hidden. Expand/collapse button uses aria-expanded. When extending toolbar behaviour, preserve keyboard access and screen reader support.
KB articles live in docs/ using the standard WebberZone structure. Frontmatter values:
products: [code-block-highlighting]- Section prefixes:
01-wzcbh-getting-started,02-wzcbh-advanced,03-wzcbh-developer-docs
Run /docs-style --audit webberzone-code-block-highlighting to check style compliance before committing docs.
Verify: JS attribute schema → save output → render_code_block() in PHP → frontend Prism plugin support.