Code snippet
Syntax-highlighted source with copy-to-clipboard. Same WC powers the snippets across all three framework demos.
TypeScript (auto-detected)
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };Vue SFC (explicit language)
<script setup lang="ts">import { ref } from 'vue';const count = ref(0);</script><template> <button @click="count++">Clicked {{ count }} times</button></template>Line numbers
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };Theming
The block follows the page's data-bs-theme with no wiring. Pass theme to pin it instead.
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };Per-line annotations
Tab reaches the active line, then the arrow keys move between line links and Home / End jump to the ends. Each line number is a real link, so middle-click still opens it.
1interface User {2 id: number;3 name: string;4}56function greet(user: User): string {Branches: 1 of 2 taken7 return `Hello, ${user.name}!`;8}910export const me: User = { id: 1, name: 'Pieterjan' };Use the up and down arrow keys to move between line links, Home and End for the first and last line.
<BsCodeSnippet class="coverage" :code="source" language="ts" line-numbers :annotations="COVERAGE" :active-line="activeLine" :line-href="(line: number) => `#L${line}`" @line-activate="onLineActivate" /><!-- kind is opaque — colour it yourself: .coverage :deep(.annotation-uncovered) { background: rgb(220 53 69 / 16%); } -->Constrained size
Give the component a height or max-height and the listing scrolls vertically inside it; constrain the width and long lines scroll horizontally.
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };<BsCodeSnippet class="sized-snippet" :code="source" language="ts" line-numbers /><!-- .sized-snippet { max-height: 220px; } — the code area scrolls inside it. -->Usage
<script setup lang="ts">import { BsCodeSnippet } from '@mintplayer/vue-bootstrap/code-snippet';</script><template> <BsCodeSnippet language="tsx" :code="`const greet = (n: string) => \`hi, ${n}\`;`" /></template>