Skip to content

Commit ae5700e

Browse files
committed
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
1 parent 4b79f82 commit ae5700e

28 files changed

Lines changed: 98 additions & 158 deletions

CLAUDE.md

Lines changed: 40 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CLAUDE.md
22

3-
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.
44

55
## Commands
66

@@ -20,174 +20,70 @@ npm run start # Watch mode for block/editor/frontend bundles
2020
npm run zip # Plugin zip
2121
```
2222

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.
6627

6728
## Architecture
6829

6930
**Namespace:** `WebberZone\Code_Block_Highlighting`
7031

71-
**Autoloader:** `includes/autoloader.php`
72-
73-
**Bootstrap flow:**
74-
75-
- Main plugin file loads the autoloader.
76-
- `wz_cbh()` resolves the `Main` singleton on `plugins_loaded`.
77-
- `Main` loads `includes/options-api.php`.
78-
- `Main` instantiates:
79-
- `Frontend\Blocks`
80-
- `Frontend\Styles_Handler`
81-
- `Admin\Admin` is created on `init` only when `is_admin()`.
32+
Bootstrap: `wz_cbh()` singleton on `plugins_loaded` → instantiates `Frontend\Blocks`, `Frontend\Styles_Handler``Admin\Admin` on `init` (admin only).
8233

83-
**Key PHP classes:**
34+
Key files:
35+
- `includes/class-main.php` — bootstrap and object wiring
36+
- `includes/frontend/class-blocks.php` — editor assets, REST route, `render_block_core/code`
37+
- `includes/frontend/class-styles-handler.php` — conditional Prism asset loading
38+
- `includes/admin/class-settings.php` — settings registration, theme resolution
39+
- `includes/blocks/src/js/index.js` — block filter, Inspector Controls
40+
- `includes/blocks/src/js/frontend.js` — Prism grammars + plugins
8441

85-
- `includes/class-main.php` — plugin bootstrap and object wiring
86-
- `includes/frontend/class-blocks.php` — editor asset registration, REST route, `render_block_core/code`
87-
- `includes/frontend/class-styles-handler.php` — conditional frontend Prism asset loading
88-
- `includes/admin/class-settings.php` — settings registration, theme resolution, language autocomplete wiring
42+
Always `require` the generated `.asset.php` manifest before enqueueing block scripts.
8943

90-
**JS entry points:**
44+
## Non-obvious implementation details
9145

92-
- `includes/blocks/src/js/index.js` — replaces `core/code` edit/save and adds Inspector Controls
93-
- `includes/blocks/src/js/frontend.js` — Prism core, supported grammars, toolbar/copy/show-language plugins, frontend toolbar behaviour
46+
**`_legacyTitle` attribute** — read-only migration attribute; copies `title` from old `code-syntax-block` format on first load, then clears itself.
9447

95-
**Build output:**
48+
**`maxHeight`** — CSS-only: serialized as inline `style` by the block save function, not touched by the PHP render filter.
9649

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.
10051

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.
10253

103-
## Data flow
54+
**Default color scheme:** `prism-onedark`
10455

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.
11457

11558
## Asset loading
11659

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.
12261

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
12663

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
13267
- 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`
15269

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
16871

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`
17076

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
17578

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`
17782

178-
## Adding a Prism theme
83+
## Accessibility
17984

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.
18486

185-
## Notes for future work
87+
## Before adding new per-block controls
18688

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.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ __License:__ [GPL-2.0+](http://www.gnu.org/licenses/gpl-2.0.html)
1616

1717
__Plugin page:__ [WebberZone Code Block Highlighting](https://webberzone.com/plugins/webberzone-code-block-highlighting/) | [WordPress.org listing](https://wordpress.org/plugins/webberzone-code-block-highlighting/)
1818

19-
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.
2020

2121
## Description
2222

@@ -34,7 +34,7 @@ Simply activate the plugin and your code blocks will instantly display beautiful
3434

3535
### Supported languages
3636

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.
3838

3939
### Included themes (18)
4040

@@ -97,7 +97,7 @@ __Does this plugin replace the core Code block?__
9797
No. The plugin uses JavaScript and PHP filters to extend `core/code`. Deactivating it leaves behind valid, standard WordPress blocks.
9898

9999
__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.
101101

102102
__Does Prism.js load on every page?__
103103
No. Assets are only enqueued on pages containing at least one code block. Use `wz_cbh_force_load_assets` to override.

includes/assets/prism-a11y-dark-rtl.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/assets/prism-atom-dark-rtl.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/assets/prism-darcula-rtl.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/assets/prism-dracula-rtl.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)