Shiki-powered syntax-highlighted code block with optional line numbers, line highlighting, copy button, filename header, compact pill mode and theme awareness. Supports 14 languages and honours the active Origam theme.
Aperçu
Rendu de l’aperçu en cours…
default
Rendu de l’aperçu en cours…
compact
Rendu de l’aperçu en cours…
with filename
Structure
Anatomie
Décomposition visuelle de la structure interne du composant avec les appels de classes BEM.
Anatomy of <origam-code> — 6 internal parts. Root is <figure> for W3C correctness.
1.origam-code
Root element (default tag: ). Carries display, background, border, font-family and overflow tokens.
2.origam-code__header
Header bar rendered when filename is set. Contains the filename badge or lang badge and the copy button.
3.origam-code__copy
OrigamBtn copy button. Positioned in the header (--header), floating top-right (--floating) or inline in compact mode (--compact).
4.origam-code__scroller
Scrollable area wrapping the
pair. flex: 1 1 auto in non-compact mode so it fills a constrained height.
5.origam-code__pre / .origam-code__code
semantic pair. The element carries data-lang and receives the shiki-highlighted innerHTML.
6.origam-code__footer
API
Props
Toutes les props acceptées par ce composant, avec leur type, valeur par défaut et description.
code
string
Code to highlight. When omitted, the default slot is used as the source. When both are provided, the prop wins.
Language grammar to apply. Supported: 'plaintext' | 'vue' | 'ts' | 'js' | 'tsx' | 'jsx' | 'scss' | 'css' | 'json' | 'bash' | 'html' | 'xml' | 'yaml' | 'md'. Unknown values fall back to plaintext.
lineNumbers
boolean
false
Shows a left gutter with line numbers. Pure CSS counter — no JS layout work.
highlightLines
number[] | string | null
null
Lines to highlight. Accepts a 1-based array ([2, 5, 6]) or a range string ('2,5-7'). Null/empty disables.
copyable
boolean
true
Shows the copy-to-clipboard button. True by default — most code blocks benefit from it.
format
boolean
false
Auto-format the code before highlighting. Reserved — currently a no-op that warns in dev mode. Prettier is not bundled at runtime to keep the tarball small.
wrap
boolean
false
Wraps long lines instead of scrolling horizontally.
filename
string
Optional filename rendered in the header bar (e.g. 'App.vue'). When present AND copyable=true, the header hosts the copy button; otherwise the copy button floats in the top-right corner.
compact
boolean
false
Renders as a single-line inline pill (ideal for install commands). Header, filename and line numbers are suppressed; the copy button collapses to a small icon.
prompt
string
Decorative prefix rendered before the code (e.g. '$' for shell commands). Purely visual — not copied to clipboard.
hideHeader
boolean
Do not render the header bar (filename / language badge / copy button). For a block embedded in a surface that already shows that information, such as a tab of OrigamCodeGroup.
flat
boolean
Flatten the block into its host: no border, no radius, no elevation, no outer margin.
scrollerAriaLabel
string
Accessible name of the scrollable region. Left out, it is derived from filename, then lang. Set it when several blocks of the same language share a page.
id
string
class
string | Array<string> | object
style
string | Array<string> | object | StyleValue
tag
string
'figure'
Root HTML element. Defaults to <figure> for semantic correctness.
border
boolean | number | string | TDirectionBoth | Array<TDirectionBoth>
Replaces the default header bar (filename/lang badge + copy button). Receives filename, lang name, the copy function and the copied flag.
#footer—
Content appended after the code block inside a <footer> element.
#default—
Source code as slot text. Used when the code prop is absent. Whitespace is preserved.
API
Emits
Événements émis par ce composant.
@copy
string
API
Membres exposés
Propriétés et méthodes accessibles via ref template (defineExpose). Utilisés pour le contrôle programmatique.
() => void
Force re-highlights the code. Useful when the theme changes or the code prop is mutated without Vue reactivity.
Ref<boolean>
True for feedbackDuration ms after a successful copy.
Ref<HTMLElement | undefined>
Template ref pointing to the inner <code> element. Useful for external syntax processing or DOM inspection.
Personnalisation
Variables CSS
Propriétés CSS personnalisées exposées par ce composant. Surchargez-les pour personnaliser sans perdre la compatibilité avec le thème.
Code block background colour.
Default foreground colour for non-highlighted tokens.
Border radius.
Monospace font stack.
Font size.
Line height of code rows.
Vertical padding inside the code surface.
Horizontal padding inside the code surface.
Header bar background.
Background of highlighted lines.
API
Composable
Lazily instantiates a shiki highlighter singleton on first call and reuses it across every OrigamCode instance. Exposes highlight(), prime(), isReady() and resetCacheForTesting().
Signature
typescript
Utilisation
vue
Inclusion
Accessibilité
Rôles ARIA, navigation clavier et gestion du focus. Sourcé depuis le template réel du composant.
Rôles ARIA
figure
Interactions clavier
Interactions clavier
Touche
Action
Tab
Moves focus to the copy button when copyable=true.
Enter / Space
Triggers the copy action on the focused copy button.
Notes
Root element defaults to <figure> for W3C correctness. The code block is rendered inside <pre><code data-lang="..."> which gives screen readers proper semantic context.
The copy button aria-label and aria-live="polite" are set so screen readers announce "Copied" after a successful write without interrupting the current reading.
The prompt prefix (<span aria-hidden="true">) is decorative — it is never read aloud and is never included in the clipboard payload.
The scrollable code area is focusable via keyboard when content overflows, allowing keyboard users to scroll horizontally.
Fondation
Design tokens
Extrait des tokens de ce composant — les variables --origam-<composant>---<propriété>, déclarées dans sa feuille de tokens tenue à la main, sans étape de build.
Source
color
var(--origam-color__surface---raised)
Block background.
dimension
var(--origam-radius---md)
Corner radius.
fontFamily
var(--origam-font__family---mono)
Monospace font stack.
dimension
var(--origam-font__size---sm)
Font size.
color
var(--origam-color__feedback--warning---bgSubtle)
Highlighted line background.
Interactif
Playground
Modifiez les props en direct et observez le composant se mettre à jour. Le snippet de code généré suit vos changements.
Rendu de l’aperçu en cours…
Usage
Exemples
Extraits de code prêts à coller dans vos templates.
Basic code block
vue
Compact install command
vue
Line highlighting
vue
Écosystème
Éléments liés
Composants et directives d'autres dossiers qui collaborent avec celui-ci.