Vue 3 CodeBlock
by WebDevNerdStuff
v2.3.5
PrismJS
Neon Bunny
This will also update the examples and documentation below.
# Description
The Vue 3 CodeBlock component leverages the power of PrismJS or Highlight.js to provide syntax highlighting for code blocks within your application. The component takes a prop, which is the code to be highlighted, and uses PrismJS or Highlight.js to render the code with syntax highlighting. The component supports a variety of programming languages and can be customized with different themes to match your application's design. With this component, your users can display their code snippets with ease and clarity, making it easier to share and collaborate on code within your application.
# Usage
Global Plugin Registration
Global options have a higher precedence and will override local props
Global options have a higher precedence and will override local props
import { createApp } from 'vue';
import App from './App.vue';
import { createVCodeBlock } from '@wdns/vue-code-block';
const VCodeBlock = createVCodeBlock({
// options
});
const app = createApp(App);
app.use(VCodeBlock);
app.mount('#app');
Global Component Registration
import { createApp } from 'vue';
import App from './App.vue';
import { VCodeBlock } from '@wdns/vue-code-block';
const app = createApp(App);
app.component('VCodeBlock', VCodeBlock);
app.mount('#app');
Local Registration
<template>
<VCodeBlock
:code="code"
highlightjs
label="Hello World"
lang="javascript"
theme="neon-bunny"
/>
</template>
<script setup>
import VCodeBlock from '@wdns/vue-code-block';
const code = ref(`const foo = 'bar';`);
</script>
# Props
Name | Type | Default | Description | ||||
---|---|---|---|---|---|---|---|
#browserWindow | boolean | false | To give the code block a browser window look. | ||||
#code | object | string | number | The code to be displayed in the code block. | |||||
#codeBlockRadius | string | 0.5rem | The border radius of the code block. | ||||
#copyButton | boolean | true | To show a copy button within the code block. | ||||
#copyFailedText | string | Copy failed! | The text to be displayed when the code copy failed. | ||||
#copyIcons | boolean | true | To show the copy icons on the copy code tab. | ||||
#copySuccessText | string | Copied! | The text to be displayed when the code copy was successful. | ||||
#copyTab | boolean | true? | To show the copy code tab. | ||||
#copyText | string | Copy Code | The text to be displayed on the copy tab. | ||||
#cssPath | string | undefined | undefined | Used to load the css from a specified location instead of the component using the CDN location. If you want to dynamically change the theme, you will also need to change the theme prop. | ||||
#floatingTabs | boolean | true | To make the tabs float on top of the code block. | ||||
#height | string | number | auto | The height of the code block. | ||||
#highlightjs | boolean | false | Specifies that the Highlight.js library should be used. * Required if prismjs prop is not set. | ||||
#indent | number | 4 | The number of spaces to indent the code for json. | ||||
#label | string | The label to be displayed on the code block. | |||||
#lang | string | javascript | The language of the code. | ||||
#maxHeight | string | number | auto | The max height of the code block. | ||||
#persistentCopyButton | boolean | false | To show a persistent copy button within the code block. | ||||
#prismjs | boolean | true | Specifies that the PrismJS library should be used. * Required if highlightjs prop is not set. | ||||
#prismPlugin | boolean | false | Specifies that a PrismJS plugin is being used. This is needed for the plugin to work properly. | ||||
#runTab | boolean | false | To show the run tab. | ||||
#runText | string | Run | The text to be displayed on the run tab. | ||||
#tabGap | string | 0.25rem | The gap between the tabs. | ||||
#tabs | boolean | false | To show the tabs. This will show/hide all tabs. | ||||
#theme | string | boolean | neon-bunny | The theme to be used for the code block. Available options include:
Neon Bunny Themes
|
# Events
Name | Description |
---|---|
#run | The event emitted when the run tab is clicked. |
#update:copy-status | The event emitted when the copy status is updated. |
# Slots
Name | Description |
---|---|
#copyButton | Slot for the copy button inside the code block of the component. |
| |
#label | Slot for the label of the component. |
| |
#tabs | Slot for the tabs of the component. |
|
# Examples
Languages
JavaScript
// Example 1: Creating an array of numbers and finding the sum
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((total, num) => total + num);
console.log(sum); // Output: 15
// Example 2: Converting a string to uppercase
const greeting = 'hello world';
const uppercaseGreeting = greeting.toUpperCase();
console.log(uppercaseGreeting); // Output: HELLO WORLD
// Example 3: Generating a random number between 1 and 10
const randomNumber = Math.floor(Math.random() * 10) + 1;
console.log(randomNumber); // Output: A random number between 1 and 10
// Example 4: Checking if a number is even or odd
const num = 4;
if (num % 2 === 0) {
console.log('Even');
} else {
console.log('Odd');
} // Output: Even
// Example 5: Fetching data from an API
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
// Output: The JSON data for the TODO with ID 1 from the API
Vue (using lang = html)
<template>
<div>
<h1>{{ greeting }}</h1>
</div>
</template>
<script setup>
import { ref } from 'vue';
const greeting = ref('Hello, World!');
</script>
CSS
/**
* MIT License
* Copyright (c) 2023 WebDevNerdStuff
* WebDevNerdStuff Neon Bunny
* VSCode Theme: https://marketplace.visualstudio.com/items?itemName=WebDevNerdStuff.neon-bunny
*/
:root {
--neon-bunny-blue-light: #2492ff;
--neon-bunny-blue: #0b93ff;
--neon-bunny-gray-lighter: #aaa;
--neon-bunny-gray: #7f817e;
--neon-bunny-green-darker-darker: #008b05;
--neon-bunny-green-darker: #2bb71d;
--neon-bunny-green-light: #2bb71d;
--neon-bunny-green-neon: #0aff04;
--neon-bunny-green: #00d205;
--neon-bunny-lime-lighter: #c3e88d;
--neon-bunny-lime: #b2ff02;
--neon-bunny-magenta: #df00df;
--neon-bunny-neon-green: #00ff00;
--neon-bunny-orange: #e58100;
--neon-bunny-peach-darker: #ffb46a;
--neon-bunny-peach-light: #ffe4a6;
--neon-bunny-peach: #ffcb6b;
--neon-bunny-pink: #ff1190;
--neon-bunny-purple-light-dim: #c792ea;
--neon-bunny-purple-light: #d285cc;
--neon-bunny-purple: #ea03ff;
--neon-bunny-red: #ff3229;
--neon-bunny-salmon: #ff6f5b;
--neon-bunny-teal: #80fcff;
--neon-bunny-white: #fff;
--neon-bunny-yellow: #fef611;
/* Standard */
--neon-bunny-atrule: var(--neon-bunny-peach);
--neon-bunny-attr-name: var(--neon-bunny-purple-light-dim);
--neon-bunny-attr-value: var(--neon-bunny-peach);
--neon-bunny-boolean: var(--neon-bunny-blue-light);
--neon-bunny-builtin: var(--neon-bunny-purple);
--neon-bunny-cdata: var(--neon-bunny-gray);
--neon-bunny-char: var(--neon-bunny-pink);
--neon-bunny-class-name: var(--neon-bunny-peach);
--neon-bunny-comment: var(--neon-bunny-gray);
--neon-bunny-constant: var(--neon-bunny-green-darker);
--neon-bunny-deleted: var(--neon-bunny-red);
--neon-bunny-entity: var(--neon-bunny-peach);
--neon-bunny-function: var(--neon-bunny-green-neon);
--neon-bunny-important: var(--neon-bunny-red);
--neon-bunny-inserted: var(--neon-bunny-lime-lighter);
--neon-bunny-keyword: var(--neon-bunny-blue);
--neon-bunny-namespace: var(--neon-bunny-peach);
--neon-bunny-number: var(--neon-bunny-white);
--neon-bunny-operator: var(--neon-bunny-blue-light);
--neon-bunny-prolog: var(--neon-bunny-gray);
--neon-bunny-property: var(--neon-bunny-pink);
--neon-bunny-punctuation: var(--neon-bunny-blue);
--neon-bunny-regex: var(--neon-bunny-peach-light);
--neon-bunny-string: var(--neon-bunny-green-darker);
--neon-bunny-symbol: var(--neon-bunny-pink);
--neon-bunny-tag: var(--neon-bunny-blue-light);
--neon-bunny-url: var(--neon-bunny-orange);
--neon-bunny-variable: var(--neon-bunny-green-darker);
/* HTML */
--neon-bunny-html-attr-name: var(--neon-bunny-green);
--neon-bunny-html-attr-value-punctuation: var(--neon-bunny-peach-darker);
--neon-bunny-html-attr-value: var(--neon-bunny-peach-darker);
/* CSS */
--neon-bunny-css-atrule-rule: var(--neon-bunny-blue);
--neon-bunny-css-atrule: var(--neon-bunny-white);
--neon-bunny-css-function: var(--neon-bunny-orange);
--neon-bunny-css-property: var(--neon-bunny-pink);
--neon-bunny-css-punctuation: var(--neon-bunny-white);
--neon-bunny-css-selector: var(--neon-bunny-lime);
--neon-bunny-css-string: var(--neon-bunny-green-light);
--neon-bunny-css: var(--neon-bunny-purple-light-dim);
/* JS */
--neon-bunny-js-keyword: var(--neon-bunny-blue);
--neon-bunny-js-literal-property: var(--neon-bunny-neon-green);
--neon-bunny-js-operator: var(--neon-bunny-blue-light);
--neon-bunny-js-punctuation: var(--neon-bunny-white);
--neon-bunny-js-string: var(--neon-bunny-green-darker-darker);
--neon-bunny-js-template-string-string: var(--neon-bunny-green-darker-darker);
--neon-bunny-js: var(--neon-bunny-green-darker);
/* PHP */
--neon-bunny-php-boolean: var(--neon-bunny-blue);
--neon-bunny-php-class-name-definition-class-name: var(--neon-bunny-magenta);
--neon-bunny-php-class-name-return-type: var(--neon-bunny-gray-lighter);
--neon-bunny-php-class-name: var(--neon-bunny-teal);
--neon-bunny-php-double-quote-string: var(--neon-bunny-salmon);
--neon-bunny-php-function: var(--neon-bunny-green-neon);
--neon-bunny-php-keyword-type-hint: var(--neon-bunny-gray-lighter);
--neon-bunny-php-keyword: var(--neon-bunny-blue);
--neon-bunny-php-operator: var(--neon-bunny-purple);
--neon-bunny-php-package: var(--neon-bunny-peach);
--neon-bunny-php-property: var(--neon-bunny-purple-light);
--neon-bunny-php-punctuation: var(--neon-bunny-white);
--neon-bunny-php-single-quote-string: var(--neon-bunny-yellow);
--neon-bunny-php-variable: var(--neon-bunny-purple-light);
}
code[class*="language-"],
pre[class*="language-"] {
-moz-hyphens: none;
-moz-tab-size: 4;
-ms-hyphens: none;
-o-tab-size: 4;
-webkit-hyphens: none;
color: var(--neon-bunny-white);
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
font-size: 1em;
hyphens: none;
line-height: 1.5;
tab-size: 4;
text-align: left;
white-space: pre;
word-break: normal;
word-spacing: normal;
word-wrap: normal;
}
pre[class*="language-"]::-moz-selection,
pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection,
code[class*="language-"] ::-moz-selection {
background: rgba(29, 59, 83, 0.99);
text-shadow: none;
}
pre[class*="language-"]::selection,
pre[class*="language-"] ::selection,
code[class*="language-"]::selection,
code[class*="language-"] ::selection {
background: #ffffff15;
text-shadow: none;
}
@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}
/* Code blocks */
pre[class*="language-"] {
margin: 0.5em 0;
overflow: auto;
padding: 1em;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #000000;
color: white;
}
:not(pre) > code[class*="language-"] {
border-radius: 0.3em;
padding: 0.1em;
white-space: normal;
}
/* -------------------------------------------------- Standard */
.token.atrule {
color: var(--neon-bunny-atrule);
}
.token.attr-name {
color: var(--neon-bunny-attr-name);
}
.token.attr-value {
color: var(--neon-bunny-attr-value);
}
.token.bold {
font-weight: bold;
}
.token.boolean {
color: var(--neon-bunny-boolean);
}
.token.builtin {
color: var(--neon-bunny-builtin);
}
.token.cdata {
color: var(--neon-bunny-cdata);
font-style: italic;
}
.token.char {
color: var(--neon-bunny-char);
}
.token.class-name {
color: var(--neon-bunny-class-name);
}
.token.constant {
color: var(--neon-bunny-constant);
}
.token.comment {
color: var(--neon-bunny-comment);
font-style: italic;
}
.token.deleted {
color: var(--neon-bunny-deleted);
}
.token.entity {
color: var(--neon-bunny-entity);
}
.token.function {
color: var(--neon-bunny-function);
}
.token.important {
color: var(--neon-bunny-important);
font-style: italic;
}
.token.inserted {
color: var(--neon-bunny-inserted);
}
.token.italic {
font-style: italic;
}
.token.keyword {
color: var(--neon-bunny-keyword);
}
.namespace {
color: var(--neon-bunny-namespace);
}
.token.number {
color: var(--neon-bunny-number);
}
.token.operator {
color: var(--neon-bunny-operator);
}
.token.prolog {
color: var(--neon-bunny-prolog);
font-style: italic;
}
.token.property {
color: var(--neon-bunny-property);
}
.token.punctuation {
color: var(--neon-bunny-punctuation);
}
.token.regex {
color: var(--neon-bunny-regex);
}
.token.string {
color: var(--neon-bunny-string);
}
.token.symbol {
color: var(--neon-bunny-symbol);
}
.token.tag {
color: var(--neon-bunny-tag);
}
.token.url {
color: var(--neon-bunny-url);
text-decoration: underline;
}
.token.variable {
color: var(--neon-bunny-variable);
}
/* -------------------------------------------------- HTML */
.language-html .token.attr-name {
color: var(--neon-bunny-html-attr-name);
}
.language-html .token.attr-value {
color: var(--neon-bunny-html-attr-value);
}
.language-html .token.attr-value .token.punctuation {
color: var(--neon-bunny-html-attr-value-punctuation);
}
/* -------------------------------------------------- CSS */
.language-css {
color: var(--neon-bunny-css) !important;
}
.language-css .token.atrule {
color: var(--neon-bunny-css-atrule);
}
.language-css .token.atrule .token.rule {
color: var(--neon-bunny-css-atrule-rule);
}
.language-css .token.function {
color: var(--neon-bunny-css-function);
}
.language-css .token.property {
color: var(--neon-bunny-css-property);
}
.language-css .token.punctuation {
color: var(--neon-bunny-css-punctuation);
}
.language-css .token.selector {
color: var(--neon-bunny-css-selector);
}
.language-css .token.string,
.style .token.string {
color: var(--neon-bunny-css-string);
font-style: italic;
}
/* -------------------------------------------------- JavaScript */
.language-javascript,
.language-js {
color: var(--neon-bunny-js) !important;
font-style: italic;
}
.language-javascript span,
.language-js span {
font-style: normal;
}
.language-javascript .token.keyword,
.language-js .token.keyword {
color: var(--neon-bunny-js-keyword);
}
.language-javascript .token.literal-property.property,
.language-js .token.literal-property.property {
color: var(--neon-bunny-js-literal-property);
font-style: italic;
}
.language-javascript .token.operator,
.language-js .token.operator {
color: var(--neon-bunny-js-operator);
font-style: italic;
}
.language-javascript .token.punctuation,
.language-js .token.punctuation {
color: var(--neon-bunny-js-punctuation);
}
.language-javascript .token.template-string .token.string,
.language-js .token.template-string .token.string {
color: var(--neon-bunny-js-template-string-string);
}
/* -------------------------------------------------- PHP */
.language-php .token.boolean {
color: var(--neon-bunny-boolean);
}
.language-php .token.class-name {
color: var(--neon-bunny-php-class-name);
}
.language-php .token.class-name-definition.class-name {
color: var(--neon-bunny-php-class-name-definition-class-name);
}
.language-php .token.class-name.return-type {
color: var(--neon-bunny-php-class-name-return-type);
font-style: italic;
}
.language-php .token.function {
color: var(--neon-bunny-php-function);
}
.language-php .token.keyword {
color: var(--neon-bunny-php-keyword);
}
.language-php .token.keyword.type-hint {
color: var(--neon-bunny-php-keyword-type-hint);
font-style: italic;
}
.language-php .token.operator {
color: var(--neon-bunny-php-operator);
}
.language-php .token.package {
color: var(--neon-bunny-php-package);
}
.language-php .token.property {
color: var(--neon-bunny-php-property);
}
.language-php .token.punctuation {
color: var(--neon-bunny-php-punctuation);
}
.language-php .token.string.double-quoted-string {
color: var(--neon-bunny-php-double-quote-string);
}
.language-php .token.string.single-quoted-string {
color: var(--neon-bunny-php-single-quote-string);
}
.language-php .token.variable {
color: var(--neon-bunny-php-variable);
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Google tag (gtag.js) -->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue 3 CodeBlock</title>
<meta name="description"
content="Vue 3 CodeBlock - Highlight your code with ease using this
syntax highlighting component powered by PrismJS or Highlight.js." />
<meta name="keywords"
content="vue-code-block, code, pre, highlight, syntax, vue, vue3,
component, javascript, neon bunny, webdevnerdstuff, wdns" />
<meta name="author" content="WebDevNerdStuff & Bunnies... lots and lots
of bunnies!" />
<meta name="robots" content="index, follow" />
<meta name="googlebot" content="index, follow" />
<meta name="theme-color" content="#f01d7f" />
<meta property="og:locale" content="en_US">
<meta property="og:type" content="website">
<meta property="og:title" content="Vue 3 CodeBlock">
<meta property="og:description"
content="Vue 3 CodeBlock - Highlight your code with ease using this
syntax highlighting component powered by PrismJS or Highlight.js.">
<meta property="og:url" content="https://webdevnerdstuff.github.io/vue-code-block/">
<meta property="og:image" content="https://webdevnerdstuff.github.io/vue-code-block/vue-code-block-social.jpg">
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Henny+Penny&family=Indie+Flower&display=swap" rel="stylesheet">
<link rel="icon" type="image/svg+xml" href="/vue.svg" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
SVG
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img"
class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198">
<path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path>
<path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path>
<path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path>
</svg>
Additional Languages
PrismJS does not load all languages by default. In order to use additional languages you will need to import that languages component.
Example of using PrismJS to highlight TypeScript
<template>
<VCodeBlock
:code="myCode"
lang="typescript"
prismjs
/>
</template>
<script setup>
import Prism from 'prismjs';
import 'prismjs/components/prism-typescript';
</script>
TypeScript
class Person {
private name: string;
private age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
public sayHello() {
console.log(`Hello, my name is ${this.name} and I'm ${this.age} years old.`);
}
}
const person = new Person("John Doe", 30);
person.sayHello();
Example of using undefined to highlight JSON
<template>
<VCodeBlock
:code="myCode"
:indent="2"
lang="json"
prismjs
/>
</template>
<script setup>
import Prism from 'prismjs';
import 'prismjs/components/prism-json';
</script>
JSON
{
"name": "John Doe",
"age": 30,
"isMarried": false,
"hobbies": [
"reading",
"hiking",
"coding"
],
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
}
Example of using undefined to highlight PHP
<template>
<VCodeBlock
:code="myCode"
lang="php"
prismjs
/>
</template>
<script setup>
import Prism from 'prismjs';
import 'prismjs/components/prism-markup-templating';
import 'prismjs/components/prism-php';
</script>
PHP
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Inertia\Inertia;
use Illuminate\Http\JsonResponse;
use App\HttpControllers\Controller;
use App\HttpRequests\DestroyUserRequest;
use App\HttpRequests\StoreUserRequest;
use App\HttpRequests\UpdateUserRequest;
use App\HttpResources\UserResource;
class UserController extends Controller
{
/**
* Users
*
* @return \Inertia\Response
*/
public function index()
{
$users = User::get();
return Inertia::render('Users/Index', [
'currentPage' => 'Site Options',
'users' => $users,
]);
}
/**
* Store User.
*
*/
public function store(StoreUserRequest $request): JsonResponse
{
$validated = $request->validated();
$user = [
'name' => $validated['name'],
'email' => $validated['email'],
];
$user = User::create($user);
$response = [
'err' => !$user,
'msg' => $user ? 'success' : 'error',
'user' => new UserResource($user),
];
return response()->json($response);
}
/**
* Update User
*/
public function update(UpdateUserRequest $request, User $userModel): JsonResponse
{
$validated = $request->validated();
$user = $userModel->withTrashed()->find($validated['id']);
$user->updated_by = auth()->id();
if ($validated['deletedAt'] === 'activate')
{
$user->restore();
}
else
{
$user->name = $validated['name'];
$user->email = $validated['email'];
$user->update($validated);
}
$response = [
'err' => !$user,
'msg' => $user ? 'success' : 'error',
'siteOption' => new UserResource($user),
];
return response()->json($response);
}
/**
* Remove User
*/
public function destroy(DestroyUserRequest $request, User $userModel): JsonResponse
{
$validated = $request->validated();
$user = $userModel->findOrFail($validated['id']);
$user->updated_by = auth()->id();
$results = $user->delete();
return response()->json([
'err' => !$results,
'status' => $results ? 'success' : 'error',
'siteOption' => new UserResource($user),
]);
}
}
?>
Plugins
PrismJS does not load all plugins by default. In order to use additional plugins you will need to import them. Please note that not all plugins may work with this component.
Example using the line-numbers Plugin
<template>
<VCodeBlock
class="line-numbers"
:code="pluginExample"
label="line-numbers"
lang="html"
prism-plugin
prismjs
/>
</template>
<script setup>
import 'prismjs/plugins/line-numbers/prism-line-numbers.js';
import 'prismjs/plugins/line-numbers/prism-line-numbers.css';
</script>
Tabs
Copy Code Tab
<VCodeBlock
:code="myCode"
copy-tab
label="Copy Code Tab"
lang="javascript"
prismjs
:run-tab="false"
tabs
/>
Run Code Tab
<template>
<VCodeBlock
:code="myCode"
:copy-tab="false"
label="Run Code Tab"
lang="javascript"
prismjs
run-tab
tabs
@run="runMyCodeFunction"
/>
</template>
<script setup>
function runMyCodeFunction() {
const message = 'Run Code Tab';
alert(message);
}
</script>
Copy & Run Code Tabs
<template>
<VCodeBlock
:code="myCode"
label="Copy & Run Code Tabs"
lang="javascript"
prismjs
:run-tab="true"
tabs
@run="runMyOtherCodeFunction"
/>
</template>
<script setup>
function runMyCodeFunction() {
const message = 'bar';
alert(message);
}
</script>
Copy Button
Visible on hover
<VCodeBlock
:code="myCode"
label="Visible on hover"
lang="html"
prismjs
/>
Persistent Copy Button
<VCodeBlock
:code="myCode"
label="Persistent Copy Button"
lang="html"
persistent-copy-button
prismjs
/>
Browser Window
<VCodeBlock
:browser-window="true"
:code="myCode"
lang="javascript"
prismjs
/>
Other Prop Examples
codeBlockRadius:
<VCodeBlock
:code="myCode"
:code-block-radius="codeBlockRadius"
lang="html"
prismjs
>
<template #label>
codeBlockRadius:
<input v-model="codeBlockRadius" type="text" />
</template>
</VCodeBlock>
copyText:
<VCodeBlock
:code="myCode"
copy-tab
:copyText="copyText"
lang="html"
prismjs
tabs
>
<template #label>
copyText:
<input v-model="copyText" type="text" />
</template>
</VCodeBlock>
runText:
<VCodeBlock
:code="runTextExample"
:copy-tab="false"
lang="html"
run-tab
:runText="runText"
prismjs
tabs
:theme="selectedTheme"
@run="runTextCodeExampleFunction"
>
<template #label>
runText:
<input v-model="runText" type="text" />
</template>
</VCodeBlock>
<VCodeBlock
:code="exampleCode"
:floating-tabs="floatingTabs"
lang="html"
prismjs
tabs
>
<template #label>
<input
v-model="floatingTabs"
checked
type="checkbox"
/>
<label>
floatingTabs =
<span class="boolean-style">{{ floatingTabs }}</span>
</label>
</template>
</VCodeBlock>
height:
<VCodeBlock
:code="myCode"
:height="height"
lang="html"
prismjs
>
<template #label>
height:
<input v-model="height" type="number" />
</template>
</VCodeBlock>
tabGap:
<VCodeBlock
:code="myCode"
lang="html"
:run-tab="true"
prismjs
:tab-gap="tabGap"
tabs
>
<template #label>
tabGap:
<input v-model="tabGap" type="text" />
</template>
</VCodeBlock>
indent (json):
{
"name": "John Doe",
"age": 30,
"isMarried": false,
"hobbies": [
"reading",
"hiking",
"coding"
],
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
}
# Developer Playground
Setup the Playground
First clone the repository:
git clone git@github.com:webdevnerdstuff/vue-code-block.git
Next run the following command to setup the Playground:
pnpm i && pnpm play
This will create a file for you to adjust and play with.
/src/playground/PlaygroundPage.vue