Alice committed 2024-06-01a1b2c
Codeblocks
A comprehensive demonstration of the code block component capabilities.
Themeing
The code block component supports custom theming via CSS variables. Below is an example of a VSCode-like theme definition that can be applied.
{
"--bg": "#1e1e1e",
"--primary": "#252526",
"--header-bg": "#252526",
"--border": "#333333",
"--text": "#d4d4d4",
"--line-number": "#858585",
"--tag": "#569cd6",
"--attr": "#9cdcfe",
"--string": "#ce9178",
"--punct": "#808080",
"--keyword": "#c586c0",
"--function": "#dcdcaa",
"--comment": "#6a9955",
"--number": "#b5cea8",
"--operator": "#d4d4d4",
"--button-bg": "#2d2d2d",
"--button-text": "#cccccc",
"--button-primary-bg": "#007acc",
"--button-primary-text": "#ffffff",
"--status-bar-bg": "#007acc",
"--error-color": "#f14c4c",
"--error-bg": "rgba(241, 76, 76, 0.1)",
"--error-text": "#cccccc",
"--scroll-track": "#1e1e1e",
"--scroll-thumb": "#424242",
"--fade-start": "rgba(30, 30, 30, 0)",
"--fade-end": "#1e1e1e",
"--terminal-rgb-bg": "30, 30, 30",
"--terminal-bg": "#1e1e1e",
"--terminal-text": "#d4d4d4",
"--terminal-green": "#6A9955",
"--terminal-red": "#F44747",
"--terminal-yellow": "#FFAF00",
"--terminal-blue": "#569CD6",
"--terminal-cyan": "#4EC9B0",
"--terminal-magenta": "#C586C0",
"--terminal-white": "#d4d4d4",
"--terminal-black": "#1e1e1e"
}VSCode Example Theme
function hello() {
return "World";
}
x = undefined;
Error: Variable not found
Warning: Check your variable usage
1. Minimal Configuration
Line numbers disabled, copy button hidden, status bar hidden.
txt
2. Language Highlighting
JavaScript
javascript
Vue
vue
3. Validation & Error Handling
The component automatically detects syntax errors for JSON and XML-like languages. Notice the red lines and the "Problems" indicator in the status bar.
Broken JSON (Syntax Error)
json
Broken XML (Tag Mismatch)
xml
4. Custom Sections
Inject arbitrary content between lines using the sections prop and slot. Useful for Git blame, inline warnings, or AI suggestions.
javascript
5. Line Truncation
Forcing a maximum of 5 lines for long content.
javascript
6. Editable Mode
Use v-model and editable to turn it into an editor.
Live Editor|script.js
1
function legacyFunction() {
2
// This function is old
3
return true;
4
}
5
6
function newFunction() {
7
return false;
8
}
Live Preview of Model:
function legacyFunction() {
// This function is old
return true;
}
function newFunction() {
return false;
}Live Editor|script.js
7. Within Frame Component
plaintext
This is generic content inside the frame, but usually you'd put the
UICodeBlock here if you needed custom framing logic. 