feat(editor): highlight Swift, Objective-C, Ruby, and Groovy in code blocks #840

Merged
raisondetredev merged 1 commit from refs/pull/840/head into main 2026-08-22 21:08:16 +02:00
raisondetredev commented 2026-08-22 21:08:02 +02:00 (Migrated from codeberg.org)

The block language menu offered nineteen tags and no way to colour Apple
platform code. A card holding a Swift snippet had to be tagged swift
anyway — the renderer keeps an unknown tag and falls back to unstyled
monospace — so the block rendered grey and the menu labelled it with the
bare lowercase tag, since kCodeBlockLanguageNames had no entry either.

That became visible with the Rust / Kotlin+Android / Swift+iOS decks:
385 of their 440 Swift and Objective-C blocks rendered as plain text,
while the Rust and Kotlin ones beside them coloured normally.

All four grammars already ship in highlight, so this is imports plus
map entries. Ruby and Groovy come along because the same decks quote
podspecs and Gradle Groovy build files, which had been falling back to
text for the same reason.

Placement keeps every existing entry in its current relative order and
puts each new one next to its nearest relative — Ruby by Python, Groovy
by Java, Swift by Kotlin, Objective-C ahead of C. The two lists and the
grammar map stay in the lockstep the component test already asserts.

The cost is bundle weight, as the header in code_highlighting.dart
notes: 31 KB of additional grammar source, against 102 KB already
imported.

code_highlighting_test.dart gains a round-trip check per grammar.
highlightedCodeSpan silently returns plain text when a grammar drops or
duplicates a character, and a silent fallback is indistinguishable from
the grey rendering this commit removes — so each test asserts both that
the runs rejoin to the source exactly and that at least one run is
coloured. Unregistering a grammar fails them.

The notebook keeps its own smaller registry in code_editor_config.dart,
deliberately untouched: those languages are the ones Judge0 can execute,
and a notebook cell cannot run Swift.

Signed-off-by: Tizian 「ティツィアーン」 raisondetredev@pm.me

The block language menu offered nineteen tags and no way to colour Apple platform code. A card holding a Swift snippet had to be tagged `swift` anyway — the renderer keeps an unknown tag and falls back to unstyled monospace — so the block rendered grey and the menu labelled it with the bare lowercase tag, since `kCodeBlockLanguageNames` had no entry either. That became visible with the Rust / Kotlin+Android / Swift+iOS decks: 385 of their 440 Swift and Objective-C blocks rendered as plain text, while the Rust and Kotlin ones beside them coloured normally. All four grammars already ship in `highlight`, so this is imports plus map entries. Ruby and Groovy come along because the same decks quote podspecs and Gradle Groovy build files, which had been falling back to `text` for the same reason. Placement keeps every existing entry in its current relative order and puts each new one next to its nearest relative — Ruby by Python, Groovy by Java, Swift by Kotlin, Objective-C ahead of C. The two lists and the grammar map stay in the lockstep the component test already asserts. The cost is bundle weight, as the header in `code_highlighting.dart` notes: 31 KB of additional grammar source, against 102 KB already imported. `code_highlighting_test.dart` gains a round-trip check per grammar. `highlightedCodeSpan` silently returns plain text when a grammar drops or duplicates a character, and a silent fallback is indistinguishable from the grey rendering this commit removes — so each test asserts both that the runs rejoin to the source exactly and that at least one run is coloured. Unregistering a grammar fails them. The notebook keeps its own smaller registry in `code_editor_config.dart`, deliberately untouched: those languages are the ones Judge0 can execute, and a notebook cell cannot run Swift. Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
project-halkyon/halkyon-learn!840
No description provided.