x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<div class="p-8 max-w-2xl"> <article data-controller="midwest-card midwest-code-block" class="midwest-card padding-none midwest-code-block theme-rouge"> <div class="wrap"> <header class="flex px-4"> <div class="code-block-meta"> <span class="midwest-badge size-sm theme-primary"> <span class="value">ruby</span> </span> </div> <span class="midwest-tooltip" data-controller="midwest-tooltip"> <span id="tooltip-trigger-de68" class="midwest-tooltip-trigger" style="anchor-name: --tooltip-de68" data-action="mouseenter->midwest-tooltip#show mouseleave->midwest-tooltip#hide focus->midwest-tooltip#show blur->midwest-tooltip#hide" aria-describedby="tooltip-de68"> <button aria-label="Copy code" data-action="midwest-code-block#copy" class="midwest-button variant-ghost size-small theme-primary code-block-copy" name="button"> <span class="midwest-button-content"> <span class="copy-icon"> <div class="midwest-icon " aria-hidden="true"> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" aria-hidden="true"><path d="M368 48h-11.41a8 8 0 01-7.44-5.08A42.18 42.18 0 00309.87 16H202.13a42.18 42.18 0 00-39.28 26.92 8 8 0 01-7.44 5.08H144a64 64 0 00-64 64v320a64 64 0 0064 64h224a64 64 0 0064-64V112a64 64 0 00-64-64zm-48.13 64H192.13a16 16 0 010-32h127.74a16 16 0 010 32z"></path></svg> </div> </div> </span> <span class="check-icon"> <div class="midwest-icon " aria-hidden="true"> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M416 128L192 384l-96-96"></path></svg> </div> </div> </span> </span> <div class="midwest-loading-icon" role="img" aria-label="Loading" aria-hidden="true" style="display: none"> <div class="midwest-loading-icon-inner"> <!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL --> <svg viewbox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="Midwest-LoadingIcon__Svg" focusable="false" aria-hidden="true"> <circle cx="15" cy="15" r="15"> <animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate> </circle> <circle cx="60" cy="15" r="9" fill-opacity="0.3"> <animate attributename="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcmode="linear" repeatcount="indefinite"></animate> </circle> <circle cx="105" cy="15" r="15"> <animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate> </circle> </svg> </div> </div> </button> </span> <span id="tooltip-de68" popover="manual" role="tooltip" class="midwest-tooltip-popover placement-top" style="position-anchor: --tooltip-de68" data-midwest-tooltip-target="popover"> Copy code </span></span></header> <section> <div class="code-block-body" data-midwest-code-block-target="source"> <pre class="highlight"><code><span class="k">def</span> <span class="nf">fibonacci</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">return</span> <span class="n">n</span> <span class="k">if</span> <span class="n">n</span> <span class="o"><=</span> <span class="mi">1</span> <span class="n">fibonacci</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">fibonacci</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span><span class="k">end</span><span class="mi">10</span><span class="p">.</span><span class="nf">times</span> <span class="k">do</span> <span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="nb">puts</span> <span class="s2">"fib(</span><span class="si">#{</span><span class="n">i</span><span class="si">}</span><span class="s2">) = </span><span class="si">#{</span><span class="n">fibonacci</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="k">end</span></code></pre> </div> </section> </div> </article></div>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%sample_code = <<~RUBY def fibonacci(n) return n if n <= 1 fibonacci(n - 1) + fibonacci(n - 2) end 10.times do |i| puts "fib(\#{i}) = \#{fibonacci(i)}" endRUBYlang = (params[:language] || 'ruby').to_symcode_theme = (params[:code_theme] || 'rouge').to_symshow_lines = params[:line_numbers] == trueshow_copy = params[:copy] != falsefname = params[:filename].presence%><div class="p-8 max-w-2xl"> <%= render Midwest::CodeBlockComponent.new(sample_code, language: lang, theme: code_theme, line_numbers: show_lines, copy: show_copy, filename: fname) %></div>Playground
Explore the component with live parameters.
| Param | Description | Input |
|---|---|---|
|
Syntax highlighting language |
|
|
|
Color theme |
|
|
|
Show line numbers |
|
|
|
Show copy button |
|
|
|
Optional filename header |
|
No assets to display.
Add a .js or .css file alongside the component to see it here.
Figma embed for Code Block/playground
Annotate a preview to embed its Figma design here:
@figma "https://figma.com/..."