Skip to content

Implement CodeBlockNode component with textarea #276

Closed

Description

@malibio

Overview

Create dedicated CodeBlockNode component with textarea-based editing and language selection.

Parent Issue: #274 (Textarea migration)

Behavior

Auto-Detection Pattern

When TextNode content starts with ```:

  • Automatically convert TextNode → CodeBlockNode
  • Node type: code-block

Content Storage

Store complete fence syntax:
```javascript
const x = 1;
console.log(x);
```

Stored as-is in database.

Language Selection

  • UI dropdown for language selection (see docs/design-system/components.html → Code Block Nodes)
  • Automatically insert language in opening fence: ```javascript
  • Update content when language changes in dropdown

Closing Fence Behavior

  • Display uneditable closing ``` (visual indicator only)
  • User cannot edit/delete closing fence directly
  • Removing opening ``` deletes entire block → converts to TextNode

Multiline Support

  • Shift+Enter creates new lines within code block
  • Enter key at end of content creates new TextNode below

No Inline Formatting

  • Code blocks don't support inline markdown
  • Content displayed as-is (raw text)

Syntax Highlighting

  • Phase 1: No syntax highlighting (raw text display)
  • Phase 2 (future): Add syntax highlighting per language
  • Markdown code blocks: Show raw syntax, no rendering

Conversion Back to TextNode

When user removes opening ```:
```javascript → (removed) = CodeBlockNode → TextNode

Acceptance Criteria

  • Auto-detect ``` pattern and convert node type
  • Language dropdown UI matches design system
  • Store fence syntax with language in database
  • Uneditable closing fence displayed
  • Removing opening fence converts to TextNode
  • Multiline support (Shift+Enter)
  • Enter at end creates new TextNode below
  • No inline formatting support
  • Raw text display (no syntax highlighting yet)
  • Register CodeBlockNode in plugin system
  • Tests cover creation, editing, conversion

Design Reference

See docs/design-system/components.html → Code Block Nodes section.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions