Skip to content

Commit 710b58b

Browse files
committed
feat: Improve code block styling in playground
- Add subtle border and better padding to code blocks - Add language label (php, js, djot, etc.) in top-right corner - Better inline code styling with border - Register Djot language for syntax highlighting in playground
1 parent 20f41d4 commit 710b58b

2 files changed

Lines changed: 81 additions & 6 deletions

File tree

docs/.vitepress/components/DjotPlayground.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22
import { ref, watch, onMounted, nextTick } from 'vue'
33
import hljs from 'highlight.js'
44
5+
// Register Djot language for syntax highlighting
6+
function registerDjotLanguage() {
7+
if (hljs.getLanguage('djot')) return
8+
9+
hljs.registerLanguage('djot', () => ({
10+
name: 'Djot',
11+
aliases: ['djot'],
12+
case_insensitive: false,
13+
contains: [
14+
{ className: 'section', begin: /^#{1,6}\s/, end: /$/ },
15+
{ className: 'emphasis', begin: /(?<!\w)_(?!\s)/, end: /_(?!\w)/ },
16+
{ className: 'strong', begin: /(?<!\w)\*(?!\s)/, end: /\*(?!\w)/ },
17+
{ className: 'code', begin: /`+/, end: /`+/ },
18+
{ className: 'link', begin: /\[[^\]]*\]\([^)]*\)/ },
19+
{ className: 'quote', begin: /^>/, end: /$/ },
20+
{ className: 'bullet', begin: /^[ \t]*[-*+](?=\s)/ },
21+
{ className: 'bullet', begin: /^[ \t]*\d+[.)](?=\s)/ },
22+
{ className: 'keyword', begin: /^`{3,}\s*[a-zA-Z]*$/ },
23+
{ className: 'attr', begin: /\{(?![=+\-%])[^}]+\}/ },
24+
{ className: 'addition', begin: /\{=/, end: /=\}/ },
25+
{ className: 'addition', begin: /\{\+/, end: /\+\}/ },
26+
{ className: 'deletion', begin: /\{-/, end: /-\}/ },
27+
],
28+
}))
29+
}
30+
31+
registerDjotLanguage()
32+
533
const SANDBOX_URL = 'https://sandbox.dereuromark.de/sandbox/djot'
634
735
const djotInput = ref(`# Welcome to Djot

docs/.vitepress/theme/custom.css

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,73 @@
150150

151151
/* Code blocks in playground preview */
152152
.djot-playground .preview pre {
153+
position: relative;
153154
background: var(--vp-code-block-bg);
155+
border: 1px solid var(--vp-c-divider);
154156
border-radius: 8px;
155-
padding: 1rem;
157+
padding: 1.25rem 1.5rem;
156158
overflow-x: auto;
157-
margin: 1rem 0;
159+
margin: 1.25rem 0;
158160
}
159161

160162
.djot-playground .preview pre code {
163+
display: block;
161164
font-family: var(--vp-font-family-mono);
162-
font-size: 14px;
163-
line-height: 1.6;
165+
font-size: 13px;
166+
line-height: 1.7;
164167
color: var(--vp-c-text-1);
168+
background: transparent;
169+
padding: 0;
170+
}
171+
172+
/* Language label for code blocks */
173+
.djot-playground .preview pre code[class*="language-"]::before {
174+
content: attr(data-language);
175+
position: absolute;
176+
top: 0.5rem;
177+
right: 0.75rem;
178+
font-size: 11px;
179+
font-weight: 500;
180+
color: var(--vp-c-text-3);
181+
text-transform: uppercase;
182+
letter-spacing: 0.025em;
183+
}
184+
185+
.djot-playground .preview pre code.language-php::before {
186+
content: 'php';
187+
}
188+
189+
.djot-playground .preview pre code.language-js::before,
190+
.djot-playground .preview pre code.language-javascript::before {
191+
content: 'js';
165192
}
166193

194+
.djot-playground .preview pre code.language-html::before {
195+
content: 'html';
196+
}
197+
198+
.djot-playground .preview pre code.language-css::before {
199+
content: 'css';
200+
}
201+
202+
.djot-playground .preview pre code.language-bash::before,
203+
.djot-playground .preview pre code.language-shell::before {
204+
content: 'sh';
205+
}
206+
207+
.djot-playground .preview pre code.language-djot::before {
208+
content: 'djot';
209+
}
210+
211+
/* Inline code */
167212
.djot-playground .preview code:not(pre code) {
168213
background: var(--vp-code-block-bg);
169-
padding: 0.2em 0.4em;
214+
border: 1px solid var(--vp-c-divider);
215+
padding: 0.15em 0.4em;
170216
border-radius: 4px;
171217
font-family: var(--vp-font-family-mono);
172-
font-size: 0.9em;
218+
font-size: 0.875em;
219+
color: var(--vp-c-text-1);
173220
}
174221

175222
/* highlight.js theme for playground */

0 commit comments

Comments
 (0)