Skip to content

Code Block

@astryxdesign/core v0.7.1 · CodeBlock

CodeBlock and SyntaxTheme are exported from @astryx-vue/core/Code. Inline Code, the tokenizer, and the copy helper are documented on the Code page.

CodeBlock props ​

NameTypeDefaultDescription
codestring—The read-only code. The copy button writes this string.
languagestring'plaintext'Tokenizer language. plaintext hides the language label.
syntaxThemeSyntaxThemeDefinition—Syntax colors for this block. Shorthand for wrapping it in SyntaxTheme.
titlestring—Filename or label in the header.
hasLanguageLabelbooleantrueWhether the language name appears in the header.
hasLineNumbersbooleanfalseWhether to draw a line number gutter.
highlightLinesnumber[]—One-indexed lines to emphasize. On a diff row, the highlight replaces the diff tint.
isDiffbooleanfalsePaint the snippet as a unified diff. Text after the glyph keeps the language syntax colors. Copy still writes the original string.
hasCopyButtonbooleantrueWhether to show the copy button.
isWrappedbooleanfalseWhether long lines wrap instead of scrolling sideways.
maxHeightnumber | string—Maximum height before the body scrolls. Numbers are pixels.
isCollapsiblebooleanfalseWhether the header can collapse the body once the line count reaches the threshold.
collapsibleThresholdnumber10Lines required before the collapse control appears.
size'sm' | 'md''md'Text size.
widthstring'fit-content'CSS width. 100% fills the parent.
container'card' | 'section''card'section drops the border, radius, and background.
tokenizer(code, language) => SyntaxToken[]—Custom tokenizer. Tokens use absolute offsets and do not replace the copied text.
highlightMode'auto' | 'ranges' | 'spans''auto'How tokens are painted.
copyLabelstring'Copy code'Accessible name of the copy control before a copy.
copiedLabelstring'Copied'Name and announcement after a successful copy.
codeLabelstring'Code'Accessible name of the code viewport.

CodeBlock events ​

  • copy: emitted after the code string was written to the clipboard.

SyntaxTheme ​

NameTypeDescription
themeSyntaxThemeDefinitionA preset or a defineSyntaxTheme() result. A [light, dark] tuple is stored as light-dark(). The component page is Syntax Theme.

The default slot is the content that should pick up those colors, usually one or more CodeBlocks.

githubDark sets --astryx-code-syntax-* and --astryx-code-block-background. A dark background also sets --astryx-code-block-border to white at 12% opacity. Diff colors are optional slots in that same list: added, removed, diff-header, added-marker, and removed-marker. When a syntax theme leaves them out, markers follow its punctuation color, the header row gets no extra paint, and the added and removed tints stay on the page theme's slots.