Add block text highlighting in instruction panel - #1584
Merged
Conversation
cocomarine
temporarily deployed
to
previews/1584/merge
August 10, 2026 12:09 — with
GitHub Actions
Inactive
vite.lib.js passes `babel: { plugins: [["prismjs", ...]] }` to
@vitejs/plugin-react. Plugin-react v6 transforms with oxc and has no
`babel` option at all, so the config has been ignored since the Vite
migration. That left us with the bare prismjs entry: markup, css, clike
and javascript, no python, and an empty Prism.plugins. rpf-markdown-core
was emitting correct `line-numbers` / `data-line` markup all along;
there was simply no plugin JS to consume it.
Replaced with explicit imports in src/utils/prism.js. Setting
Prism.manual and configuring NormalizeWhitespace at import time also
fixes a latent bug: the old useEffect raced prism-core's automatic
highlight pass and re-registered its before-sanity-check hook on every
mount.
cocomarine
temporarily deployed
to
previews/1584/merge
August 10, 2026 13:51 — with
GitHub Actions
Inactive
The plugin prepends a shim banner to every pre-bundled dependency and
does not terminate the last statement:
globalThis.global = globalThis.global || __global_polyfill
A newline does not end that statement. Prism's plugin files start with
`(function(){...})()`, so the IIFE parsed as an argument to the shim
and the whole expression was short-circuited away once globalThis.global
was truthy — the plugin body never ran. Verified in Chrome:
Prism.plugins was ["fileHighlight", "NormalizeWhitespace"] under
`yarn start` but the full set in a production build, since the banner
is only wired into optimizeDeps. prism-python escaped it by not
starting with a paren, and normalize-whitespace by getting a
__commonJSMin wrapper that preserved the semicolon.
Excluded the three plugin files from pre-bundling.
cocomarine
temporarily deployed
to
previews/1584/merge
August 10, 2026 13:53 — with
GitHub Actions
Inactive
cocomarine
temporarily deployed
to
previews/1584/merge
August 10, 2026 14:31 — with
GitHub Actions
Inactive
cocomarine
had a problem deploying
to
previews/1584/merge
August 10, 2026 14:33 — with
GitHub Actions
Failure
…om:RaspberryPiFoundation/editor-ui into 1690-add-block-highlighting-in-instruction
cocomarine
had a problem deploying
to
previews/1584/merge
August 10, 2026 14:37 — with
GitHub Actions
Failure
cocomarine
temporarily deployed
to
previews/1584/merge
August 10, 2026 14:42 — with
GitHub Actions
Inactive
cocomarine
marked this pull request as ready for review
August 10, 2026 16:15
cocomarine
marked this pull request as draft
August 10, 2026 16:15
cocomarine
temporarily deployed
to
previews/1584/merge
August 10, 2026 16:21 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the instructions rendering pipeline to support block-type (scratchblocks-style) inline code highlighting via Kramdown-style class attributes, while also restoring Prism syntax highlighting behavior that was impacted during the Vite migration.
Changes:
- Switch instruction markdown rendering from
markedto@raspberrypifoundation/rpf-markdown-coreto support inline class attributes. - Replace the prior
babel-plugin-prismjsbuild-time Prism injection with explicit runtime Prism imports/config insrc/utils/prism.js. - Adjust Vite dev dependency optimization and Jest transforms to accommodate Prism plugin behavior and ESM-only transitive deps used by
rpf-markdown-core.
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds @raspberrypifoundation/rpf-markdown-core and related dependency graph changes; removes babel-plugin-prismjs/marked entries. |
| package.json | Adds @raspberrypifoundation/rpf-markdown-core; removes direct marked and babel-plugin-prismjs deps. |
| vite.lib.js | Removes @vitejs/plugin-react Babel prism injection now that Prism setup is explicit in source. |
| vite.config.js | Excludes specific Prism plugins from optimizeDeps to avoid dev-time prebundle issues. |
| src/utils/prism.js | Centralizes Prism language/plugin registration and runtime configuration (manual mode, whitespace defaults, hook). |
| src/utils/prism.test.js | Adds tests asserting Prism setup and verifying rpf-markdown-core fences produce line numbers/highlights. |
| src/containers/WebComponentLoader.jsx | Removes legacy window.Prism → window.syntaxHighlight bridging script. |
| src/containers/WebComponentLoader.test.jsx | Removes assertions/mocks related to the removed window.syntaxHighlight bridge. |
| src/components/Menus/Sidebar/InstructionsPanel/InstructionsStep/InstructionsStep.jsx | Uses rpf-markdown-core for markdown rendering; uses shared Prism utility; post-processes links for target/rel. |
| src/components/Menus/Sidebar/InstructionsPanel/InstructionsStep/InstructionsStep.test.jsx | Updates tests for new Prism import and adds coverage for inline code class attachment behavior. |
| src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.test.jsx | Removes direct Prism mocking and a Prism assertion tied to the prior behavior. |
| src/assets/stylesheets/Instructions.scss | Refactors scratchblock inline code colour rules using the shared category map and adjusts dark-mode specificity. |
| src/assets/stylesheets/_scratch_colours.scss | Introduces $scratch-block-categories mapping used to generate scratchblock class styles. |
| jest.config.js | Updates transformIgnorePatterns to ensure Jest transforms marked and scratchblocks as required by rpf-markdown-core’s CJS build. |
| .babelrc | Removes Prism Babel plugin configuration, leaving only the CRA preset. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
cocomarine
marked this pull request as ready for review
August 11, 2026 07:36
cocomarine
temporarily deployed
to
previews/1584/merge
August 11, 2026 07:37 — with
GitHub Actions
Inactive
zetter-rpf
reviewed
Aug 11, 2026
zetter-rpf
reviewed
Aug 11, 2026
zetter-rpf
reviewed
Aug 11, 2026
zetter-rpf
approved these changes
Aug 11, 2026
Contributor
|
@cocomarine could we look at adding some more user friendly class names - happy to discuss this. Can also do in a follow up PR |
maxelkins
pushed a commit
that referenced
this pull request
Aug 11, 2026
Closes RaspberryPiFoundation/digital-editor-issues#1690 ## Block-type text highlighting - Used [rpf-markdown-core](https://github.com/RaspberryPiFoundation/rpf-markdown-core) (built by the Code Club team) for rendering instructions, chosen for its inline Kramdown class support. - Refactored the css file so that they apply to both light and dark mode without breaking others. | Before | After | | -------- | ------- | | <img width="392" height="349" alt="Screenshot 2026-08-10 at 17 02 22" src="https://github.com/user-attachments/assets/907a3a46-c871-4128-8f2d-081a9293edcf" /> | <img width="395" height="364" alt="Screenshot 2026-08-10 at 17 04 13" src="https://github.com/user-attachments/assets/8ac0b8f3-9a34-45ae-b134-334f8a98454a" /> | ## Prism and other fixes - While doing this work, I found Prism had stopped working possibly due to the partial Vite migration. Prism provides syntax highlighting, line numbering and line highlighting in code blocks of instructions. Classroom and ExpCS instructions don't use these currently, but CCP instructions do (and CCP team also noticed this when running projects site locally along with latest editor-ui). <img width="360" alt="Screenshot 2026-08-10 at 17 02 57" src="https://github.com/user-attachments/assets/6d134da6-0bb3-476f-8c80-08a3cacb9456" /> - The existing `vite.lib.js` configured `babel-plugin-prismjs` via @vitejs/plugin-react's babel option. But the plugin-react v6 no longer has, so the config was ignored. Replaced with explicit imports in src/utils/prism.js. - In dev environment, `vite-plugin-node-polyfills` prepends a shim banner to every pre-bundled dependency without terminating the last statement. Prism's plugin files start with (function(){…})(), so it was parsed as an argument to the shim and then short-circuited away, resulting in line-numbers and line-highlight not registered. Worked around with optimizeDeps.exclude in vite.config.js. - Jest couldn't load any test importing rpf-markdown-core. Its CJS build requires marked and scratchblocks, both ESM-only with no CommonJS entry. Updated transformIgnorePatterns to exempt both, matched against the full path so the nested rpf-markdown-core/node_modules/scratchblocks copy is also covered. ## Can our users use any other features that the rpf-markdown-core provides? - Not yet. There are some styling issues with others which we need to address first. - CCP team is also open to collaboration if we require certain set of functionalities from or improvements to the library. | Spacing issues | issues with dark mode | | -------- | ------- | | <img width="400" height="580" alt="Screenshot 2026-08-10 at 17 04 34" src="https://github.com/user-attachments/assets/8b5e80ff-5f78-4857-9adc-21d5ee06387c" /> | <img width="400" alt="Screenshot 2026-08-10 at 17 19 52" src="https://github.com/user-attachments/assets/044320f4-70ee-4017-8b4f-4b5c95753e14" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1690
Block-type text highlighting
Prism and other fixes
While doing this work, I found Prism had stopped working possibly due to the partial Vite migration. Prism provides syntax highlighting, line numbering and line highlighting in code blocks of instructions. Classroom and ExpCS instructions don't use these currently, but CCP instructions do (and CCP team also noticed this when running projects site locally along with latest editor-ui).

The existing
vite.lib.jsconfiguredbabel-plugin-prismjsvia @vitejs/plugin-react's babel option. But the plugin-react v6 no longer has, so the config was ignored. Replaced with explicit imports in src/utils/prism.js.In dev environment,
vite-plugin-node-polyfillsprepends a shim banner to every pre-bundled dependency without terminating the last statement. Prism's plugin files start with (function(){…})(), so it was parsed as an argument to the shim and then short-circuited away, resulting in line-numbers and line-highlight not registered. Worked around with optimizeDeps.exclude in vite.config.js.Jest couldn't load any test importing rpf-markdown-core. Its CJS build requires marked and scratchblocks, both ESM-only with no CommonJS entry. Updated transformIgnorePatterns to exempt both, matched against the full path so the nested rpf-markdown-core/node_modules/scratchblocks copy is also covered.
Can our users use any other features that the rpf-markdown-core provides?