Skip to content

Add block text highlighting in instruction panel - #1584

Merged
cocomarine merged 14 commits into
mainfrom
1690-add-block-highlighting-in-instruction
Aug 11, 2026
Merged

Add block text highlighting in instruction panel#1584
cocomarine merged 14 commits into
mainfrom
1690-add-block-highlighting-in-instruction

Conversation

@cocomarine

@cocomarine cocomarine commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1690

Block-type text highlighting

  • Used 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
Screenshot 2026-08-10 at 17 02 22 Screenshot 2026-08-10 at 17 04 13

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).
    Screenshot 2026-08-10 at 17 02 57

  • 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
Screenshot 2026-08-10 at 17 04 34 Screenshot 2026-08-10 at 17 19 52

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
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
cocomarine temporarily deployed to previews/1584/merge August 10, 2026 13:53 — with GitHub Actions Inactive
@cocomarine
cocomarine temporarily deployed to previews/1584/merge August 10, 2026 14:31 — with GitHub Actions Inactive
@cocomarine
cocomarine temporarily deployed to previews/1584/merge August 10, 2026 14:42 — with GitHub Actions Inactive
@cocomarine
cocomarine marked this pull request as ready for review August 10, 2026 16:15
@cocomarine
cocomarine marked this pull request as draft August 10, 2026 16:15
@cocomarine
cocomarine temporarily deployed to previews/1584/merge August 10, 2026 16:21 — with GitHub Actions Inactive
@cocomarine cocomarine changed the title Add rpf-markdown-core syntax for block highlighting Add rpf-markdown-core syntax for block text highlighting in instruction Aug 11, 2026
@cocomarine cocomarine changed the title Add rpf-markdown-core syntax for block text highlighting in instruction Add block text highlighting in instruction panel Aug 11, 2026
@cocomarine
cocomarine requested a lite review from Copilot August 11, 2026 07:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 marked to @raspberrypifoundation/rpf-markdown-core to support inline class attributes.
  • Replace the prior babel-plugin-prismjs build-time Prism injection with explicit runtime Prism imports/config in src/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.Prismwindow.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.

Comment thread src/utils/prism.test.js
@cocomarine
cocomarine marked this pull request as ready for review August 11, 2026 07:36
@cocomarine
cocomarine temporarily deployed to previews/1584/merge August 11, 2026 07:37 — with GitHub Actions Inactive
Comment thread yarn.lock
Comment thread src/assets/stylesheets/Instructions.scss

@zetter-rpf zetter-rpf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, I appreciate the time you've taken to understand RPF markdown and prism and to improve instructions as a whole.

Added a few comments, the only thing that might be a blocker to merging is the change in how links are rendered

@maxelkins

Copy link
Copy Markdown
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

@cocomarine
cocomarine merged commit 0567d57 into main Aug 11, 2026
6 checks passed
@cocomarine
cocomarine deleted the 1690-add-block-highlighting-in-instruction branch August 11, 2026 08:51
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"
/> |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants