Components
Code
A readable code block in both themes.
Block#
import { initTheme } from '@originlabsbr/halora/theme';
// keep the key this site already uses
initTheme({ storageKey: 'theme' });
<figure class="ha-code" style="width:100%;margin:0">
<div class="ha-code__bar"><span>app.js</span></div>
<pre tabindex="0"><code><span class="ha-tok-keyword">import</span> <span class="ha-tok-punct">{</span> initTheme <span class="ha-tok-punct">}</span> <span class="ha-tok-keyword">from</span> <span class="ha-tok-string">'@originlabsbr/halora/theme'</span><span class="ha-tok-punct">;</span>
<span class="ha-tok-comment">// keep the key this site already uses</span>
<span class="ha-tok-function">initTheme</span><span class="ha-tok-punct">({</span> storageKey<span class="ha-tok-punct">:</span> <span class="ha-tok-string">'theme'</span> <span class="ha-tok-punct">});</span></code></pre>
</figure>Give the pre tabindex="0" so keyboard users can scroll long lines. Add your own copy button inside .ha-code__bar; this site uses an ha-icon-button.
Inline code#
Set data-theme on the root element.
<p>Set <code class="ha-inline-code">data-theme</code> on the root element.</p>Token classes#
| Class | Prism equivalent | Token |
|---|---|---|
ha-tok-keyword | .token.keyword, .tag, .selector | code-keyword |
ha-tok-string | .token.string, .attr-value | code-string |
ha-tok-function | .token.function, .class-name | code-function |
ha-tok-number | .token.number, .boolean | code-number |
ha-tok-constant | .token.property, .attr-name, .variable | code-constant |
ha-tok-comment | .token.comment | code-comment |
ha-tok-punct | .token.punctuation, .operator | code-punct |
Inside .ha-code, Prism and Gatsby Remark class names are styled too, so a Prism-based blog can adopt the colors without changing its markup.
Accessibility#
- Every token color reaches 4.5:1 on the code background in light and dark, for both brands. The contrast gate checks them.
- Never rely on color alone to carry meaning in code samples.