Search documentation

Find a component or a docs page

Codeblock

Displays a block of code with syntax highlighting and a copy button.

Setup

Syntax colors come from CodeblockTheme, Rouge's GitHub theme in light and dark. Render it once in the head of your layout: render RubyUI::CodeblockTheme.new

Usage

Example

Without copy button

Line numbers

Diff

Mark lines with variant: :added, :removed or :highlighted.

Wrap

Long lines wrap instead of scrolling sideways.

Small

Destructive

Custom copy message

Copy the code to hear the message with a screen reader.

Installation

Components

ComponentBuilt usingSource
CodeblockPhlex
CodeblockActionsPhlex
CodeblockContentPhlex
CodeblockCopyButtonPhlex
CodeblockDocsPhlex
CodeblockFooterPhlex
CodeblockHeaderPhlex
CodeblockLinePhlex
CodeblockThemePhlex
CodeblockTitlePhlex
CodeblockControllerStimulus JS