Repository navigation
[COMMS-1058] Enable code block syntax highlighting in BlockNote on documents - #26126
Conversation
6cfeafb to
e1e3892
Compare
e1e3892 to
04468de
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Caution The provided work package version does not match the core version Details:
Please make sure that:
|
|
Caution The Enterprise plan field is not set on the work package Details:
Please make sure that:
|
brunopagno
left a comment
There was a problem hiding this comment.
Looks good 🎉
Holding off the approval until the base branch is approved
04468de to
c944818
Compare
|
Warning Flaky specs
🤖 Ask Copilot to investigateCopy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer. |
c944818 to
fa1793f
Compare
Ticket
https://community.openproject.org/wp/COMMS-1058
Stacked on #26049 (COMMS-1057), please review that one first.
What are you trying to accomplish?
Code blocks in documents get syntax highlighting. Each code block has a language picker, and the code is highlighted in the chosen language. The language is kept in the stored markdown as the fence info (
```ruby). The same extension also highlights the LaTeX source in the math popup from COMMS-1057.Screenshots
What approach did you choose and why?
Highlighting.
@blocknote/code-block(0.54.2, matching our BlockNote version) provides thesyntaxHighlighterextension and a list of 48 common languages, which the code block spec inOpBlockNoteEditornow uses. Highlighting is done by Shiki with its JavaScript regex engine. Every grammar is a separate chunk that is only loaded once a block uses that language, so the main bundle barely grows. New code blocks start as plain text, the same default as before and as the server-side schema, so hocuspocus needs no change and already writes the language into the markdown.Guarding unsupported languages. As soon as a language list is configured, BlockNote throws while rendering a code block whose language is not an exact id of that list. The throw happens while the editor mounts, so a single such block makes the whole document fail to open for everyone. Such blocks already exist, because without a list BlockNote stored whatever the user typed. The
```jsinput rule and pasted markdown store aliases likejsorsh, or languages the list does not have, likego. This is still the case in BlockNote 0.56.frontend/src/react/extensions/code-block.tswraps the render of the code block spec. An alias is shown as its language (jsas JavaScript) and an unknown language as plain text. The stored value is left untouched. Rebuilding the spec from BlockNote's helpers instead would lose the code block keyboard shortcuts (tab indentation and the```input rule), whose extension is not exported.Language picker styling. The editor's shadow root loads the application stylesheet, and its global
selectrule (full width, fixed height, page background with an arrow, set with!important) turned BlockNote's language picker into a grey band across the top of every code block, with the language name invisible. The documents stylesheet now resets those properties for the picker, so it shows as BlockNote intends, a small label in the corner of the block on hover. Its options get the default foreground color, since BlockNote paints them black, which would be unreadable on the dark page background in dark mode.Known gaps. The package's list lacks some widely used languages (Go, Dockerfile, diff, PowerShell, TOML, INI). Their grammars are already installed with Shiki and could be added in a follow-up. Blocks in those languages render as plain text for now.
AI involvement
Merge checklist