Skip to content

Feat: single runnable code block plugin for the editor - #56

Merged
khanzadimahdi merged 1 commit into
mainfrom
feat/runnable-code-block-plugin
Aug 3, 2026
Merged

Feat: single runnable code block plugin for the editor#56
khanzadimahdi merged 1 commit into
mainfrom
feat/runnable-code-block-plugin

Conversation

@khanzadimahdi

Copy link
Copy Markdown
Member

Summary

Combines the code block feature and the separate "executable" runtime dropdown into one CKEditor plugin, adds a proper settings panel for code blocks, and makes snippets runnable inside the editor — not just in the published article.

The plugin requires CodeBlockEditing and registers its own codeBlock toolbar item (split button: insert + language list + "Code block settings"), so CodeBlock and the second executable toolbar entry are gone from the editor config. The old executable-code-block-plugin.ts is deleted.

Component settings

A contextual balloon follows the caret into any code block:

Language ▾        Runtime ▾
(toggle) Editable code        [▶ Run]     ← only with a runtime
─────────────────────────────────────
Program output:                     ✕
  …
  • Language and Runtime as bordered input-like dropdowns showing their current value.
  • Editable code — off by default, and only meaningful with a runtime: the row appears when one is chosen, and clearing the runtime clears the flag.
  • Run + output, going through the same runCode WebSocket call the published page uses (wired via the new runnableCodeBlock: { onRun, translate, direction } config).
  • Runnable blocks are labelled with their runtime next to the language label in the editing view.
  • Panel direction follows the app direction (useI18n()), since the panel is translated by the app dictionary while the CKEditor UI language stays en. New UI strings added to en.json / fa.json.

Published rendering

CodeHighlight now honours the flag: CodeMirror is read-only unless the block is runnable and marked editable; the reset control follows the same condition, and run controls key off the runtime rather than the mere presence of the attribute object.

Data contract

Unchanged and back-compatible: data-executable="<runtime>" plus the new data-executable-editable="true" on <code>, which the article body parser already maps to executable.editable. Upcast now migrates both into real model attributes — including legacy content carrying them on <pre> — and strips them from the General-HTML-Support bag so they are never written twice.

Testing

Verified in a headless CKEditor instance (jsdom): loading, both commands, panel bindings, running with output, and data round-tripping. <pre><code class="language-go" data-executable="go-1.24" data-executable-editable="true"> survives load→save byte-identically and unrelated GHS attributes are preserved. npm run build passes; the repo has no jest tests.

Not covered by that: real balloon positioning and pointer interaction in a browser — worth a quick manual pass in the dashboard editor.

🤖 Generated with Claude Code

Merges the code block feature and the separate "executable" runtime
dropdown into one CKEditor plugin. It requires CodeBlockEditing and
provides its own `codeBlock` toolbar item, so neither `CodeBlock` nor a
second toolbar entry is needed any more.

Code block settings now live in a contextual balloon that follows the
caret into any code block, holding the language, the runtime, and an
"editable code" toggle (off by default) that only applies once a runtime
is chosen. The same panel runs the snippet through the same WebSocket
channel the published article uses and shows its output, so authors can
try a block without leaving the editor. Runnable blocks are labelled
with their runtime next to the language label in the editing view.

Published articles honour the new flag: the CodeMirror editor is
read-only unless the block is runnable and marked editable.

The data contract is unchanged and back-compatible — `data-executable`
plus the new `data-executable-editable` on `<code>` — and upcast now
migrates those attributes into real model attributes, including legacy
content carrying them on `<pre>`, instead of leaving them to General
HTML Support.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@khanzadimahdi
khanzadimahdi merged commit c56d284 into main Aug 3, 2026
4 checks passed
@khanzadimahdi
khanzadimahdi deleted the feat/runnable-code-block-plugin branch August 3, 2026 12:07
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