Skip to content

Add rpf-markdown-core syntax for block highlighting - #1584

Draft
cocomarine wants to merge 12 commits into
mainfrom
1690-add-block-highlighting-in-instruction
Draft

Add rpf-markdown-core syntax for block highlighting#1584
cocomarine wants to merge 12 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/1682

Block-type text highlighting

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

  • The existing vite.lib.js configured babel-plugin-prismjs via @vitejs/plugin-react's babel option, which plugin-react v6 no longer has. 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 address first.
Spacing issues issues with dark mode
Screenshot 2026-08-10 at 17 04 34 Screenshot 2026-08-10 at 17 19 52
  • CCP team is also open to collaboration if we require certain set of functionalities from the library.

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

1 participant