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
Update CLAUDE.md with condensed architecture documentation, increase supported language count to 40 in README, adjust line-highlight opacity and remove redundant toolbar color override in frontend CSS
WordPress plugin that extends the native Gutenberg `core/code` block with Prism.js syntax highlighting. The editor integration is implemented by replacing the `core/code`block edit/save behaviour via a JS block filter, while frontend output is normalized and enhanced through the `render_block_core/code` PHP filter.
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.
4
4
5
5
## Commands
6
6
@@ -20,174 +20,70 @@ npm run start # Watch mode for block/editor/frontend bundles
20
20
npm run zip # Plugin zip
21
21
```
22
22
23
-
## Current feature scope
24
-
25
-
The current implementation follows the active plan in `PLAN.md`, not the broader experimental ideas in `OLD-FEATURE-PLAN.md`.
26
-
27
-
- Extends `core/code` with per-block attributes:
28
-
-`language`
29
-
-`lineNumbers`
30
-
-`lineNumbersStart`
31
-
-`wordWrap`
32
-
-`title`
33
-
-`_legacyTitle` — read-only migration attribute; copies `title` from old `code-syntax-block` format on first load, then clears itself
34
-
-`highlightLines` — maps to `data-line` on `<pre>`, consumed by Prism line-highlight plugin
35
-
-`maxHeight` — inline `style="max-height:{n}px;overflow-y:auto"` on `<pre>` (CSS only, no Prism)
36
-
- Adds Inspector Controls for:
37
-
- language selection
38
-
- file name/title
39
-
- line numbers toggle + start line
40
-
- word wrap
41
-
- highlight lines (e.g. `1,3-5`)
42
-
- max height in px
43
-
- save current settings as defaults
44
-
- Saves defaults through the REST route `wz-cbh/v1/default-settings`
45
-
- Frontend integrates Prism plugins for:
46
-
- line numbers
47
-
- line highlight
48
-
- toolbar
49
-
- show language
50
-
- copy to clipboard
51
-
- Registers a custom Prism toolbar label that reads from `data-title`
52
-
- Registers a `wz-cbh-expand` Prism toolbar button that appears when `max-height` is set; toggles the block between collapsed (original inline style) and expanded (inline style cleared), updating `aria-expanded` on each toggle
53
-
- Supports global settings for:
54
-
- color scheme
55
-
- copy to clipboard
56
-
- show language label
57
-
- show file name
58
-
- default language
59
-
- default line numbers toggle
60
-
- default line numbers start
61
-
- default word wrap
62
-
- font size
63
-
- Ships with `One Dark` as the default theme slug: `prism-onedark`
64
-
65
-
Do not assume features from `OLD-FEATURE-PLAN.md` exist unless they are implemented in code.
23
+
## Source of truth
24
+
25
+
- Active implementation plan: `PLAN.md`
26
+
- Backlog/reference only: `OLD-FEATURE-PLAN.md` — do not assume features exist unless implemented in code.
**`_legacyTitle` attribute** — read-only migration attribute; copies `title` from old `code-syntax-block` format on first load, then clears itself.
94
47
95
-
**Build output:**
48
+
**`maxHeight`** — CSS-only: serialized as inline `style` by the block save function, not touched by the PHP render filter.
96
49
97
-
-`includes/blocks/build/index.js`
98
-
-`includes/blocks/build/frontend.js`
99
-
- corresponding `.asset.php` manifests and extracted CSS files
50
+
**`wz_cbh_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.
100
51
101
-
Always `require`the generated `.asset.php` file before enqueueing block scripts.
52
+
**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.
102
53
103
-
## Data flow
54
+
**Default color scheme:**`prism-onedark`
104
55
105
-
- Language list is provided by `Frontend\Blocks::get_languages()`
106
-
- Editor globals are injected with `wp_add_inline_script()`:
107
-
-`cbhLanguages`
108
-
-`cbhDefaultLang`
109
-
-`cbhDefaultSettings`
110
-
- Frontend globals are injected with `wp_add_inline_script()`:
111
-
-`cbhSettings`
112
-
- Block attributes are saved in block markup and normalized again in `render_code_block()`
113
-
- Default settings are stored in plugin options through the REST endpoint
56
+
**If you change block attributes in JS**, update `render_code_block()` in `class-blocks.php` and the defaults flow as well.
114
57
115
58
## Asset loading
116
59
117
-
`Frontend\Styles_Handler::enqueue_assets()` only loads Prism on the frontend when at least one `core/code` block is present in the current queried posts.
118
-
119
-
Use `wz_cbh_force_load_assets` to bypass conditional loading.
120
-
121
-
The editor canvas styling is handled separately in `Frontend\Blocks::enqueue_editor_canvas_styles()`, which:
60
+
Prism assets load only on pages containing at least one `core/code` block (`Styles_Handler::enqueue_assets()`). Use `wz_cbh_force_load_assets` to override.
122
61
123
-
- enqueues editor CSS into the block editor iframe
124
-
- extracts only `background` and `color` declarations from the active Prism theme
125
-
- re-injects them with stronger selectors so the editor canvas matches the chosen frontend theme without breaking editor layout
62
+
## Filters and routes
126
63
127
-
## Key filters, options, and routes
128
-
129
-
-`wz_cbh_languages` — filter supported Prism languages (`slug => label`)
130
-
-`wz_cbh_color_scheme_css_url` — filter the resolved Prism theme CSS URL
131
-
-`wz_cbh_force_load_assets` — force frontend Prism assets to load
64
+
-`wz_cbh_languages` — language picker UI list (`slug => label`); UI only, not grammar loader
65
+
-`wz_cbh_color_scheme_css_url` — override the Prism theme CSS URL
66
+
-`wz_cbh_force_load_assets` — force Prism assets to load on every page
132
67
- REST route: `wz-cbh/v1/default-settings`
133
-
- Settings option key: `wz_cbh_settings`
134
-
- Settings prefix: `wz_cbh`
135
-
- Settings page slug: `wz_cbh_settings`
136
-
137
-
## Current option IDs
138
-
139
-
These option IDs are registered in `includes/admin/class-settings.php`:
140
-
141
-
-`color-scheme`
142
-
-`copy-to-clipboard`
143
-
-`show-language-label`
144
-
-`show-file-name`
145
-
-`default-lang`
146
-
-`default-line-numbers`
147
-
-`default-line-numbers-start`
148
-
-`default-word-wrap`
149
-
-`font-size`
150
-
151
-
The default color scheme is `prism-onedark`.
68
+
- Settings key: `wz_cbh_settings`
152
69
153
-
## Frontend rendering rules
154
-
155
-
`Frontend\Blocks::render_code_block()` currently:
156
-
157
-
- adds `language-{slug}` to `<code>`
158
-
- adds `line-numbers` to `<pre>` when enabled
159
-
- adds `data-start` to `<pre>` when line numbering starts from a value other than `1`
160
-
- adds `word-wrap` to `<pre>` when enabled
161
-
- adds `data-title` to `<pre>` for the custom toolbar label
162
-
- adds `data-line` to `<pre>` from `highlightLines` attribute (consumed by Prism line-highlight plugin)
163
-
-`maxHeight` is CSS-only: serialized as inline `style` by the block save function, not touched by PHP
164
-
165
-
If you change block attributes in JS, update the PHP rendering logic and defaults flow as well.
166
-
167
-
## Accessibility notes
70
+
## Adding a Prism theme
168
71
169
-
The active plan targets strong accessibility support. Current frontend code already includes:
72
+
1. Add the theme mapping in `build-prism.js`
73
+
2. Copy the CSS to `includes/assets/`
74
+
3. Register the slug in `includes/admin/class-settings.php`
75
+
4. Run `npm run build:prism`
170
76
171
-
- decorative toolbar language labels marked `aria-hidden`
172
-
- a custom title label in the toolbar
173
-
- Prism copy-to-clipboard integration controlled by plugin settings
174
-
- expand/collapse button with `aria-expanded` state management
77
+
## Adding a language
175
78
176
-
If you extend toolbar behaviour, preserve keyboard access and screen reader behaviour.
79
+
1. Add `import 'prismjs/components/prism-{slug}'` to `frontend.js` (respect dependency order)
80
+
2. Add `'slug' => 'Label'` to `get_languages()` in `class-blocks.php`
81
+
3. Run `npm run build`
177
82
178
-
## Adding a Prism theme
83
+
## Accessibility
179
84
180
-
1. Add the theme mapping in `build-prism.js`
181
-
2. Ensure the generated CSS file is copied to `includes/assets/`
182
-
3. Register the theme slug in `includes/admin/class-settings.php`
183
-
4. Run `npm run build:prism`
85
+
Toolbar language labels are `aria-hidden`. Expand/collapse button uses `aria-expanded`. When extending toolbar behaviour, preserve keyboard access and screen reader support.
184
86
185
-
## Notes for future work
87
+
## Before adding new per-block controls
186
88
187
-
- Prefer `PLAN.md` as the source of truth for current implementation direction
188
-
- Treat `OLD-FEATURE-PLAN.md` as backlog/reference only
189
-
- Before adding new per-block controls, verify:
190
-
- the JS attribute schema
191
-
- the save output
192
-
- the PHP render filter
193
-
- frontend Prism plugin support
89
+
Verify: JS attribute schema → save output → `render_code_block()` in PHP → frontend Prism plugin support.
Add beautiful syntax highlighting to the Gutenberg Code block — powered by Prism.js with 18 themes and 35+ languages, zero configuration required.
19
+
Add beautiful syntax highlighting to the Gutenberg Code block — powered by Prism.js with 18 themes and 40 languages, zero configuration required.
20
20
21
21
## Description
22
22
@@ -34,7 +34,7 @@ Simply activate the plugin and your code blocks will instantly display beautiful
34
34
35
35
### Supported languages
36
36
37
-
35+ languages out of the box: Bash, C, C++, C#, CSS, Dart, Docker, F#, Go, GraphQL, Haskell, HTML, Java, JavaScript, JSON, JSX, Kotlin, Markdown, Nginx, Objective-C, PHP, PowerShell, Python, Ruby, Rust, Sass, SQL, Swift, TOML, TSX, TypeScript, Vim, XML, YAML, and more. Use the `wz_cbh_languages` filter to register additional languages.
37
+
40 languages out of the box: Apache Config, Bash, C, C++, C#, CSS, Dart, Docker, F#, Go, GraphQL, Groovy, Haskell, HTML, Java, JavaScript, JSON, JSX, Kotlin, Lua, Markdown, Nginx, Objective-C, Perl, PHP, PowerShell, Python, R, Ruby, Rust, Sass, Scala, SQL, Swift, TOML, TSX, TypeScript, Vim, XML, and YAML. Use the `wz_cbh_languages` filter to add or remove entries from the language picker.
38
38
39
39
### Included themes (18)
40
40
@@ -97,7 +97,7 @@ __Does this plugin replace the core Code block?__
97
97
No. The plugin uses JavaScript and PHP filters to extend `core/code`. Deactivating it leaves behind valid, standard WordPress blocks.
98
98
99
99
__Which languages are supported?__
100
-
35+ out of the box. Use the `wz_cbh_languages` filter to register additional Prism.js grammars.
100
+
40 out of the box. Use the `wz_cbh_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
101
102
102
__Does Prism.js load on every page?__
103
103
No. Assets are only enqueued on pages containing at least one code block. Use `wz_cbh_force_load_assets` to override.
0 commit comments