Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
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, '&') |
| 19 | .replace(/</g, '<') |
| 20 | .replace(/>/g, '>'); |
| 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 |
| 47 | name: "test service" |
| 48 | version: 1.0 |
| 49 | enabled: true |
| 50 | count: 42 |
| 51 | price: 10.00 |
| 52 | |
| 53 | items: |
| 54 | - name: "item1" |
| 55 | value: 100 |
| 56 | - name: "item2" |
| 57 | value: 200 |
| 58 | |
| 59 | settings: |
| 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> |