Skip to content
Components

Code block

Source snippets with copying, optional highlighting and collapsible long content.

After the one-time setup, call the helper directly from ERB. No component import is needed.

<%= lc_code_block "def hello(name)\n  puts name\nend", id: "my-component-ruby", language: :ruby, label: "Ruby greeting", class: "w-full" %>
def hello(name)
  puts name
end
<%= lc_code_block "def hello(name)\n  puts name\nend", id: "example-0-ruby", language: :ruby, label: "Ruby greeting", class: "w-full" %>
app/helpers/greeting_helper.rb
def hello(name)
  puts name
end
<%= lc_code_block "def hello(name)\n  puts name\nend", id: "example-1-file", language: :ruby, title: "app/helpers/greeting_helper.rb", label: "Greeting helper", class: "w-full" %>
puts 1
puts 2
puts 3
puts 4
puts 5
puts 6
puts 7
puts 8
puts 9
puts 10
puts 11
puts 12
puts 13
puts 14
puts 15
<%= lc_code_block (1..15).map { |number| "puts #{number}" }.join("\n"), id: "example-2-long", language: :ruby, label: "Long Ruby snippet", max_lines: 5, class: "w-full" %>

Helpers render semantic HTML and include their interaction wiring. Pass native attributes through class:, data:, aria: and the usual Rails options. Blocks use captured ERB content.

lc_code_block

lc_code_block(source, id:, language: nil, title: nil, label: nil, max_lines: 10, **attributes, &block)
InputDefaultValues
sourceRequired—
idRequired—
languagenil—
titlenil—
labelnilAccessible name, visible where applicable
max_lines10—
attributes{}Native HTML attributes; class:, data: and aria: merge with defaults
blockCaptured blockCaptured Rails ERB content

Styling and extension

Use class: to merge utilities, native attributes for application behavior, and the theming guide for the shared palette. For custom markup, the advanced class helpers expose the same styles, including glass surfaces and class merging.

API JSON · LLM reference