askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/test_highlight.html
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
test_highlight.html · 2.0 KB · 68 lines
1<!DOCTYPE html>
2<html>
3<head>
4 <title>Test YAML Highlighting</title>
5 <style>
6 body { background: #1e1e1e; color: #d4d4d4; font-family: monospace; }
7 pre { padding: 20px; }
8 </style>
9</head>
10<body>
11 <h1>Testing YAML Syntax Highlighting</h1>
12 <pre id="output"></pre>
13
14 <script>
15 function syntaxHighlightYAML(yaml) {
16 // Escape HTML first
17 let result = yaml
18 .replace(/&/g, '&amp;')
19 .replace(/</g, '&lt;')
20 .replace(/>/g, '&gt;');
21
22 // Apply syntax highlighting with proper span elements
23 // Comments (must come first to not interfere with other patterns)
24 result = result.replace(/(#.*)/gm, '<span style="color: #6a9955;">$1</span>');
25
26 // YAML keys at start of line (with optional indentation)
27 result = result.replace(/^(\s*)([a-zA-Z_][a-zA-Z0-9_-]*)\s*:/gm,
28 '$1<span style="color: #9cdcfe;">$2</span>:');
29
30 // List items
31 result = result.replace(/^(\s*)-\s+/gm, '$1<span style="color: #569cd6;">-</span> ');
32
33 // Quoted strings (double quotes only to avoid JS syntax errors)
34 result = result.replace(/"([^"]*)"/g, '<span style="color: #ce9178;">"$1"</span>');
35
36 // Booleans and null
37 result = result.replace(/:\s*(true|false|null)\b/gm, ': <span style="color: #569cd6;">$1</span>');
38
39 // Numbers
40 result = result.replace(/:\s*(-?\d+\.?\d*)\b/gm, ': <span style="color: #b5cea8;">$1</span>');
41
42 return result;
43 }
44
45 // Test YAML
46 const testYaml = `# Test YAML Config
47name: "test service"
48version: 1.0
49enabled: true
50count: 42
51price: 10.00
52
53items:
54 - name: "item1"
55 value: 100
56 - name: "item2"
57 value: 200
58
59settings:
60 debug: false
61 timeout: null`;
62
63 // Apply highlighting
64 document.getElementById('output').innerHTML = syntaxHighlightYAML(testYaml);
65 console.log('Highlighting applied successfully!');
66 </script>
67</body>
68</html>